Skip to main content

Asynchronous background tasks for Python web-frameworks with no dependencies

Project description

autocron

autocron is a Python background task library with no dependencies beside the standard library. It works out of the box with webframeworks like django, pyramid, flask, bottle, tornado or starlette.

autocron makes it easy to delegate long running and recurring tasks to external processes. No hassle with configuration-files.

autocron is designed for the vast majority of webapplications that don't need massive scaling. And don't want to add unnecessary dependencies.

Installation

For installation use pip:

    $ pip install autocron

or conda:

    $ conda install autocron

Quickstart

autocron provides two decorators: cron that takes a string in cron-format as argument, but accepts also keyword-arguments like minutes and hours. And delay to delegate a long running task to a background process.

Here is a simple example how to use autocron with the flask web-framework that can be run with $ flask --app application run:

    # application.py

    import autocron
    from flask import Flask

    app = Flask(__name__)
    autocron.start("the_flask_app.db")

    @autocron.cron("* * * * *")
    def cronjob():
        # do something from time to time ...

    @autocron.delay
    def do_this_later():
        # time consuming task here ...

    @app.route("/later")
    def later():
        do_this_later()
        return "delayed action triggered"

After creating the flask app instance calling autocron.start(<databasename>) starts the background workers. The cron decorated cronjob() function will get executed every minute and the delay decorated do_this_later() function gets delegated to the background worker every time the application processes the /later url. Terminating the application will shut down the worker processes.

More information and examples how to use autocron with other frameworks are at the documentation.

Documentation

The full documentation and release notes are at https://autocron.readthedocs.org

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autocron-1.2.1.tar.gz (33.1 kB view details)

Uploaded Source

Built Distribution

autocron-1.2.1-py3-none-any.whl (37.2 kB view details)

Uploaded Python 3

File details

Details for the file autocron-1.2.1.tar.gz.

File metadata

  • Download URL: autocron-1.2.1.tar.gz
  • Upload date:
  • Size: 33.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for autocron-1.2.1.tar.gz
Algorithm Hash digest
SHA256 91815100863a5f7e3f8bce4d2d2ef6d259e95be909d335d2fade15b8b7d39993
MD5 809921c71211b39b772e28bc4fa9d7ee
BLAKE2b-256 e1522f60b6bf4e9f2caf87050b5a11f03e60c9163cd63656befdab366f3159e2

See more details on using hashes here.

File details

Details for the file autocron-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: autocron-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 37.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for autocron-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 62ff98b2342915518dacb1962cbbcb47d74735a8215c9a44f1f5b88c92d6e915
MD5 cb52ca2389d20c628804d585ebb27629
BLAKE2b-256 a9ee1af4510576de8908110189b585dd4ebd40b6fb7fd9d35956beb370ce80eb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page