Shared foundation for fastapi-fabric — DB engine, config loading, HTTP middleware, rate limiting.
Project description
fastapi-fabric-core
Shared foundation for the fastapi-fabric ecosystem. Provides database engine management, config loading, HTTP middleware, and utilities used by all other packages.
Install
fastapi-fabric-core is installed automatically as a dependency of any fastapi-fabric extra:
pip install fastapi-fabric[auth]
What's included
| Feature | Description |
|---|---|
| Config loading | config.yaml + environment variable overrides via pydantic-settings |
| DB engine | Async SQLAlchemy engine init, session factory, BaseSchema for ORM models |
| HTTP logging | Structured request/response logging middleware |
| Request ID | Per-request UUID propagated through headers and logs |
| Rate limiting | In-memory sliding window rate limiter (single-process) |
| Pagination | Shared Page response model |
| Error helpers | Standard error response shapes |
Config
Create config.yaml next to your app entry point:
auth:
secret_key: "your-random-32-char-secret"
system_admin_password: "changeme"
server:
debug: false
secure_cookies: true # set false behind HTTP (dev only)
The config path is resolved relative to the file that first imports fastapi_fabric.core.config. Override with the CONFIG_YAML environment variable.
from fastapi_fabric.core.config import get_config
config = get_config() # cached; reads config.yaml once
Database
from fastapi_fabric.core.db import DatabaseModel, get_engine, get_session, init_engine
# Call once at startup
init_engine("sqlite+aiosqlite:///./app.db")
# or
init_engine("postgresql+asyncpg://user:pass@localhost/mydb")
# Create tables for all registered ORM models
engine = get_engine()
async with engine.begin() as conn:
await conn.run_sync(DatabaseModel.metadata.create_all)
# Use in FastAPI routes
async def my_route(session: AsyncSession = Depends(get_session)):
...
ORM models subclass DatabaseModel (never SQLAlchemy's DeclarativeBase directly):
from fastapi_fabric.core.db import DatabaseModel
from sqlalchemy.orm import Mapped, mapped_column
class MyModel(DatabaseModel):
__tablename__ = "my_table"
id: Mapped[str] = mapped_column(primary_key=True)
name: Mapped[str]
Middleware
Add structured HTTP access logging to your app:
from fastapi_fabric.core.middleware.http_log import HTTPAccessLogMiddleware
app.add_middleware(HTTPAccessLogMiddleware)
Per-request IDs (UUIDv7) are available via a dependency rather than middleware:
from fastapi_fabric.core.dependencies.request_id import get_request_id
@app.get("/items")
async def list_items(request_id: str = Depends(get_request_id)):
...
Rate limiting
from fastapi_fabric.core.dependencies.rate_limit import RateLimitConfig, rate_limiter
@app.post(
"/login",
dependencies=[Depends(rate_limiter())],
openapi_extra={"x-rate-limit": RateLimitConfig(limit=5, window=60)},
)
async def login():
...
Limits are per-IP (unauthenticated) or per-principal (authenticated). State is in-process and does not synchronize across workers.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_fabric_core-0.1.0.tar.gz.
File metadata
- Download URL: fastapi_fabric_core-0.1.0.tar.gz
- Upload date:
- Size: 27.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68f9484287e9f40b7b62f567b0e2f57c5db1c23d9ba7035823b16f421f7cae52
|
|
| MD5 |
5ef79d973dc2b34dfcd35eba354502f5
|
|
| BLAKE2b-256 |
337ec1fd659c32bab6b3112772fd0cfc1906fb5489eca587d971d48d3cd064c3
|
File details
Details for the file fastapi_fabric_core-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_fabric_core-0.1.0-py3-none-any.whl
- Upload date:
- Size: 27.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67eef5187a84d9c1f5a9ca709f9fd0197394f1bb26b0c6382b1b4f559d9c6d8a
|
|
| MD5 |
f0f10119be513b09384c4d25dc429a95
|
|
| BLAKE2b-256 |
ea6f541f4dc420e611ad012bcc95a8027a69ef2b92730f06fa24ba26009f6956
|