Skip to main content

Beautiful FastAPI request/response logging middleware with Rich panels

Project description

FastAPI Rich Logging

PyPI version GitHub release Python versions

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

  • Built with Rich for beautiful terminal output
  • Designed for FastAPI applications
  • Inspired by the need for better development logging experience

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_rich_panels-0.1.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_rich_panels-0.1.2-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

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

Hashes for fastapi_rich_panels-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1df23abb4d889e12292374ccc65bdbea5b074b1422855f4be9567c87ec1d2f43
MD5 145e8fa7a0047db6b08fc19728c4e0c6
BLAKE2b-256 f7ac226be6d551af9802418c2794f38f59b3000c7df4849fa6fd04969b8c16eb

See more details on using hashes here.

File details

Details for the file fastapi_rich_panels-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_rich_panels-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 339f3c92a1c04ee338d05899853cfaf64b0825cf015b9aeb5715fb1ab8734031
MD5 af0106f57b7f0e0f1d8d4da07b6c38bb
BLAKE2b-256 142586d368e005f05f47313632ea4ae96fc8e00063bf6a6d2265a6384b96bd54

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page