Beautiful FastAPI request/response logging middleware with Rich panels
Project description
FastAPI Rich Logging
Beautiful FastAPI request/response logging middleware with Rich panels and colors.
โจ Features
- ๐จ Beautiful Rich panels - Colorful, formatted request/response logs
- โก High performance - Minimal overhead on your FastAPI application
- ๐ง Highly configurable - Control what gets logged and how
- ๐ก๏ธ Security focused - Automatically masks sensitive headers
- ๐ Request timing - Track response times for performance monitoring
- ๐ฏ Easy integration - One line to add to your FastAPI app
๐ฆ Installation
pip install fastapi-rich-panels
๐ Quick Start
from fastapi import FastAPI
from fastapi_rich_panels import RichLoggingMiddleware
app = FastAPI()
# Add the Rich logging middleware
app.add_middleware(RichLoggingMiddleware)
@app.get("/")
async def hello():
return {"message": "Hello World!"}
That's it! Your FastAPI app now has beautiful request/response logging.
๐จ What it looks like
When you make requests to your API, you'll see beautiful panels in your terminal:
โโ ๐ Incoming Request โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Method GET โ
โ URL http://localhost:8000/users/123?active=true โ
โ Path /users/123 โ
โ Client 127.0.0.1:54321 โ
โ Query active=true โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโ โ
Request Completed โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Status 200 โ
โ Method GET โ
โ Path /users/123 โ
โ Duration 0.0234s โ
โ Content-Type application/json โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ๏ธ Configuration
from fastapi import FastAPI
from fastapi_rich_panels import RichLoggingMiddleware
app = FastAPI()
app.add_middleware(
RichLoggingMiddleware,
show_headers=True, # Show request headers
show_query_params=True, # Show query parameters
logger=my_logger, # Use custom logger
)
๐ Advanced Usage
Simple Logging
For minimal, clean logs:
from fastapi_rich_panels import SimpleRichLoggingMiddleware
app.add_middleware(SimpleRichLoggingMiddleware)
Custom Console
Use your own Rich console:
from rich.console import Console
from fastapi_rich_panels import RichLoggingMiddleware
console = Console(width=120, style="bold blue")
app.add_middleware(
RichLoggingMiddleware,
console=console
)
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
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_rich_panels-0.1.2.tar.gz.
File metadata
- Download URL: fastapi_rich_panels-0.1.2.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1df23abb4d889e12292374ccc65bdbea5b074b1422855f4be9567c87ec1d2f43
|
|
| MD5 |
145e8fa7a0047db6b08fc19728c4e0c6
|
|
| BLAKE2b-256 |
f7ac226be6d551af9802418c2794f38f59b3000c7df4849fa6fd04969b8c16eb
|
File details
Details for the file fastapi_rich_panels-0.1.2-py3-none-any.whl.
File metadata
- Download URL: fastapi_rich_panels-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
339f3c92a1c04ee338d05899853cfaf64b0825cf015b9aeb5715fb1ab8734031
|
|
| MD5 |
af0106f57b7f0e0f1d8d4da07b6c38bb
|
|
| BLAKE2b-256 |
142586d368e005f05f47313632ea4ae96fc8e00063bf6a6d2265a6384b96bd54
|