Middleware that logs requests and responses to standard output
Project description
Swarmauri Middleware Stdio
swarmauri_middleware_stdio provides a lightweight FastAPI middleware that
logs incoming requests and outgoing responses to standard output using
Python's logging module. It is handy for development and debugging when a
full logging stack is unnecessary.
Installation
Pick the tool that matches your workflow:
# pip
pip install swarmauri_middleware_stdio
# Poetry
poetry add swarmauri_middleware_stdio
# uv
pip install uv # install uv if it's not already available
uv add swarmauri_middleware_stdio
Usage
import logging
import sys
from fastapi import FastAPI, Request
from swarmauri_middleware_stdio import StdioMiddleware
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
app = FastAPI()
stdio = StdioMiddleware()
@app.middleware("http")
async def log_to_stdout(request: Request, call_next):
return await stdio.dispatch(request, call_next)
@app.get("/")
async def hello() -> dict[str, str]:
return {"message": "hello"}
How It Works
StdioMiddleware uses Python's logging facilities under the logger name
swarmauri_middleware_stdio.StdioMiddleware. Each request produces an INFO
record before the downstream handler runs, and the matching response status is
logged afterwards. Configure logging (as in the example above) to route those
messages to stdout or another destination appropriate for your deployment.
When the middleware is active you should see output similar to:
INFO swarmauri_middleware_stdio.StdioMiddleware STDIO Request: GET /
INFO swarmauri_middleware_stdio.StdioMiddleware STDIO Response: 200
Want to help?
If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swarmauri_middleware_stdio-0.8.0.dev45.tar.gz.
File metadata
- Download URL: swarmauri_middleware_stdio-0.8.0.dev45.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba49c3335667e9057ad47b69fe353449cd247e2462e2eecfa1e4613ef8b51d96
|
|
| MD5 |
12ca85a191890c55c4bafc40e43d8af2
|
|
| BLAKE2b-256 |
76ab8566cfccfe021315c7386b130e4cb981ecda580a4e8ed966845eaa8f9340
|
File details
Details for the file swarmauri_middleware_stdio-0.8.0.dev45-py3-none-any.whl.
File metadata
- Download URL: swarmauri_middleware_stdio-0.8.0.dev45-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
323eaa526e112024cccf720db1c5952014848d53f0b76e653d9c9828ea62e7d0
|
|
| MD5 |
9c9150d9d88c16ff6c9c7b2c043f4304
|
|
| BLAKE2b-256 |
be59f948108f5da086b3bc1e1800d813d54c96d9ad1588d8f839995b27577aa3
|