The AsyncIO Task Runner (Coro Runner) is a Python utility designed for managing concurrent asynchronous tasks using the built-in asyncio module. It provides an efficient way to execute multiple tasks in a single-threaded environment with customizable concurrency limits.
This project leverages asyncio (introduced in Python 3.4) to simplify handling of asynchronous workloads, making it ideal for lightweight, scalable applications.
- Configurable Concurrency: Define the number of concurrent tasks when initializing the runner.
- Efficient Task Management: Run multiple tasks concurrently with streamlined execution control.
- Worker Queue: Multiple queue can be configued along with their priority.
- Monitoring Tool Integration: Support for real-time task monitoring and analytics. We have report now.
- Robust Logging: Detailed logging to track task execution and debug issues. Debug log has been placed.
- Low-Level API: Features such as callbacks, acknowledgments, and error handling for advanced use cases.
- More Backends: I have plan to have multiple backends and room to develop according to user's choice too.
To install coro-runner, use pip:
pip install coro-runner
pip install coro-runner[redis] # If you want to use RedisBackend-
Define and schedule tasks:
from coro_runner import CoroRunner runner = CoroRunner(concurrency=10) # Add your tasks from anywhere b runner.add_task(your_task, args=[1,2,3], kwargs={"test": "OK!"}) # your_task must be a async function
Declare the runner once and call from everywhere.
- Python 3.12 or later
- Uv for dependency management
-
Clone the repository:
git clone https://github.com/iashraful/async-coro-runner.git cd async-coro-runner -
Run any command using
uv:uv run <Command>
-
Install dependencies:
uv sync
Run the test suite to verify the setup:
uv run pytest -sSample Output:
Task started: Task-1
Task ended: Task-1
...
The project includes an example API implemented with FastAPI. It demonstrates how to use the task runner to manage asynchronous tasks.
-
Run the API server:
uvicorn example:app --reload
-
Trigger tasks using the endpoint:
GET /fire-task?count=25
Contributions are welcome! Follow these steps to get started:
- Fork the repository and create a new branch for your feature or bug fix.
- Write tests for your changes.
- Open a pull request with a clear description of your contribution.