Metadata-Version: 2.1
Name: litestar-utils
Version: 0.1.1
Summary: Utilities for the Litestar framework.
Author: Alessandro Ferrini
Author-email: alessandro.ferrini@apptecsrl.com
Requires-Python: >=3.8,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Dist: litestar
Description-Content-Type: text/markdown

# litestar-utils

Utilities for the [Litestar framework](https://github.com/litestar-org/litestar) 

**Source Code**: [https://github.com/Alurith/litestar-utils](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: 
```sh
 $ pip install litestar-utils
```
or
```sh
 $ 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](https://docs.litestar.dev/2/reference/connection.html#litestar.connection.Request) and a `float`


```python
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)],
)
```

