skillfed

aiojobs

Job scheduler for managing background tasks (asyncio)

aiojobs v1.4.0 354.1K downloads/30d#7,298 on PyPI927
Permissive license Apache 2 Active released

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 aiojobs

uv

uv add aiojobs

poetry

poetry add aiojobs

Installing 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

Development Status :: 5 - Production/StableFramework :: AsyncIOIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseOperating System :: MacOS :: MacOS XOperating System :: Microsoft :: WindowsOperating System :: POSIXProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Topic :: Software Development

Tags

asyncio background task schedulermanage concurrent async jobsasyncio task lifecycle controlbackground task queue asyncioasync job schedulinggraceful asyncio shutdownshield asyncio tasks
asynciobackground-jobstask-scheduling

More Software Development packages