Skip to main content

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.

pip install cronipy

Usage

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

from cronipy import Cron

cron = Cron()

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

Then, from the directory that contains your module, install jobs by running:

cronipy install

And to clean up your crontab from jobs added by cronipy:

cronipy uninstall

Jobs can also be installed/uninstalled from Python with Cron().install()/Cron().uninstall().

For a more complete example contained inside a Python script (e.g. /some/dir/tasks_module.py):

import asyncio
import subprocess
from cronipy import Cron

cron = Cron(env={"DISPLAY": ":0.0", "XDG_RUNTIME_DIR": "/run/user/1000"})

@cron.task("*/2 * * * *")
def do_stuff():
    subprocess.run(["notify-send", "cronipied!"])

# cronipy also supports tasks
# defined as async functions
# and the Cron().task decorator can
# override or add specific env vars
@cron.task("*/5 * * * *", env={"DISPLAY": ":0.1"})
async def do_other_stuff():
    await asyncio.create_subprocess_exec("notify-send", "cronipied!")

if __name__ == "__main__":
    cron.install()

cronipy adds one line per decorated function into the current user's crontab. Function output is logged in logs/<function name>.log. The example above would generate cron lines as follows:

*/2 * * * * cd /some/dir && DISPLAY=:0.0 XDG_RUNTIME_DIR=/run/user/1000 PYTHONPATH=/some/dir /some/dir/.venv/bin/python -c "from tasks_module import cron; cron()" do_stuff >> /some/dir/logs/do_stuff.log 2>&1
*/5 * * * * cd /some/dir && DISPLAY=:0.1 XDG_RUNTIME_DIR=/run/user/1000 PYTHONPATH=/some/dir /some/dir/.venv/bin/python -c "from tasks_module import cron; cron()" do_other_stuff >> /some/dir/logs/do_other_stuff.log 2>&1

where /some/dir contains tasks_module.py (and is where the file was executed from). The job working directory and log directory can be modified via arguments to Cron(), see Configuration.

CLI

$ cronipy install --help
Usage: cronipy install [ARGS]

╭─ Parameters ──────────────────────────────╮
│ PATH --path              [default: ./]    │
│ REPLACE-EXISTING         [default: False] │
│   --replace-existing                      │
│   --no-replace-existing                   │
╰───────────────────────────────────────────╯

$ uv run cronipy uninstall --help
Usage: cronipy uninstall [ARGS]

╭─ Parameters ──────────────────────────────╮
│ PATH --path  [default: ./]                │
╰───────────────────────────────────────────╯

The --path parameter can also be used to install jobs with more specific targeting:

# install jobs from all Cron objects in a module
cronipy install mypackage.tasks_module

# install jobs from specific Cron object
cronipy install mypackage.tasks_module:cron

# install jobs from single-file module specified as file path
cronipy install ./tasks_module.py

The same argument handling is done with the cronipy uninstall command.

To replace your existing crontab with jobs defined through cronipy:

cronipy install --replace-existing

Configuration

You can pass the following 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 (can also be passed to the Cron().task decorator with higher priority).
  • 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. Set up a development environment with uv sync, and run the checks with uv run pytest.

License

BSD 3-Clause

Metadata

Release files for cronipy 0.1.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cronipy 0.1.10
File Size Uploaded Provenance Actions
cronipy-0.1.10.tar.gz 4.9 kB Without provenance Details for cronipy-0.1.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cronipy 0.1.10
File Interpreter ABI Platform Actions
cronipy-0.1.10-py3-none-any.whl Python 3 none any Details for cronipy-0.1.10-py3-none-any.whl

Total release size: 10.6 kB

Release files / cronipy-0.1.10.tar.gz

Download URL cronipy-0.1.10.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
404dc8778e1d10912f6f8428bc0d09adaaa0c9f70d79b7372f96d674e5880afa
BLAKE2b-256 checksum
How to use checksums
e6ebd172be2bfb6b1784c445a9732291dd450bb278c916784b4ec238c3a34255
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Manjaro Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / cronipy-0.1.10-py3-none-any.whl

Download URL cronipy-0.1.10-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
39798de9d6a69eebcbfee8227316ceb491c11bbc1cca773dbbe590fbf6e06c63
BLAKE2b-256 checksum
How to use checksums
2e9b435affa5d3f0e08166c4de1f0dc18561b099790083fe036f906144c8d367
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Manjaro Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for cronipy 0.1.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page