Convert Figma logo to code with AI

dbader logoschedule

Python job scheduling for humans.

11,889
968
11,889
165

Top Related Projects

Task scheduling library for Python

25,320

Distributed Task Queue (development branch)

6,518

Real-time monitor and web admin for Celery distributed task queue

9,995

Simple job queues for Python

13,186

a cron library for go

Quick Overview

Schedule is a Python library for job scheduling, allowing users to run Python functions (or any other callable) periodically at pre-determined intervals or times. It's designed to be a lightweight, in-process scheduler without the need for external processes or threads.

Pros

  • Simple and intuitive API for scheduling jobs
  • Supports various scheduling patterns (intervals, specific times, days of the week)
  • Lightweight with no external dependencies
  • Can be used within existing Python applications without additional infrastructure

Cons

  • Not suitable for distributed systems or high-reliability scenarios
  • Limited to in-process execution, which may not be ideal for long-running or resource-intensive tasks
  • Lacks advanced features like job persistence or failure recovery
  • May not be as precise as cron for very specific timing requirements

Code Examples

Scheduling a job to run every 10 minutes:

import schedule
import time

def job():
    print("I'm running every 10 minutes!")

schedule.every(10).minutes.do(job)

while True:
    schedule.run_pending()
    time.sleep(1)

Scheduling a job to run at a specific time every day:

import schedule

def morning_job():
    print("Good morning!")

schedule.every().day.at("06:00").do(morning_job)

Scheduling a job to run on specific days of the week:

import schedule

def weekend_job():
    print("It's the weekend!")

schedule.every().saturday.do(weekend_job)
schedule.every().sunday.do(weekend_job)

Getting Started

To get started with Schedule, first install it using pip:

pip install schedule

Then, you can use it in your Python script:

import schedule
import time

def job():
    print("This job runs every minute")

schedule.every(1).minutes.do(job)

while True:
    schedule.run_pending()
    time.sleep(1)

This script sets up a job to run every minute and then enters a loop to keep checking for pending jobs. The time.sleep(1) call prevents the loop from consuming too much CPU.

Competitor Comparisons

Task scheduling library for Python

Pros of APScheduler

  • More feature-rich with support for various job stores (e.g., SQLAlchemy, MongoDB)
  • Offers multiple scheduling methods (interval, cron, one-off)
  • Provides event listeners and error handling mechanisms

Cons of APScheduler

  • More complex setup and configuration
  • Steeper learning curve for beginners
  • Heavier dependency footprint

Code Comparison

Schedule:

import schedule
import time

def job():
    print("I'm working...")

schedule.every(10).minutes.do(job)

while True:
    schedule.run_pending()
    time.sleep(1)

APScheduler:

from apscheduler.schedulers.blocking import BlockingScheduler

def job():
    print("I'm working...")

scheduler = BlockingScheduler()
scheduler.add_job(job, 'interval', minutes=10)
scheduler.start()

Both libraries allow for scheduling recurring tasks, but APScheduler offers more advanced features and flexibility at the cost of increased complexity. Schedule is simpler and more straightforward for basic scheduling needs, while APScheduler is better suited for more complex scheduling requirements and enterprise-level applications.

25,320

Distributed Task Queue (development branch)

Pros of Celery

  • Distributed task queue system for handling asynchronous tasks and background jobs
  • Supports multiple message brokers (e.g., RabbitMQ, Redis) for scalability
  • Offers more advanced features like task prioritization and error handling

Cons of Celery

  • More complex setup and configuration compared to Schedule
  • Steeper learning curve for beginners
  • Requires additional infrastructure (message broker) to function

Code Comparison

Schedule:

import schedule
import time

def job():
    print("I'm working...")

schedule.every(10).minutes.do(job)

while True:
    schedule.run_pending()
    time.sleep(1)

Celery:

from celery import Celery

app = Celery('tasks', broker='redis://localhost:6379')

@app.task
def add(x, y):
    return x + y

result = add.delay(4, 4)

Schedule is simpler for basic scheduling needs, while Celery offers more robust features for distributed task processing and asynchronous job execution.

6,518

Real-time monitor and web admin for Celery distributed task queue

Pros of Flower

  • More comprehensive task queue system with support for distributed task execution
  • Supports multiple message brokers (Redis, RabbitMQ, etc.) for flexibility
  • Provides a web-based monitoring interface for task management

Cons of Flower

  • Steeper learning curve due to more complex architecture
  • Requires additional setup and configuration for distributed systems
  • May be overkill for simple scheduling needs

Code Comparison

Schedule:

import schedule
import time

def job():
    print("I'm working...")

schedule.every(10).minutes.do(job)

