- Settings class with nested configurations using pydantic-settings
- Environment-based configuration with
.envsupport - Validation and type safety for all configuration values
- Safe configuration dumping (excludes sensitive data)
- Sub-configurations:
- DatabaseSettings (async PostgreSQL with connection pooling)
- CacheSettings (Redis with connection pooling)
- SecuritySettings (JWT, encryption, passwords)
- LoggingSettings (structured logging with structlog)
- MetricsSettings (Prometheus metrics)
- RateLimitingSettings (configurable rate limits)
- KafkaSettings (event streaming)
- ServiceDiscoverySettings (Go service URLs)
- HealthCheckSettings (health monitoring)
- Async SQLAlchemy 2.0 setup with asyncpg driver
- Connection pooling and health checks
- Base model class with common functionality
- Model mixins:
- UUIDPrimaryKeyMixin (UUID primary keys)
- TimestampMixin (created_at, updated_at)
- SoftDeleteMixin (soft delete functionality)
- TenantMixin (multi-tenant support)
- UserTrackingMixin (audit trails)
- SlugMixin (URL-friendly slugs)
- VersionMixin (optimistic locking)
- MetadataMixin (JSON metadata fields)
- BaseRepository with full CRUD operations
- Database lifecycle management
- Migration support with Alembic
- Async Redis client with connection pooling
- CacheManager with JSON serialization
- Cache decorators for function result caching
- CacheKeyBuilder for consistent key generation
- Support for:
- Basic get/set operations
- Multi get/set operations
- Sets and counters
- TTL management
- Pattern-based cache invalidation
- User/tenant/workspace scoped keys
- Rate limiting keys
- Distributed locks
- Standardized exception hierarchy:
- PyAirtableError (base exception)
- ValidationError (422 status)
- NotFoundError (404 status)
- PermissionError (403 status)
- AuthenticationError (401 status)
- RateLimitError (429 status)
- ServiceUnavailableError (503 status)
- DatabaseError, CacheError, ExternalServiceError
- BusinessLogicError, ConflictError, TimeoutError
- Rich error context with details
- Structured error responses
- HTTP status code mapping
- Structured logging with structlog
- JSON and console output formats
- Automatic sensitive data masking
- Context-aware logging with:
- Service information
- Request tracing
- User/tenant context
- Configurable log levels
- Integration with FastAPI middleware
- BaseModel with common functionality
- Foundation for User, Tenant, Workspace models
- Model serialization and validation
- Integration with database mixins
- AsyncTestCase for async test support
- Mock helpers and context managers
- Database testing utilities
- Cache testing utilities
- Factory pattern support
- Test fixtures
- pyproject.toml: Modern Python packaging with all dependencies
- Makefile: Comprehensive development commands
- .env.example: Complete environment variable template
- .gitignore: Python-specific ignore patterns
- LICENSE: MIT license
- Ruff configuration: Modern Python linting and formatting
- MyPy configuration: Strict type checking
- Pytest configuration: Test runners with coverage
- Pre-commit hooks: Automated code quality checks
- Configuration loading
- Database operations
- Cache operations
- Error handling
- Application lifecycle management
- Complete FastAPI application setup
- Database and cache dependencies
- Error handling middleware
- Health check endpoints
- Structured logging integration
- Application lifespan management
- All I/O operations are async/await compatible
- Connection pooling for database and cache
- Proper resource cleanup and lifecycle management
- Comprehensive type hints throughout
- Pydantic models for validation
- MyPy strict mode compliance
- Structured logging with context
- Health check endpoints
- Metrics collection ready
- Error tracking and reporting
- Tenant-scoped models and caching
- User tracking and audit trails
- Permission-aware error handling
- Async test utilities
- Mock generators and factories
- Database test setup/teardown
- Cache testing helpers
# Install package
pip install -e .
# Install with development dependencies
pip install -e .[test,dev]
# Run tests
make test
# Format and lint code
make format lint
# Type checking
make type-check
# Build package
make buildThis shared library provides the foundation for Python microservices in the PyAirtable ecosystem:
- Consistent configuration across all services
- Standardized database patterns with async support
- Unified caching strategy with Redis
- Common error handling and response formats
- Structured logging for observability
- Testing utilities for reliable tests
- FastAPI integration patterns
Services can extend this library by:
- Adding service-specific models
- Implementing business logic repositories
- Creating custom middleware
- Adding service-specific error types
- Extending the configuration with service settings
The library ensures consistency, reduces boilerplate, and provides production-ready components for building scalable Python microservices.