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

File metadata

  • Download URL: swarmauri_middleware_stdio-0.8.0.dev38.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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.dev38.tar.gz
Algorithm Hash digest
SHA256 bda6ba84248efdd873cab5f0e162415832711358ac2a6bce09b287553171aaaa
MD5 b8d197ea340db4d6929a8fd4e45392ae
BLAKE2b-256 727ba41269074568b1113f134a534d0085423a11660587b33cba663b3f8e4871

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_middleware_stdio-0.8.0.dev38-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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.dev38-py3-none-any.whl
Algorithm Hash digest
SHA256 c49cda8b8ca59b0a05b003a087b937459378b97c3843d87c0a8512aa900d5131
MD5 48191ec8bebec23073278d37c3553ec9
BLAKE2b-256 fb7aa0b0cd0e7fd699281f5c2b810c1450ce9d4c90037f87fdb615a290404d6b

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