while True:
    schedule.run_pending()
    time.sleep(1)

Flower:

from celery import Celery

app = Celery('tasks', broker='redis://localhost:6379')

@app.task
def add(x, y):
    return x + y

result = add.delay(4, 4)

Schedule is simpler for basic scheduling tasks, while Flower (via Celery) offers more advanced features for distributed task processing.

9,995

Simple job queues for Python

Pros of RQ

  • Distributed task queue system, allowing for scalable job processing across multiple workers
  • Supports priority queues and job dependencies
  • Integrates well with Redis for robust job storage and management

Cons of RQ

  • More complex setup and configuration compared to Schedule
  • Requires Redis as a dependency
  • May be overkill for simple scheduling needs

Code Comparison

Schedule:

import schedule
import time

def job():
    print("I'm working...")

schedule.every(10).minutes.do(job)

while True:
    schedule.run_pending()
    time.sleep(1)

RQ:

from redis import Redis
from rq import Queue

q = Queue(connection=Redis())

def job():
    print("I'm working...")

result = q.enqueue(job)

Summary

Schedule is a lightweight, in-process scheduler for periodic jobs, ideal for simple use cases. RQ is a more powerful, distributed task queue system suitable for complex, scalable job processing. Schedule is easier to set up but lacks advanced features, while RQ offers more flexibility at the cost of increased complexity and Redis dependency.

13,186

a cron library for go

Pros of cron

  • More flexible scheduling options, including cron-style syntax
  • Better performance and scalability for large-scale applications
  • Supports time zones and daylight saving time adjustments

Cons of cron

  • Steeper learning curve, especially for those unfamiliar with cron syntax
  • Less intuitive for simple, human-readable scheduling tasks
  • Requires more setup and configuration compared to schedule

Code Comparison

schedule:

import schedule
import time

def job():
    print("I'm working...")

schedule.every(10).minutes.do(job)

while True:
    schedule.run_pending()
    time.sleep(1)

cron:

c := cron.New()
c.AddFunc("0 */10 * * * *", func() {
    fmt.Println("I'm working...")
})
c.Start()

// Block main goroutine forever
select{}

Both libraries allow for scheduling recurring tasks, but cron uses the more powerful cron syntax, while schedule opts for a more readable, method-chaining approach. cron is generally more suitable for complex scheduling needs, while schedule is easier to use for simple, frequent tasks.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

schedule <https://schedule.readthedocs.io/>__

.. image:: https://github.com/dbader/schedule/workflows/Tests/badge.svg :target: https://github.com/dbader/schedule/actions?query=workflow%3ATests+branch%3Amaster

.. image:: https://coveralls.io/repos/dbader/schedule/badge.svg?branch=master :target: https://coveralls.io/r/dbader/schedule

.. image:: https://img.shields.io/pypi/v/schedule.svg :target: https://pypi.python.org/pypi/schedule

Python job scheduling for humans. Run Python functions (or any other callable) periodically using a friendly syntax.

  • A simple to use API for scheduling jobs, made for humans.
  • In-process scheduler for periodic jobs. No extra processes needed!
  • Very lightweight and no external dependencies.
  • Excellent test coverage.
  • Tested on Python and 3.7, 3.8, 3.9, 3.10, 3.11, 3.12

Usage

.. code-block:: bash

$ pip install schedule

.. code-block:: python

import schedule
import time

def job():
    print("I'm working...")

schedule.every(10).seconds.do(job)
schedule.every(10).minutes.do(job)
schedule.every().hour.do(job)
schedule.every().day.at("10:30").do(job)
schedule.every(5).to(10).minutes.do(job)
schedule.every().monday.do(job)
schedule.every().wednesday.at("13:15").do(job)
schedule.every().day.at("12:42", "Europe/Amsterdam").do(job)
schedule.every().minute.at(":17").do(job)

def job_with_argument(name):
    print(f"I am {name}")

schedule.every(10).seconds.do(job_with_argument, name="Peter")

while True:
    schedule.run_pending()
    time.sleep(1)

Documentation

Schedule's documentation lives at schedule.readthedocs.io <https://schedule.readthedocs.io/>_.

Meta

Daniel Bader - @dbader_org <https://twitter.com/dbader_org>_ - mail@dbader.org

Inspired by Adam Wiggins' <https://github.com/adamwiggins>_ article "Rethinking Cron" <https://adam.herokuapp.com/past/2010/4/13/rethinking_cron/>_ and the clockwork <https://github.com/Rykian/clockwork>_ Ruby module.

Distributed under the MIT license. See LICENSE.txt <https://github.com/dbader/schedule/blob/master/LICENSE.txt>_ for more information.

https://github.com/dbader/schedule