Skip to main content

A cron-style scheduler that turns functions from any package into scheduled jobs via config files.

Project description

gpscheduler

PyPI version Python License: MIT Documentation

GPScheduler (General-Purpose Scheduler) is a cron-style Python scheduler that turns functions from any package into scheduled jobs via config files, configures startup arguments, and exposes a decorator to mark schedulable functions.

中文文档README.zh.md


Features

  • Config-driven cron jobs — declare schedules, callables, and call arguments in YAML config files; no timers hardcoded in application code.
  • Package-agnostic — point a job at any importable function in any installed package, located by dotted path.
  • Two decorators@scheduled marks a function as schedulable; @worker_init builds an expensive object (DB connection, network client, …) once and reuses it across runs.
  • Thread and process executors — each job picks its own pool. Threads for I/O-bound work, processes for CPU-bound or isolated work.
  • Scheduler-wide globals — shared config values (db_url, api_key, …) injected into every job that asks for them.
  • Graceful, cross-platform shutdownCtrl+C on Windows, SIGINT/SIGTERM on Linux, with a configurable shutdown timeout.
  • Fail-Early validation — invalid config fails loudly at load time, never silently at the first trigger.
  • Embeddable — run standalone via the CLI, or embed it inside a host application.

Installation

pip install gpscheduler

For local development from a clone:

source .venv/Scripts/activate   # Git Bash on Windows
pip install -e ".[dev]"

Quick start

  1. Install gpscheduler (see Installation).

  2. Write a package containing a @scheduled function:

    # myjobs/hello.py
    from gpscheduler import scheduled
    
    @scheduled
    def greet(name: str, *, greeting: str = "Hello") -> None:
        print(f"{greeting}, {name}!")
    
  3. Point a config folder at it:

    # configs/scheduler.yaml
    cfg_class_name: GPSchedulerConfig
    configured_class_name: GPScheduler
    executor: thread
    packages: [myjobs]
    
    # configs/jobs/hello.yaml
    cfg_class_name: GPJobConfig
    func: "myjobs.hello.greet"
    cron: "*/2 * * * * *"   # every 2 seconds (6-segment, leading seconds field)
    args: ["world"]
    kwargs:
      greeting: "Hi"
    

    The config folder also needs a global_env.yaml (required by the underlying gpconfig loader) — an empty {} is fine.

  4. Run it:

    gpscheduler run --config configs
    

    Use gpscheduler list-jobs --config configs for a dry run that validates config and lists enabled jobs without starting anything.

See the Examples page in the docs for a complete, annotated demo covering arguments, job_globals injection, worker_init in both thread and process pools, and more.

Documentation

Full documentation is published at https://linnetcodes.github.io/gpscheduler/ (English / 简体中文).

License

MIT © LinnetCodes

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

gpscheduler-0.1.0.tar.gz (108.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gpscheduler-0.1.0-py3-none-any.whl (31.3 kB view details)

Uploaded Python 3

File details

Details for the file gpscheduler-0.1.0.tar.gz.

File metadata

  • Download URL: gpscheduler-0.1.0.tar.gz
  • Upload date:
  • Size: 108.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gpscheduler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 72dc056b11b07a7dd4944347cce81a179c2013deae18baa51452c23f97dd2a4b
MD5 20e851046c9b5c1ddcc236961ec50859
BLAKE2b-256 c54c2a2ed28fff1227d2bd9a65e5c909b6b39c91baf9be9dc1521a290e16cce3

See more details on using hashes here.

Provenance

The following attestation bundles were made for gpscheduler-0.1.0.tar.gz:

Publisher: python-publish.yml on LinnetCodes/gpscheduler

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gpscheduler-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gpscheduler-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 31.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gpscheduler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4f64ba8c71cd3942812c4840b78b2534e905d8c3cde87b9608dfd3b88d682cbd
MD5 8aa94ad9e31ac2276a9b322eb0a06aa7
BLAKE2b-256 fd722bbc685ac7bff1ae8223b93d15a6abae47bb897f690b9342b7c07e38d48f

See more details on using hashes here.

Provenance

The following attestation bundles were made for gpscheduler-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on LinnetCodes/gpscheduler

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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