Cronitor Python Client

raw JSON →
4.9.0 verified Mon Apr 27 auth: no python

A lightweight Python client for Cronitor, providing monitoring and alerting for cron jobs, background jobs, and API endpoints. Current version 4.9.0, released May 2025. Active development with occasional minor releases.

pip install cronitor
error cronitor.errors.CronitorRequestError: 401 Unauthorized
cause Invalid or missing API key.
fix
Ensure CRONITOR_API_KEY environment variable is set to a valid key from your Cronitor account, or pass api_key explicitly.
error cronitor.errors.CronitorRequestError: 404 Not Found
cause The monitor key does not exist or the API endpoint is misspelled.
fix
Double-check the monitor key and the endpoint URL. For pings, ensure the monitor key is correct.
error ImportError: cannot import name 'Cronitor' from 'cronitor'
cause Using an older version of the library (<4.0) that doesn't have the Cronitor class.
fix
Upgrade to latest version: pip install --upgrade cronitor. In older versions, use import cronitor; cronitor.api_key = '...'.
breaking In v4.0, the client was rewritten. The old import pattern `from cronitor import Cronitor` still works, but the API for creating monitors changed: use `cronitor.monitors.create()` instead of `Cronitor(api_key).create_monitor()`.
fix Use `cronitor.monitors.create(name, schedule)` instead of direct methods on the Cronitor class.
gotcha API key must be set via environment variable or passed explicitly. The client does not auto-read from .env files.
fix Set CRONITOR_API_KEY environment variable or pass `api_key` argument to Cronitor() constructor.
deprecated The `pings.create()` method is deprecated in favor of the module-level `ping()` function.
fix Use `from cronitor import ping` and call `ping(monitor_key, state='...')` instead of `cronitor.pings.create(...)`.

Initialize the client with your API key, create a monitor, and send a run ping.

import os
from cronitor import Cronitor

api_key = os.environ.get('CRONITOR_API_KEY', '')
if not api_key:
    raise ValueError('CRONITOR_API_KEY environment variable not set')

cronitor = Cronitor(api_key=api_key)

# Create a monitor
monitor = cronitor.monitors.create(name='My Job', schedule='*/5 * * * *')

# Ping the monitor
cronitor.ping(monitor.key, state='run')
print('Job started.')