Skip to main content

Middleware that logs requests and responses to standard output

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_middleware_stdio


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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swarmauri_middleware_stdio-0.8.0.dev34.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file swarmauri_middleware_stdio-0.8.0.dev34.tar.gz.

File metadata

  • Download URL: swarmauri_middleware_stdio-0.8.0.dev34.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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

Hashes for swarmauri_middleware_stdio-0.8.0.dev34.tar.gz
Algorithm Hash digest
SHA256 042a9854fcb160b20099cb7047c7f6460cbe500ea5a6cefe1e56e91e327cc980
MD5 3b7e22bb72ce8270ee1ca3aa38ce4f1b
BLAKE2b-256 f591d97fcc2f128ba0b65475fe410e394fe7711066460a94871ce3c7e806b4b7

See more details on using hashes here.

File details

Details for the file swarmauri_middleware_stdio-0.8.0.dev34-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_middleware_stdio-0.8.0.dev34-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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

Hashes for swarmauri_middleware_stdio-0.8.0.dev34-py3-none-any.whl
Algorithm Hash digest
SHA256 fa43a0cd725a85f14eea2cb78d7f308f132a23a8da93a1aa315e16f2f7071d7a
MD5 ceb83cd6512dc46b444f0b38505110d2
BLAKE2b-256 4151306606e804a0f9ac11d51f9e67f4a04c4d21355cb6a7b2b1f280da3e88e7

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