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

File metadata

  • Download URL: swarmauri_middleware_stdio-0.8.0.dev46.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.dev46.tar.gz
Algorithm Hash digest
SHA256 f7ed16a89a67980313a5a82e30a1e5cd081b3608e80ba2de0d39e1f2f4ac9c5f
MD5 5f3a5811ff322a62253dd0ce2f3ff98c
BLAKE2b-256 b119c76ad8613fa5c97cc55d33accdc40d9570b65e95b12a4ade4ac2687b2e4b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_middleware_stdio-0.8.0.dev46-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.dev46-py3-none-any.whl
Algorithm Hash digest
SHA256 8693c2a4c4ddc8f8a71037e3214bee42f99e92852ab35efc76c6e0842dd81b67
MD5 0fa6e4449023d736b562270c2cedfd14
BLAKE2b-256 ad82ef3fbe8ecb62ce835cad82d829ba633698ce3a31895e501e3d6f04a6e5da

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