aiojobs
Job scheduler for managing background tasks (asyncio)
What it is and what it does
aiojobs is a task scheduler for asyncio applications that manages the lifecycle of background jobs spawned during runtime. It solves the problem of uncontrolled task cancellation during application shutdown by providing a context manager that tracks all spawned tasks and waits for them to complete before closing. The library includes a Scheduler class that accepts coroutines via spawn(), tracks their execution, and ensures graceful termination.
The package is typically used in asyncio web applications (especially with aiohttp) to run background work—such as cleanup, notifications, or long-running operations—without losing tasks on shutdown. It also provides a shield() method to protect tasks from cancellation while keeping them tracked, solving a gap in asyncio.shield() that loses visibility of shielded tasks. The single runtime dependency (async-timeout) keeps installation lightweight.
Use it for:
- Run background cleanup or maintenance tasks in web handlers without losing them on shutdown
- Spawn multiple long-running coroutines and ensure all complete before application exit
- Shield critical tasks from cancellation while maintaining scheduler visibility for graceful shutdown
- Integrate background job management into aiohttp.web applications via the built-in aiohttp plugin
- Manage task lifecycle in asyncio applications where manual task tracking is error-prone
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
aiojobs provides a scheduler for spawning and managing background asyncio tasks with controlled lifecycle, including graceful shutdown and task shielding from cancellation.
Yes. aiojobs is actively maintained, production-stable, has no known vulnerabilities, and solves a real problem in asyncio applications—uncontrolled task loss during shutdown. Low install friction and permissive licensing make it a safe, practical choice for any asyncio project needing reliable background task management.
Install
aiojobs on PyPI
pip
pip install aiojobsuv
uv add aiojobspoetry
poetry add aiojobsInstalling aiojobs
Before you install
Low install friction with a single runtime dependency (async-timeout). Actively maintained with recent commits and stable production status across Python 3.9–3.13.
License in practice
Licensed under Apache 2 (permissive), allowing free use, modification, and distribution in both open and proprietary projects with minimal restrictions.
Quickstart
pip install aiojobs
import asyncio
import aiojobs
async def background_task(delay):
await asyncio.sleep(delay)
async def main():
async with aiojobs.Scheduler() as scheduler:
await scheduler.spawn(background_task(1.0))
await asyncio.sleep(0.5)
asyncio.run(main())
Requires Python 3.9 or later; asyncio is built-in but the application must use async/await syntax.
Verify before relying
- Whether the scheduler supports priority queues or task ordering beyond FIFO spawn order
- Maximum recommended number of concurrent jobs before performance degrades
- Whether aiohttp integration is required or optional for core scheduler functionality
Package facts
| License | Apache 2 (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — async-timeout |
| Maintenance | actively maintained — 496 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 354,079/month — #7,298 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: aiojobs-1.4.0-py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
aiorunProvides a simplified entry point for asyncio…
permissive · top 15,000 on PyPI
aiotoolsaiotools provides idiomatic asyncio utilities…
permissive · top 15,000 on PyPI
aiomonitorAdds a concurrent monitor and interactive…
permissive · top 15,000 on PyPI
APSchedulerAPScheduler lets you schedule Python code to…
permissive · top 1,000 on PyPI
django-apschedulerAdds persistent job scheduling to Django…
permissive · top 15,000 on PyPI
schedulerAn in-process job scheduler for Python that…
copyleft · top 15,000 on PyPI
django-background-tasksDjango Background Tasks is a database-backed…
permissive · top 15,000 on PyPI
timeloopTimeloop runs periodic tasks at fixed intervals…
permissive · top 15,000 on PyPI
aiometeraiometer is a concurrency scheduling library…
permissive · top 15,000 on PyPI
aiodebugaiodebug provides monitoring and testing…
permissive · top 15,000 on PyPI