Skip to main content

Utilities for the Litestar framework.

Project description

litestar-utils

Utilities for the Litestar framework

Source Code: https://github.com/Alurith/litestar-utils


Features:

This package include some utilities I generaly use in my projects:

  • Timing Middleware: Basic timing for each request

Installation:

 $ pip install litestar-utils

or

 $ poetry add litestar-utils

Usage:

Timing Middleware:

Use the create_timing_middleware function to create the middleware, the only required argument is emit.

emit must be a callable that accept 2 arguments a Request and a float

from litestar import Litestar, get
from litestar_utils import create_timing_middleware


@get("/")
async def hello_world() -> str:
    return "Hello, world!"


@get("/base", exclude_timing=True)
async def base_all() -> str:
    return "All your base are belong to us"

app = Litestar(
    [hello_world, base_all],
    middleware=[create_timing_middleware(emit=print)],
)

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

litestar_utils-0.1.1.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

litestar_utils-0.1.1-py3-none-any.whl (3.8 kB view hashes)

Uploaded Python 3

Supported by

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