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_logging 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_logging 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_logging import SimpleRichLoggingMiddleware

app.add_middleware(SimpleRichLoggingMiddleware)

Custom Console

Use your own Rich console:

from rich.console import Console
from fastapi_rich_logging 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.0.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.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_rich_panels-0.1.0.tar.gz.

File metadata

  • Download URL: fastapi_rich_panels-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 76cd96a1b068711070f6f9ba976bfea9047b90f968b63188b1ee360707048f2d
MD5 199d10dc0746b5279e1b38f3416879e9
BLAKE2b-256 9f3e63c2764267c6991661f5de0afecede6f76bfc296efc3faf32328e8c80e30

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_rich_panels-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0049038295e87ce43bc0c7c38af03cd068d114d7a9451139aa10d23a4be5fbd2
MD5 31b75bc0f82eb87a2242361d3f443e7c
BLAKE2b-256 b31a55a4724075509ddc574b64754a6fdebea5fdfb602fa21379df949208b0ee

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