Registry / workflow / apscheduler

apscheduler

JSON →
library3.11.3pypypi✓ verified 25d ago

APScheduler is a flexible, in-process task scheduler library for Python, offering cron-like capabilities. It allows you to schedule Python code to be executed later, either once or periodically, within your application. The current stable version is 3.11.2. It supports various scheduler types, job stores (e.g., in-memory, SQLAlchemy, MongoDB), and triggers (date, interval, cron, calendarinterval). APScheduler is primarily meant to be run inside existing applications, not as a standalone daemon. It is actively maintained with a stable 3.x series and an ongoing pre-release 4.x series with significant architectural changes.

pip install apscheduler
INSTALL
IMPORT
SIG · APSCHEDULER
A
apscheduler
workflowpythonv3.11.3
Install
2.4s avg
Import
389ms
Disk
42MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.11.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 0.416s · 43.8MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 2.4s · import 0.363s · 42MB
42MB installed
● package 42MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BackgroundScheduler
from apscheduler.schedulers.background import BackgroundScheduler
BlockingScheduler
from apscheduler.schedulers.blocking import BlockingScheduler
AsyncIOScheduler
from apscheduler.schedulers.asyncio import AsyncIOScheduler
IntervalTrigger
from apscheduler.triggers.interval import IntervalTrigger
CronTrigger
from apscheduler.triggers.cron import CronTrigger
DateTrigger
from apscheduler.triggers.date import DateTrigger

This quickstart demonstrates a `BackgroundScheduler` which runs jobs in a separate thread without blocking the main application. It schedules a simple function to run every 5 seconds using an `IntervalTrigger`. The `while True: time.sleep(2)` loop keeps the main thread alive, allowing the background scheduler to operate. A `KeyboardInterrupt` handler ensures a graceful shutdown of the scheduler.

import time from datetime import datetime from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.triggers.interval import IntervalTrigger def my_job(): print(f"Hello from APScheduler! The time is: {datetime.now()}") if __name__ == '__main__': scheduler = BackgroundScheduler() scheduler.add_job(my_job, IntervalTrigger(seconds=5), id='my_scheduled_job') print('Starting scheduler. Press Ctrl+C to exit.') scheduler.start() try: # This is here to simulate application activity (for BackgroundScheduler) while True: time.sleep(2) except (KeyboardInterrupt, SystemExit): scheduler.shutdown() print("Scheduler shut down successfully.")
Debug
Known issues
breakingAPScheduler 4.0 (currently in pre-release) introduces significant breaking changes. Key changes include a split of the 'job' concept into 'Task', 'Schedule', and 'Job', the merging of 'workers' into 'schedulers', removal of synchronous interfaces for event brokers and data stores, and a completely overhauled job store system that is incompatible with 3.x data. The `add_job()` method is renamed to `add_schedule()`.
fix
Refer to the APScheduler 4.x migration guide before upgrading. A direct migration path for persistent job store data from 3.x to 4.x is not automatically available at the time of writing and may require manual recreation or a specific migration tool when 4.x is stable.
affects: 3.x to 4.x (pre-release)
gotchaWhen using `BackgroundScheduler`, if your main script finishes, the scheduler will also stop. You need to keep the main thread alive (e.g., with `time.sleep()`, a web server, or another blocking call) for the background jobs to execute.
fix
For standalone scripts, use `while True: time.sleep(interval)` with a `try...except KeyboardInterrupt` block, or use `BlockingScheduler` if the scheduler is the only thing running in your process. For web applications, ensure the scheduler's lifecycle is tied to the application's.
affects: 3.x
gotchaFunctions scheduled with persistent job stores (e.g., SQLAlchemyJobStore, MongoDBJobStore) must be importable by a textual reference (e.g., 'mymodule:my_function'). Lambda functions, bound methods, or nested functions often cannot be properly serialized and deserialized across application restarts or different processes, leading to `ValueError`.
fix
Ensure scheduled functions are top-level functions in a module, or static/class methods, and provide their fully qualified path (e.g., `scheduler.add_job('my_module.my_function', ...)`).
affects: 3.x
gotchaSharing a persistent job store among multiple APScheduler *instances* (in different processes or nodes) directly can lead to incorrect behavior like duplicate job execution or missed jobs, as APScheduler 3.x does not have built-in interprocess synchronization for job stores.
fix
For multi-process or multi-node deployments, APScheduler 3.x typically requires a single, dedicated scheduler process that manages jobs, with other processes communicating with it. Alternatively, consider using a distributed task queue (like Celery) if strong guarantees and distributed coordination are critical. APScheduler 4.x aims to address this with enhanced data stores and event brokers.
affects: 3.x
deprecatedSupport for `pytz` time zones has been deprecated in version 3.11.0 in favor of `zoneinfo` (or `backports.zoneinfo` for Python < 3.9).
fix
Migrate your timezone definitions to use `zoneinfo` (built-in in Python 3.9+) or `backports.zoneinfo` for older Python versions. For example, `from zoneinfo import ZoneInfo` instead of `from pytz import timezone`.
affects: >=3.11.0
Errors
Common errors & fixes
ImportError: cannot import name 'AsyncIOSchedular'
The class name 'AsyncIOSchedular' is misspelled; the correct spelling is 'AsyncIOScheduler'.
fix
from apscheduler.schedulers.asyncio import AsyncIOScheduler
AttributeError: module 'apscheduler.schedulers.asyncio' has no attribute 'get_event_loop'
The 'asyncio' module from APScheduler is being imported instead of Python's standard 'asyncio' module.
fix
import asyncio
ImportError: cannot import name 'monthrange'
A local file named 'calendar.py' is shadowing Python's standard 'calendar' module.
fix
Rename the local 'calendar.py' file to avoid name conflicts.
ModuleNotFoundError: No module named 'apscheduler'
The APScheduler library is either not installed, installed in a different Python environment than the one being used, or there's a naming conflict with a local file named 'apscheduler.py'.
fix
Ensure APScheduler is installed in your current Python environment using `pip install apscheduler`. If using a virtual environment, activate it before installing. If a local file `apscheduler.py` exists, rename it.
ValueError: This Job cannot be serialized since the reference to its callable (<bound method xxxxxxxx.on_crn_field_submission of <__main__.xxxxxxx object at xxxxxxxxxxxxx>>) could not be determined. Consider giving a textual reference (module:function name) instead.
This error occurs when trying to schedule a function that cannot be reliably serialized (e.g., lambda functions, bound methods, nested functions) which is required by persistent job stores or process pool executors for job persistence or inter-process communication.
fix
Define the job function as a module-level function, a static method, or a class method. Pass a textual reference (e.g., 'your_module.your_function') instead of a direct callable reference to `add_job`.
Upgrade
Version history
3.11.3latest on PyPI · released Jun 28, 2026
Audit
Dependencies
tzlocalrequiredRequired for local timezone support if not using `zoneinfo` (Python < 3.9)
backports.zoneinforequiredRequired for `zoneinfo` timezone support on Python versions < 3.9
pymongooptionalFor MongoDBJobStore
SQLAlchemyoptionalFor SQLAlchemyJobStore (supports various relational databases)
redisoptionalFor RedisJobStore or RedisEventBroker
asyncpgoptionalFor AsyncpgEventBroker
Agent activity
95 hits · last 30 days
node
88
OpenAI (training)
1
Resources