# Batch monitoring jobs
URL: https://docs.datarobot.com/en/docs/api/dev-learning/python/mlops/batch-monitoring.html

> Manage batch monitoring job definitions and jobs for batch-enabled deployments with the Python API client.

# Batch monitoring jobs

[Batch monitoring jobs](https://docs.datarobot.com/en/docs/workbench/nxt-console/nxt-predictions/nxt-prediction-jobs.html) let you monitor predictions data over time. This page describes how to manage batch monitoring jobs and job definitions with the Python API client.

## Prerequisites

- Data and output configuration for running a monitoring job (e.g., intake and output settings compatible with batch prediction jobs ).

## Batch monitoring job definitions

A batch monitoring job definition is a saved configuration for a batch monitoring job. Definitions can be run once on demand or on a schedule. The Python client exposes these via [BatchMonitoringJobDefinition](https://docs.datarobot.com/en/docs/api/dev-learning/python/mlops/batch-monitoring.html#datarobot.models.batch_monitoring.BatchMonitoringJobDefinition).

### List job definitions

List all batch monitoring job definitions. You can also filter them by deployment or name.

```
import datarobot as dr

# List all definitions
definitions = dr.BatchMonitoringJobDefinition.list()

# Filter by deployment
definitions = dr.BatchMonitoringJobDefinition.list(deployment_id='5c939e08962d741e34f609f0')

# Search by name
definitions = dr.BatchMonitoringJobDefinition.list(search_name='Daily Monitoring')
```

Refer to [BatchMonitoringJobDefinition.list](https://docs.datarobot.com/en/docs/api/dev-learning/python/mlops/batch-monitoring.html#datarobot.models.batch_monitoring.BatchMonitoringJobDefinition.list) for parameters such as `offset` and `limit`.

### Get a job definition

Retrieve a single job definition via its ID:

```
import datarobot as dr

definition = dr.BatchMonitoringJobDefinition.get(job_definition_id='550e8400-e29b-41d4-a716-446655440000')
print(definition.name, definition.deployment_id)
```

### Create a job definition

Create a batch monitoring job definition with the desired intake, output, and deployment. The payload matches the [batch monitoring job create](https://docs.datarobot.com/en/docs/workbench/nxt-console/nxt-monitoring/nxt-batch-monitoring.html) API (e.g., `deploymentId`, `intakeSettings`, `outputSettings`). You can set `enabled` and `schedule` to run it on a schedule.

```
import datarobot as dr

definition = dr.BatchMonitoringJobDefinition.create(
    deployment_id='5c939e08962d741e34f609f0',
    name='Weekly batch monitoring',
    intake_settings={'type': 'localFile', 'url': 'file:///data/predictions.csv'},
    output_settings={'type': 'localFile', 'path': '/out/monitoring'},
    enabled=False
)
```

Refer to [BatchMonitoringJobDefinition.create](https://docs.datarobot.com/en/docs/api/dev-learning/python/mlops/batch-monitoring.html#datarobot.models.batch_monitoring.BatchMonitoringJobDefinition.create) and the [Batch Monitoring API](https://docs.datarobot.com/en/docs/workbench/nxt-console/nxt-monitoring/nxt-batch-monitoring.html) for all supported options (e.g., `monitoringBatchPrefix`, `monitoringColumns`, `chunkSize`).

### Update a job definition

Update an existing definition (e.g., name, schedule, or enabled state):

```
import datarobot as dr

definition = dr.BatchMonitoringJobDefinition.get(job_definition_id='550e8400-e29b-41d4-a716-446655440000')
definition.update(name='Daily batch monitoring', enabled=True)
```

See [BatchMonitoringJobDefinition.update](https://docs.datarobot.com/en/docs/api/dev-learning/python/mlops/batch-monitoring.html#datarobot.models.batch_monitoring.BatchMonitoringJobDefinition.update) for updatable fields.

### Run a job definition

To execute a definition once without changing its schedule:

```
import datarobot as dr

definition = dr.BatchMonitoringJobDefinition.get(job_definition_id='550e8400-e29b-41d4-a716-446655440000')
job = definition.run_once()
print(job.id, job.status)
```

### Run a job definition on a schedule

Start running the definition on its configured schedule (if any):

```
import datarobot as dr

definition = dr.BatchMonitoringJobDefinition.get(job_definition_id='550e8400-e29b-41d4-a716-446655440000')
definition.run_on_schedule()
```

### Delete a job definition

Remove a batch monitoring job definition. The definition cannot have jobs currently running.

```
import datarobot as dr

definition = dr.BatchMonitoringJobDefinition.get(job_definition_id='550e8400-e29b-41d4-a716-446655440000')
definition.delete()
```

## Batch monitoring jobs

A batch monitoring job is a single run (either from a single submission or from a definition). Use [BatchMonitoringJob](https://docs.datarobot.com/en/docs/api/dev-learning/python/mlops/batch-monitoring.html#datarobot.models.batch_monitoring.BatchMonitoringJob) to retrieve the job status and details.

### Get a batch monitoring job

Retrieve a job by ID to check status or results (for example, after running a definition with `run_once()`):

```
import datarobot as dr

job = dr.BatchMonitoringJob.get(job_id='660e8400-e29b-41d4-a716-446655440001')
print(job.status, job.deployment_id)
```

---
