airflow-cron
Generate Airflow DAG models from cron configuration.
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
@rebootschedules- Cronie random ranges using
~ CRON_TZandRANDOM_DELAYscheduler 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.
Metadata
Release files for airflow-cron 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| airflow_cron-0.1.0.tar.gz | 10.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| airflow_cron-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.4 kB
Release files / airflow_cron-0.1.0.tar.gz
| Download URL | airflow_cron-0.1.0.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35366f2cc470fe118d27baf939d5d4e38e0ac34e30cfb8d4fb438c2de9e13ee8
|
|
BLAKE2b-256 checksum How to use checksums |
1e55bac4545f3cc7bef5da2ff42c640106291d8120714233705eb4034920a699
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / airflow_cron-0.1.0-py3-none-any.whl
| Download URL | airflow_cron-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
88f3cc58e0d42509aa5627f0745a609ddc68077e0fd8e6a6523f6133d299facc
|
|
BLAKE2b-256 checksum How to use checksums |
712c5a9059522ba925b86970891c0ad9aa6dd5dd9fe4fc98c546bfaa2c61a6f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|