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.dev48.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.dev48.tar.gz.

File metadata

  • Download URL: swarmauri_middleware_stdio-0.8.0.dev48.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

Hashes for swarmauri_middleware_stdio-0.8.0.dev48.tar.gz
Algorithm Hash digest
SHA256 89f5beb6ffd4f0bf99614e587fece0f6eff1f48477471b9f52e9a4367a20cb9e
MD5 36a4475b7acd74ccb3cfe13c02112b23
BLAKE2b-256 324120a5762e401eddbe1d2767dab6a928dcc2dd528a286b2f1179d87916ff16

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_middleware_stdio-0.8.0.dev48-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

Hashes for swarmauri_middleware_stdio-0.8.0.dev48-py3-none-any.whl
Algorithm Hash digest
SHA256 e4029b4db4ed98ca0ed339cee07c1afc114dd9f68b2cdaf778f1f4ed3d7a2b79
MD5 55bd908904a33736f1571c5248aafe22
BLAKE2b-256 01f82dbe2948d643c8118cc2df8f1e8456a8c6f146cfd6156e55528893ca31e3

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