explaingit

agronholm/apscheduler

7,485PythonAudience · developerComplexity · 3/5Setup · moderate

TLDR

A Python library for running tasks automatically on schedules or in a queue, supports cron-style timing, fixed intervals, and one-off jobs, and works across multiple servers with persistent storage.

Mindmap

mindmap
  root((APScheduler))
    Schedule types
      Cron-style
      Fixed interval
      Calendar-based
      One-off date
    Runtime support
      Thread-based
      asyncio
      Trio
    Storage backends
      PostgreSQL
      MySQL
      SQLite
      MongoDB
    Event brokers
      Redis
      MQTT
      PostgreSQL
    Job controls
      Max concurrent copies
      Start deadline
      Random jitter
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Schedule a Python function to run every night at midnight using cron-style syntax without setting up an external tool like cron or Celery.

USE CASE 2

Run background jobs reliably across multiple web servers by storing schedules in PostgreSQL so jobs survive server restarts.

USE CASE 3

Add a task queue to a FastAPI or Django app that processes jobs asynchronously using asyncio without a separate broker service.

USE CASE 4

Set up a monthly billing job that always fires on the same day of the month regardless of varying month lengths.

Tech stack

PythonasyncioTrioPostgreSQLMySQLSQLiteMongoDBRedis

Getting it running

Difficulty · moderate Time to first run · 30min

Distributed setups need an external database (PostgreSQL/MySQL) and optionally Redis or MQTT for event brokering.

No license information was mentioned in the explanation.

In plain English

APScheduler (Advanced Python Scheduler) is a task scheduling and task queue library for Python. It allows developers to set up jobs that run automatically at specific times, on repeating schedules, or after fixed intervals, without building that infrastructure from scratch. It can also act as a plain job queue if time-based scheduling is not needed. The library supports four built-in scheduling patterns. Cron-style scheduling targets specific times or days in a familiar format. Interval-based scheduling runs tasks every fixed number of minutes, hours, or similar units. Calendar-based scheduling runs tasks at intervals measured in months or years, always at the same time of day. One-off scheduling runs a task exactly once at a specific date and time. These patterns can be mixed and matched using combining triggers for more complex needs. APScheduler works with both traditional thread-based Python code and asynchronous code using asyncio or Trio. It integrates with web applications built on WSGI or ASGI frameworks, making it a practical fit for most Python web stacks. For applications spread across multiple servers or processes, APScheduler supports persistent storage so schedules and jobs survive process restarts. Storage backends include PostgreSQL, MySQL, SQLite, and MongoDB. When using multiple scheduler or worker instances together, event brokers handle coordination between them. The built-in broker options are PostgreSQL, Redis, and MQTT. Jobs stored in the shared data store are visible to all nodes, allowing both reliability and horizontal scaling. Extra controls include a cap on how many concurrent copies of the same job can run, a deadline for how late a job is allowed to start before being skipped, and optional jitter (a small random delay added to each job) to avoid all jobs firing at the exact same instant. The current v4 series is a pre-release, and the project advises against using it in production.

Copy-paste prompts

Prompt 1
Using APScheduler v4 with asyncio, write a Python script that runs a function every 30 minutes and also runs a separate function every day at 9am using cron syntax.
Prompt 2
I have an APScheduler job that hits an external API. Show me how to set a max_instances limit so only one copy runs at a time, and configure a deadline so late-firing jobs are skipped.
Prompt 3
Set up APScheduler with a PostgreSQL job store so that scheduled jobs persist across application restarts. Show the connection string setup and how to add a job to the persistent store.
Prompt 4
I want to add random jitter to my APScheduler interval jobs to avoid thundering-herd on my database. Show me the trigger configuration to add up to 60 seconds of jitter to an every-5-minute job.
Prompt 5
Configure APScheduler to coordinate jobs across three worker processes using a Redis event broker and a shared PostgreSQL data store.
Open on GitHub → Explain another repo

← agronholm on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.