Metadata-Version: 2.3
Name: cronipy
Version: 0.1.5
Summary: Add your description here
Author: lantonic
Author-email: lantonic <luka.olegsson@gmail.com>
Requires-Dist: cyclopts>=5.3.2
Requires-Python: >=3.12
Project-URL: Homepage, https://codeberg.org/lantonic/cronipy
Project-URL: Repository, https://codeberg.org/lantonic/cronipy
Description-Content-Type: text/markdown

# cronipy

`cronipy` turns Python functions into cron jobs. You decorate a function with a schedule, run one command, and `cronipy` writes the crontab entries for you. 

Rather than reinvent `cron` in Python, `cronipy` uses your system crontab.

The package is in early development, and the interface can change.

## Installation

Requires `cron` installed on your system.

```bash
pip install cronipy
```

## Usage

Define your jobs in a module of your package, e.g. `mypackage.tasks_module`:

```python
from cronipy import Cron

cron = Cron()

@cron.task("*/5 * * * *")
def do_something_every_five_minutes():
    ...
```

Then install jobs from all `Cron` objects in the specified module:

```bash
$ cronipy install mypackage.tasks_module
```

Or, to replace your existing crontab with jobs defined with `cronipy`:

```bash
$ cronipy install mypackage.tasks_module --replace-existing
```

`cronipy` adds one line per decorated function into the current user's `crontab`. Function output is logged in `logs/<function name>.log`.

Jobs added by `cronipy` can be cleaned up from your `crontab` by:

```bash
$ cronipy uninstall mypackage.tasks_module
```

Jobs can be also installed and uninstalled from Python:

```python
cron.install()
# and
cron.uninstall()
```

## Options

You can pass these arguments to `Cron`:

- `dry_run`: when true, a job prints its name and does nothing.
- `env`: a dictionary of environment variables added to every crontab line.
- `log_dir`: where the log files go, `./logs` by default.
- `work_dir`: the directory each job runs in, `./` by default.
- `python`: the interpreter the jobs use, the one that runs cronipy by default.

## Development

This repository uses [uv](https://docs.astral.sh/uv/). Set up a development environment with `uv sync`, and run the checks with `uv run pytest`.

## Roadmap

- [x] Enable compatibility with single-file modules.
- [x] CLI command to uninstall `cronipy` entries from `crontab`..
- [ ] Enable autodiscovery of modules containing Cron objects.

## License
[BSD 3-Clause](./LICENSE.txt) 
