Developer Documentation
Python Integration
Reliable background jobs, simplified.
Get Started View ChangelogInstallation
Add the CronFlow Python SDK to your environment using pip or your preferred package manager. The library supports Python 3.8+ and handles authentication, payload serialization, and retry logic automatically.
Run the following command in your project root to install version 2.4.1, which includes native support for Django 5.0 and Flask 3.0:
pip install cronflow-sdk==2.4.1
After installation, export your workspace API key. You can generate a new key from the CronFlow console under Settings > API Keys. The key for the production-us-east-1 workspace begins with cf_live_.
Environment Variables
Set CRONFLOW_API_KEY and CRONFLOW_ENVIRONMENT in your deployment configuration. For Docker containers, inject these via the .env file loaded by your orchestration layer.
Requirements File
Add cronflow-sdk==2.4.1 to your requirements.txt or pyproject.toml. The SDK pulls in httpx and pydantic as transitive dependencies for request validation.
Code Example
Initialize the client and define a scheduled task using the decorator pattern. The SDK automatically registers your function with the CronFlow scheduler and handles serialization of job payloads.
import cronflow
from cronflow import schedule
# Initialize with your workspace key
cronflow.init(api_key="cf_live_8x9m2p4q7r")
@schedule.every("*/15 * * * *")
def generate_daily_reports():
"""Runs every 15 minutes during business hours (09:00-17:00 UTC)."""
report_data = fetch_metrics_from_postgres()
cronflow.publish("reports.generated", payload=report_data)
print(f"Report batch {report_data['batch_id']} queued successfully.")
if __name__ == "__main__":
cronflow.run()
The @schedule decorator accepts standard cron expressions. When the trigger fires, CronFlow routes the execution to your configured worker pool. Use cronflow.publish to emit events to your internal Kafka topic or AWS SQS queue after processing completes.
Framework-Specific Notes
CronFlow integrates seamlessly with major Python web frameworks. Below are configuration patterns for Django, Flask, and standalone scripts.
Django & Celery
Replace your existing Celery beat scheduler with CronFlow by adding cronflow.django to INSTALLED_APPS. Set CELERY_BEAT_SCHEDULE to {} and configure the CRONFLOW_DJANGO_APP_NAME setting. The SDK syncs your settings.py cron definitions on every server restart.
Flask Applications
Initialize the extension inside your application factory. Use CronFlow(app) after configuring your database and extensions. Flask-Admin integration is available via the cronflow-flask-admin companion package for visual job monitoring.
Standalone Scripts
For data pipelines and ETL jobs, run the SDK in daemon mode using cronflow daemon start. This keeps the process alive, handles graceful shutdowns on SIGTERM, and writes structured logs to /var/log/cronflow/worker.log.
Need help migrating from APScheduler or Celery Beat? Our migration guide covers payload serialization differences, timezone handling, and worker scaling best practices. Contact our engineering support at python-support@cronflow.io for architecture reviews.
Read Migration Guide API Reference