A production-grade implementation of asynchronous Python concepts, designed to mock and manage high-concurrency LLM streaming infrastructure.
This repository demonstrates how to bridge the gap between standard Python scripting and enterprise AI backend engineering. Moving from a MERN stack background, this project enforces:
- Strict Concurrency: Using Python 3.11+
asyncio.TaskGroupto manage parallel I/O bound LLM requests without blocking the Event Loop. - Resilience: Custom
@async_retrydecorators implementing Exponential Backoff and Jitter to prevent Thundering Herd problems during API outages. - Telemetry: Custom
@async_timerdecorators leveragingfunctools.wrapsto preserve function metadata for AI observability tools (like LangSmith). - Streaming: Utilizing Asynchronous Generators (
yield) to simulate Server-Sent Events (SSE) for token-by-token LLM output. - Type Safety:
Pydanticmodels for strict data validation on streamed chunks.
Developed using uv for lightning-fast dependency management.
Make sure you have Python 3.11+ and uv installed.
If you don't have uv installed, get it via:
# macOS/Linux
curl -LsSf [https://astral.sh/uv/install.sh](https://astral.sh/uv/install.sh) | sh
# Windows
powershell -c "irm [https://astral.sh/uv/install.ps1](https://astral.sh/uv/install.ps1) | iex"- Clone the repository:
git clone https://github.com/Piyushtiwari919/Python-backend-lab.git
cd Python-backend-lab
- Install dependencies:
uv sync
- Run the application:
uv run python -m src.main
This backend architecture acts as the foundational layer for AI agent workflows. The concepts validated here—specifically non-blocking generator streams and strict task lifecycle management—are designed to be integrated seamlessly with asynchronous WebSocket clients and React/Next.js frontends.