Skip to main content

airflow-cron

Generate Airflow DAG models from cron configuration.

Build Status codecov License PyPI

Overview

airflow-cron converts the user-crontab models from cron-pydantic into airflow-pydantic DAG and Bash task models. Each enabled cron job becomes one DAG containing one Bash task.

from airflow_cron import CronAirflowConfiguration, create_dags

configuration = CronAirflowConfiguration.model_validate(
    {
        "environment": {"PATH": "/usr/local/bin:/usr/bin"},
        "job": {
            "backup": {
                "schedule": "0 2 * * *",
                "command": "/opt/bin/backup",
            },
            "cleanup": {
                "schedule": "@weekly",
                "command": "/opt/bin/cleanup",
                "enabled": False,
            },
        },
    }
)

dag_models = create_dags(configuration)

The result contains a backup DAG scheduled at 0 2 * * *. Its run task uses the cron command as its Bash command and appends the configured environment to the worker environment. Disabled jobs are omitted.

To expose generated models from an Airflow DAG file:

for dag_id, model in dag_models.items():
    globals()[dag_id] = model.instantiate()

Common Airflow settings can be supplied declaratively:

job:
  backup:
    schedule: "0 2 * * *"
    command: /opt/bin/backup
dag_args:
  max_active_runs: 1
  tags: [cron]
task_args:
  execution_timeout: 02:00:00

catchup defaults to false, matching cron's behavior of not backfilling missed runs. Job schedule and command always take precedence over defaults.

Compatibility

Airflow cannot faithfully represent every crontab feature. Conversion rejects:

  • system crontabs because Airflow executor user selection is deployment-specific
  • @reboot schedules
  • Cronie random ranges using ~
  • CRON_TZ and RANDOM_DELAY scheduler environment settings
  • unescaped %, which cron converts into command input

@annually maps to @yearly, and @midnight maps to @daily.

[!NOTE] This library was generated using copier from the Base Python Project Template repository.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

airflow_cron-0.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

airflow_cron-0.1.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file airflow_cron-0.1.0.tar.gz.

File metadata

  • Download URL: airflow_cron-0.1.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for airflow_cron-0.1.0.tar.gz
Algorithm Hash digest
SHA256 35366f2cc470fe118d27baf939d5d4e38e0ac34e30cfb8d4fb438c2de9e13ee8
MD5 24f530816f26c16b7c975a8cc7cdc38a
BLAKE2b-256 1e55bac4545f3cc7bef5da2ff42c640106291d8120714233705eb4034920a699

See more details on using hashes here.

File details

Details for the file airflow_cron-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: airflow_cron-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for airflow_cron-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 88f3cc58e0d42509aa5627f0745a609ddc68077e0fd8e6a6523f6133d299facc
MD5 57a08e91a0b19996c99f01e5ce0bfeb8
BLAKE2b-256 712c5a9059522ba925b86970891c0ad9aa6dd5dd9fe4fc98c546bfaa2c61a6f0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page