Skip to main content

A task manager for Fastapi. Robust Scheduling, Distributed Safety

Project description

FastAPI Task Manager

Lightweight, efficient and fast to code scheduled task management system built on FastAPI

Lightweight, efficient and fast to code scheduled task management system built on FastAPI.

PyPI - Version PyPI - Downloads PyPI - License PyPI - Python Version Pepy Total Downloads Coveralls


Documentation: https://fastapi-task-manager.morando.uk

Source Code: https://github.com/Morry98/fastapi-task-manager


Overview

FastAPI Task Manager is a lightweight and efficient scheduled task management system built on top of FastAPI and Redis. It is designed to help developers easily create, manage, and execute scheduled tasks within their FastAPI applications.

Key Features

  • FastAPI Extension - Built as an extension to FastAPI, making it easy to integrate into existing FastAPI applications and leverage its features
  • Redis-Based - Uses Redis as the backend for storing task information, ensuring high performance and single-instance execution
  • Fast to Code - Increase the speed to develop scheduled tasks by about 400% to 500%, only a wrapper function is needed*
  • Fewer Bugs - Reduce about 60% of human (developer) induced errors managing lock, Redis keys and task execution*
  • Scheduled Tasks - Provides a simple and intuitive API for defining and scheduling tasks to run at specific intervals or times
  • Task Management - Includes FastAPI router to manage tasks, such as pausing, resuming, and monitoring execution information
  • Easy to Use - Designed to be easy to use and learn. Less time reading docs
  • Robust - Get production-ready code

* estimation based on real production task migrated to FastAPI task manager from custom "cron job" solution.

Requirements

FastAPI Task Manager stands on the shoulders of giants:

  • FastAPI - Modern, fast web framework for building APIs
  • Redis - In-memory data structure store for task storage and locking

Installation

You need to have a FastAPI project set up. If you don't have one, check the FastAPI installation tutorial.

Install FastAPI Task Manager using pip:

pip install fastapi-task-manager

Quick Example

Here's a simple example to get you started:

from fastapi import FastAPI
from fastapi_task_manager import TaskManager, task, TaskGroup
from fastapi_task_manager import Config as ManagerConfig
from pydantic_settings import BaseSettings, SettingsConfigDict


class Config(BaseSettings):
    model_config = SettingsConfigDict(
        # `.env.prod` takes priority over `.env`
        env_file=(".env", ".env.prod"),
        extra="forbid",
    )

    # --------- Redis config variables ---------
    redis_host: str | None = None
    redis_port: int = 6379
    redis_password: str | None = None
    redis_db: int = 0
    # --------- End of redis config variables ---------

    # --------- App config variables ---------
    app_name: str = "my_fastapi_app"
    concurrent_tasks: int = 3
    # --------- End of app config variables ---------

CONFIG = Config()

app = FastAPI()
router = APIRouter()

task_manager = TaskManager(
    config=ManagerConfig(
        redis_host=CONFIG.redis_host,
        redis_port=CONFIG.redis_port,
        redis_password=CONFIG.redis_password,
        redis_db=CONFIG.redis_db,
        concurrent_tasks=CONFIG.concurrent_tasks,
        redis_key_prefix=CONFIG.app_name,
    ),
    app=app,
)
my_example_task_group = TaskGroup(
  tags=["example"],
  name="My Example Task Group",
)
task_manager.add_task_group(my_example_task_group)

manager_router = task_manager.get_manager_router()
router.include_router(
  manager_router,
  prefix="/task-manager",
  tags=["task-manager"],
)

app.include_router(router)

@my_example_task_group.add_task(
  "*/5 * * * *",  # Run every 5 minutes
  name="my_scheduled_task",
  description="This is my scheduled task"
)
async def my_scheduled_task():
    print("Task executed!")
    # Your task logic here

License

This project is licensed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_task_manager-1.0.0rc8.tar.gz (35.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_task_manager-1.0.0rc8-py3-none-any.whl (44.1 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_task_manager-1.0.0rc8.tar.gz.

File metadata

  • Download URL: fastapi_task_manager-1.0.0rc8.tar.gz
  • Upload date:
  • Size: 35.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fastapi_task_manager-1.0.0rc8.tar.gz
Algorithm Hash digest
SHA256 a2c4f6a89cdcaf81a2818de6d11c031cfe4608a5bf0d5a63562b3760379419c5
MD5 94c2283a82ac80fd3308992aa8ed729b
BLAKE2b-256 38a7eaa399d82eed6dd5ff8c4821edd042ce2d4477722df53b9e32b594732794

See more details on using hashes here.

File details

Details for the file fastapi_task_manager-1.0.0rc8-py3-none-any.whl.

File metadata

  • Download URL: fastapi_task_manager-1.0.0rc8-py3-none-any.whl
  • Upload date:
  • Size: 44.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fastapi_task_manager-1.0.0rc8-py3-none-any.whl
Algorithm Hash digest
SHA256 c09c019d5f1a7934568bb1e309e5b0a7d6ee52c9563cb173b6aa092f3987b22e
MD5 26ee4214d9a601d06ed5e632554c451c
BLAKE2b-256 7b3dc29fa717c7fac5064ba1dc4ce69ef79871ffc9e8a81bdad4feba31e2081b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page