Health checks, config validation, and structured logging for FastAPI
Project description
stacklink
Health checks, config validation, and structured logging for FastAPI — in three lines of code.
Built for solo devs and small teams who want production-grade infrastructure without the setup overhead.
Install
pip install stacklink
Quick start
from fastapi import FastAPI
from stacklink import Config, Field, health, logger
app = FastAPI()
class AppConfig(Config):
env: str = Field(required=True)
service: str = Field(default="my-api")
port: int = Field(default=8080)
db_url: str = Field(required=True, secret=True)
config = AppConfig()
logger.configure(config)
logger.info("server starting", port=config.port)
health.register(app, config=config)
That's it. You now have:
- Validated, typed config from
.envand environment variables - Structured JSON logging to stdout
/healthzand/readyzendpoints on your FastAPI app
Modules
Config
Reads .env files and environment variables. Validates types. Fails loudly at startup if anything is wrong. Redacts secrets from output.
from stacklink import Config, Field
class AppConfig(Config):
env: str = Field(required=True)
port: int = Field(default=8080)
db_url: str = Field(required=True, secret=True)
config = AppConfig()
config.as_dict() # {"env": "production", "port": 8080, "db_url": "***"}
Supported types: str, int, float, bool. Bool coerces from true/false/1/0/yes/no.
Logger
Structured JSON logging. Every line is machine-parseable. Auto-tags with service name and environment when configured.
from stacklink import logger
logger.info("request handled", method="GET", path="/users", status=200)
# {"timestamp": "...", "level": "INFO", "message": "request handled", "method": "GET", "path": "/users", "status": 200}
Set LOG_LEVEL env var to control filtering (default: INFO).
Health
Registers /healthz (liveness) and /readyz (readiness) endpoints on your FastAPI app.
from stacklink import health
health.register(app, config=config)
async def check_database():
try:
await db.execute("SELECT 1")
return True
except Exception:
return False
health.add_check("database", check_database)
/healthz always returns 200. /readyz returns 200 when all checks pass, 503 when any check fails.
Documentation
Requirements
- Python 3.10+
- FastAPI 0.100+
Development
pip install -e ".[dev]"
pytest
License
MIT
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 stacklink-0.1.0.tar.gz.
File metadata
- Download URL: stacklink-0.1.0.tar.gz
- Upload date:
- Size: 207.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90080c2e600e5e06fd059795143a404c72c19b611c640f44971052cc67f8f39e
|
|
| MD5 |
78c186bb5ea3d3576ca27691d9e19601
|
|
| BLAKE2b-256 |
a07ab9e6ddb723f81d863c242dbb6b5dc701f86f11084c5b6b0133c8a7206364
|
File details
Details for the file stacklink-0.1.0-py3-none-any.whl.
File metadata
- Download URL: stacklink-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe0682d6258d6c4e39e1246ba1c9e280ad0b5d7520408f02acc01ffdcb4e0187
|
|
| MD5 |
fc40a08fd472b4aacc183d6d26cfe29e
|
|
| BLAKE2b-256 |
9d62d0745546fe03dee1b3098c0f96d7218f39c69517bbb860f6ad4d6f5f429e
|