Skip to main content

Cronflow

PyPI version Python Versions License

A lightweight Python package for controlling cron job execution with a simple decorator.

Overview

Cronflow allows you to easily enable or disable Python scripts that run via cron without modifying your crontab entries. By using a simple decorator, you can control which scripts run based on a centralized configuration file.

Key Features:

  • Simple decorator syntax for enabling/disabling cron jobs
  • No need to modify crontab entries to enable/disable scripts
  • Centralized configuration for managing multiple scripts
  • Automatic logging of script execution
  • Customizable configuration and log paths

Installation

pip install cronflow

Basic Usage

  1. Import the decorator:
from cronflow import cron_switch
  1. Apply it to your main function:
@cron_switch
def main():
    # Your code here...
    print("Processing data...")

if __name__ == "__main__":
    main()
  1. Create a configuration file:

Create a cron_switch.json file in the same directory as your script:

echo '{"example.py": true}' > cron_switch.json
{
  "your_script.py": true,
  "another_script.py": false
}
  1. Run your script from cron with the CRON environment variable:
CRON=true
0 8 * * * cd /path/to/scripts && python your_script.py

Now your_script.py will only run if it's set to true in the configuration file. You can disable it without modifying your crontab by simply changing the configuration.

Advanced Usage

Custom Configuration Path

You can specify a custom path for the configuration file:

@cron_switch(config_path="/etc/cronflow", config_name="cron_config.json")
def main():
    # Your code here...

Custom Log Directory

Customize where logs are stored:

@cron_switch(log_dir="/var/log/cronflow")
def main():
    # Your code here...

Custom Environment Variable

Use a different environment variable instead of "CRON":

@cron_switch(env_var="SCHEDULED_RUN")
def main():
    # Your code here...

Configuration Management

You can create/edit the cron_switch.json file manually or use a script:

import json

def enable_script(script_name, config_path="cron_switch.json"):
    with open(config_path, "r") as f:
        config = json.load(f)
    
    config[script_name] = True
    
    with open(config_path, "w") as f:
        json.dump(config, f, indent=2)
    
    print(f"Enabled {script_name}")

def disable_script(script_name, config_path="cron_switch.json"):
    with open(config_path, "r") as f:
        config = json.load(f)
    
    config[script_name] = False
    
    with open(config_path, "w") as f:
        json.dump(config, f, indent=2)
    
    print(f"Disabled {script_name}")

How It Works

  1. When a Python script with the @cron_switch decorator runs, it checks if the CRON environment variable is set
  2. If running from cron, it checks the configuration file to see if the script is enabled
  3. If disabled, it exits immediately without executing the main logic
  4. If enabled or not running from cron, it continues with normal execution

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Metadata

Release files for cronflow 0.2

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

Source distribution (sdist)

Source distribution for cronflow 0.2
File Size Uploaded Provenance
cronflow-0.2.tar.gz 5.5 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 11.5 kB

Release files / cronflow-0.2.tar.gz

Download URL cronflow-0.2.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1a4f08c67adb97779c6496c924c5eaba770dab9286649569d56bebab9b7ccda0
BLAKE2b-256 checksum
How to use checksums
ee31d2a92bc821b8c8f4173d824a70d24016534ba3d39e542436d665244f373f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Release files / cronflow-0.2-py3-none-any.whl

Download URL cronflow-0.2-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab0f19833624399cb4b3f9ffb7e31a9f830b29f484bfe327190850f3b9bca9f4
BLAKE2b-256 checksum
How to use checksums
bba2ba011866c069e262896f9ba883d39cfd89d095d5526483bf7bd385797cf2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Security for cronflow 0.2

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.

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files No provenance

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