FastAPI Factory Utilities
When to use this skill?
- Use this skill when building FastAPI microservices with the fastapi_factory_utilities library.
- Use this skill when implementing plugin-based architectures in FastAPI applications.
- Use this skill when setting up OAuth2/OIDC authentication with Hydra or Kratos.
- Use this skill when configuring MongoDB with Beanie ODM in FastAPI applications.
- Use this skill when implementing RabbitMQ message brokers with AioPika.
- Use this skill when setting up background task processing with Taskiq and Redis.
- Use this skill when configuring OpenTelemetry for distributed tracing and metrics.
- Use this skill when implementing structured logging with structlog.
- Use this skill when using dependency injection patterns with FastAPI's Depends system.
- Use this skill when creating mock resources for testing (AioHttp, ODM repositories).
- Use this skill when implementing repository patterns for data access.
- Use this skill when configuring health checks and status services.
- Use this skill when implementing JWT Bearer authentication with JWKS verification.
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 |
Security
| Reference | Description |
|---|---|
| JWT Authentication | JWT Bearer validation, JWKS store, custom verifiers |
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
Source: DeerHide/fastapi_factory_utilities — distributed by TomeVault.