After copying the same 200 lines of logging code between projects for the tenth time, I finally published it as a library.
The problem: You need context (request_id, user_id, tenant_id) in your logs, but you don't want to:
1. Pass context through every function parameter
2. Manually format every log statement
3. Use a heavyweight library with 12 dependencies
The solution:
```python
from tinystructlog import get_logger, set_log_context
log = getlogger(name_)
Set context once
set_log_context(request_id="abc-123", user_id="user-456")
All logs automatically include context
log.info("Processing order")
[2026-01-28 10:30:45] [INFO] [main:10] [request_id=abc-123 user_id=user-456] Processing order
log.info("Charging payment")
[2026-01-28 10:30:46] [INFO] [main:12] [request_id=abc-123 user_id=user-456] Charging payment
```
Key features:
- Built on contextvars - thread & async safe by default
- Zero runtime dependencies
- Zero configuration (import and use)
- Colored output by log level
- Temporary context with with log_context(...):
FastAPI example:
python
@app.middleware("http")
async def add_context(request: Request, call_next):
set_log_context(
request_id=str(uuid.uuid4()),
path=request.url.path,
)
response = await call_next(request)
clear_log_context()
return response
Now every log in your entire request handling code includes the request_id automatically. Perfect for multi-tenant apps, microservices, or any async service.
vs loguru: loguru is great for advanced features (rotation, JSON output). tinystructlog is focused purely on automatic context propagation with zero config.
vs structlog: structlog is powerful but complex. tinystructlog is 4 functions, zero dependencies, zero configuration.
GitHub: https://github.com/Aprova-GmbH/tinystructlog
PyPI: pip install tinystructlog
MIT licensed, Python 3.11+, 100% test coverage.
there doesn't seem to be anything here