FastAPI Factory Utilities
A library for building production-ready FastAPI microservices with plugin-based architecture.
Quick Start
See assets/quick_start_example.py for a minimal application setup.
Dependency Injection and Testing
The library uses FastAPI's Depends for dependency injection. Plugins expose resources via dependency functions (e.g., AioHttpResourceDepends, depends_status_service, depends_scheduler_component).
For testing, several plugins provide mockers to create mock resources:
- •AioHttp:
build_mocked_aiohttp_resource,build_mocked_aiohttp_response- Mock HTTP clients and responses - •ODM:
AbstractRepositoryInMemory- In-memory repository for unit testing without MongoDB - •See AioHttp reference and Repository Pattern for detailed mocking examples
Reference Documentation
Core
| Reference | Description |
|---|---|
| Application Framework | ApplicationAbstract, builders, plugin lifecycle |
| Configuration | YAML loading, environment variables, type-safe config |
| Logging | Structured logging with structlog |
| Status Service | Health and readiness monitoring |
Plugins
| Reference | Description |
|---|---|
| ODM Plugin (MongoDB) | MongoDB/Beanie integration, document models |
| Repository Pattern | Type-safe data access, in-memory testing |
| AioHttp HTTP Client | HTTP client with connection pooling, mocking utilities |
| AioPika RabbitMQ | Message publishing and consuming |
| OpenTelemetry | Distributed tracing and metrics |
| Taskiq Tasks | Background task processing with Redis |
Services
| Reference | Description |
|---|---|
| Hydra Service | OAuth2 token introspection, JWKS, client credentials |
| Kratos Service | Identity management, session validation |
| Audit Service | Event auditing with RabbitMQ |
Utilities
| Reference | Description |
|---|---|
| Pagination | Type-safe pagination types |
| Ory Utilities | Ory API pagination helpers |
Best Practices
- •Plugin Order - Load plugins in dependency order (ODM before repositories)
- •Configuration - Use YAML files with
${ENV_VAR:default}syntax - •Lifecycle - Keep
configure()lightweight, useon_startup()for connections - •Observability - Enable OpenTelemetry in production
- •Logging - Use JSON mode in production for log aggregation
- •Testing - Use mockers from aiohttp plugin for HTTP client tests