Metadata-Version: 2.4
Name: cron-pydantic
Version: 0.1.0
Summary: Pydantic models for cron
Project-URL: Repository, https://github.com/airflow-laminar/cron-pydantic
Project-URL: Homepage, https://github.com/airflow-laminar/cron-pydantic
Author-email: the cron-pydantic authors <t.paine154@gmail.com>
License: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.11
Requires-Dist: pydantic>=2
Requires-Dist: pyyaml
Provides-Extra: develop
Requires-Dist: build; extra == 'develop'
Requires-Dist: bump-my-version; extra == 'develop'
Requires-Dist: check-dist; extra == 'develop'
Requires-Dist: codespell; extra == 'develop'
Requires-Dist: hatchling; extra == 'develop'
Requires-Dist: mdformat; extra == 'develop'
Requires-Dist: mdformat-tables>=1; extra == 'develop'
Requires-Dist: pytest; extra == 'develop'
Requires-Dist: pytest-cov; extra == 'develop'
Requires-Dist: ruff; extra == 'develop'
Requires-Dist: twine; extra == 'develop'
Requires-Dist: ty; extra == 'develop'
Requires-Dist: uv; extra == 'develop'
Requires-Dist: wheel; extra == 'develop'
Description-Content-Type: text/markdown

# cron-pydantic

Pydantic models for cron schedules, jobs, and crontab files.

[![Build Status](https://github.com/airflow-laminar/cron-pydantic/actions/workflows/build.yaml/badge.svg?branch=main&event=push)](https://github.com/airflow-laminar/cron-pydantic/actions/workflows/build.yaml)
[![codecov](https://codecov.io/gh/airflow-laminar/cron-pydantic/branch/main/graph/badge.svg)](https://codecov.io/gh/airflow-laminar/cron-pydantic)
[![License](https://img.shields.io/github/license/airflow-laminar/cron-pydantic)](https://github.com/airflow-laminar/cron-pydantic)
[![PyPI](https://img.shields.io/pypi/v/cron-pydantic.svg)](https://pypi.python.org/pypi/cron-pydantic)

## Installation

```bash
pip install cron-pydantic
```

## Usage

Define a crontab from Python or validate the equivalent YAML with
`CronConfiguration.model_validate`:

```python
from cron_pydantic import CronConfiguration

configuration = CronConfiguration.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,
            },
        },
    }
)

print(configuration.to_cron())
```

This renders:

```cron
# Generated by cron-pydantic
PATH=/usr/local/bin:/usr/bin

# cron-pydantic: backup
0 2 * * * /opt/bin/backup
# cron-pydantic: cleanup
# @weekly /opt/bin/cleanup
```

Use `system=True` and provide each job's `user` to render `/etc/crontab` or
`/etc/cron.d` format:

```python
configuration = CronConfiguration.model_validate(
    {
        "system": True,
        "job": {
            "backup": {
                "schedule": "@daily",
                "user": "root",
                "command": "/opt/bin/backup",
            }
        },
    }
)
```

Parse existing content with `CronConfiguration.from_cron`, load YAML or crontab
files with `CronConfiguration.load`, and write rendered content with
`configuration.write(path)`.

`cron-pydantic` does not install a crontab or modify the host scheduler. This
keeps rendering and validation separate from deployment and avoids replacing
unmanaged crontab entries.

## Supported syntax

- Five-field user crontab schedules
- Six-field system crontab entries containing a user
- Lists, ranges, steps, month and weekday names, and Cronie random ranges
- `@reboot`, `@yearly`, `@annually`, `@monthly`, `@weekly`, `@daily`,
  `@midnight`, and `@hourly`
- Environment assignments and disabled jobs

> [!NOTE]
> This library was generated using [copier](https://copier.readthedocs.io/en/stable/) from the [Base Python Project Template repository](https://github.com/python-project-templates/base).
