A comprehensive shared library for PyAirtable microservices, providing common functionality and utilities for building robust, scalable Python services.
- config: Configuration management with pydantic-settings
 - database: SQLAlchemy setup with async support
 - cache: Redis client with async support
 - middleware: FastAPI middleware (auth, logging, metrics, rate limiting)
 - errors: Standardized error handling
 - logger: Structured logging with structlog
 - metrics: Prometheus metrics helpers
 - health: Health check utilities
 - utils: Common utilities
 
- User, Tenant, Workspace models: Core domain models
 - Common DTOs and responses: Standardized API responses
 - Pagination helpers: Consistent pagination across services
 - Event schemas: Event-driven architecture support
 
- HTTP clients: For Go services (auth, permission, etc.)
 - Event bus client: Kafka integration
 - Service discovery: Service discovery helpers
 
- Test database setup: Automated test database management
 - Mock generators: Factory-based test data generation
 - Async test helpers: Utilities for async testing
 
- Python 3.11+
 - FastAPI
 - SQLAlchemy 2.0+
 - Redis
 - PostgreSQL (for async database support)
 
pip install pyairtable-python-sharedFor development:
pip install pyairtable-python-shared[test,dev]from pyairtable_shared.config import settings
# Access configuration
print(settings.database_url)
print(settings.redis_url)from pyairtable_shared.database import get_async_session
async def example():
    async with get_async_session() as session:
        # Use session for database operations
        passfrom pyairtable_shared.cache import get_redis_client
async def example():
    redis = await get_redis_client()
    await redis.set("key", "value")
    value = await redis.get("key")from fastapi import FastAPI
from pyairtable_shared.middleware import (
    add_auth_middleware,
    add_logging_middleware,
    add_metrics_middleware,
    add_rate_limiting_middleware,
)
app = FastAPI()
# Add middleware
add_auth_middleware(app)
add_logging_middleware(app)
add_metrics_middleware(app)
add_rate_limiting_middleware(app)from pyairtable_shared.logger import get_logger
logger = get_logger(__name__)
logger.info("Service started", service="my-service")
logger.error("Error occurred", error="details", user_id="123")from pyairtable_shared.models import User, Tenant, Workspace
from pyairtable_shared.models.dto import UserResponse, PaginatedResponse
# Use shared models
user = User(email="user@example.com", name="John Doe")
response = UserResponse.from_orm(user)git clone https://github.com/pyairtable/pyairtable-python-shared.git
cd pyairtable-python-shared
pip install -e .[test,dev]# Run all tests
pytest
# Run with coverage
pytest --cov=src/pyairtable_shared
# Run only unit tests
pytest -m unit
# Run only integration tests
pytest -m integration# Format code
ruff format
# Lint code
ruff check
# Type checking
mypy src/pre-commit install
pre-commit run --all-filesThe library is organized into several packages:
src/pyairtable_shared/
├── __init__.py
├── config/           # Configuration management
├── database/         # Database utilities
├── cache/           # Redis cache utilities
├── middleware/      # FastAPI middleware
├── errors/          # Error handling
├── logger/          # Structured logging
├── metrics/         # Prometheus metrics
├── health/          # Health checks
├── utils/           # Common utilities
├── models/          # Shared models
├── clients/         # HTTP clients
└── testing/         # Test utilities
- Fork the repository
 - Create a feature branch
 - Make changes with tests
 - Run the test suite
 - Submit a pull request
 
MIT License - see LICENSE file for details.