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.2.1.tar.gz (5.5 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.2.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_rich_panels-0.2.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fastapi_rich_panels-0.2.1.tar.gz
Algorithm Hash digest
SHA256 dcdc7df92dc498d60594426bf0ee90a17d6f7aca63108e37c38f5c7d443c172e
MD5 e28f4c00001b64f5e3bfb533bbb1d373
BLAKE2b-256 f110cb65c9a8c8c0606819effda7dc4bb9baf599dbf78ef9d36fa2d244831ae6

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_rich_panels-0.2.1.tar.gz:

Publisher: publish.yml on Danish903/fastapi-rich-panels

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for fastapi_rich_panels-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2f14ad58a730f715e0cd29805217a77f5410f84600aef9f3ad4b91625b295b75
MD5 0e49ba5264aadaeef5591326fdd268a5
BLAKE2b-256 8bdf26ec0fec9a8f22b4cb4a06e49c4e3a3c62d7fc09f5949d9d87432f2481c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_rich_panels-0.2.1-py3-none-any.whl:

Publisher: publish.yml on Danish903/fastapi-rich-panels

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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