swarmauri_middleware_stdio 0.8.0.dev5__py3-none-any.whl → 0.8.0.dev33__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- swarmauri_middleware_stdio/StdioMiddleware.py +16 -2
- swarmauri_middleware_stdio/__init__.py +2 -0
- swarmauri_middleware_stdio-0.8.0.dev33.dist-info/METADATA +116 -0
- swarmauri_middleware_stdio-0.8.0.dev33.dist-info/RECORD +7 -0
- {swarmauri_middleware_stdio-0.8.0.dev5.dist-info → swarmauri_middleware_stdio-0.8.0.dev33.dist-info}/WHEEL +1 -1
- swarmauri_middleware_stdio-0.8.0.dev5.dist-info/METADATA +0 -61
- swarmauri_middleware_stdio-0.8.0.dev5.dist-info/RECORD +0 -7
- {swarmauri_middleware_stdio-0.8.0.dev5.dist-info → swarmauri_middleware_stdio-0.8.0.dev33.dist-info}/entry_points.txt +0 -0
- {swarmauri_middleware_stdio-0.8.0.dev5.dist-info → swarmauri_middleware_stdio-0.8.0.dev33.dist-info/licenses}/LICENSE +0 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"""Utilities for logging HTTP request and response details to stdout."""
|
|
2
|
+
|
|
1
3
|
import logging
|
|
2
4
|
from typing import Any, Callable
|
|
3
5
|
|
|
@@ -10,12 +12,24 @@ logger = logging.getLogger(__name__)
|
|
|
10
12
|
|
|
11
13
|
@ComponentBase.register_type(MiddlewareBase, "StdioMiddleware")
|
|
12
14
|
class StdioMiddleware(MiddlewareBase):
|
|
13
|
-
"""
|
|
15
|
+
"""Log request and response details to stdout.
|
|
16
|
+
|
|
17
|
+
The middleware writes basic information about each request and the
|
|
18
|
+
corresponding response status to standard output. It is primarily
|
|
19
|
+
intended for development and debugging.
|
|
20
|
+
"""
|
|
14
21
|
|
|
15
22
|
async def dispatch(
|
|
16
23
|
self, request: Request, call_next: Callable[[Request], Any]
|
|
17
24
|
) -> Any:
|
|
18
|
-
"""Log the request,
|
|
25
|
+
"""Log the request, call the next handler, then log the response.
|
|
26
|
+
|
|
27
|
+
request (Request): Incoming HTTP request.
|
|
28
|
+
call_next (Callable[[Request], Any]): Callable that invokes the next
|
|
29
|
+
middleware or endpoint.
|
|
30
|
+
RETURNS (Any): Response produced by the downstream middleware or
|
|
31
|
+
endpoint.
|
|
32
|
+
"""
|
|
19
33
|
logger.info("STDIO Request: %s %s", request.method, request.url.path)
|
|
20
34
|
response = await call_next(request)
|
|
21
35
|
status = getattr(response, "status_code", "unknown")
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swarmauri_middleware_stdio
|
|
3
|
+
Version: 0.8.0.dev33
|
|
4
|
+
Summary: Middleware that logs requests and responses to standard output
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: swarmauri,sdk,standards,middleware,stdio
|
|
8
|
+
Author: Jacob Stewart
|
|
9
|
+
Author-email: jacob@swarmauri.com
|
|
10
|
+
Requires-Python: >=3.10,<3.13
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Development Status :: 3 - Alpha
|
|
18
|
+
Classifier: Programming Language :: Python
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
|
+
Requires-Dist: fastapi
|
|
22
|
+
Requires-Dist: swarmauri_base
|
|
23
|
+
Requires-Dist: swarmauri_core
|
|
24
|
+
Requires-Dist: swarmauri_standard
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+

|
|
28
|
+
|
|
29
|
+
<p align="center">
|
|
30
|
+
<a href="https://pypi.org/project/swarmauri_middleware_stdio/">
|
|
31
|
+
<img src="https://img.shields.io/pypi/dm/swarmauri_middleware_stdio" alt="PyPI - Downloads"/>
|
|
32
|
+
</a>
|
|
33
|
+
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_stdio/">
|
|
34
|
+
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_stdio.svg"/>
|
|
35
|
+
</a>
|
|
36
|
+
<a href="https://pypi.org/project/swarmauri_middleware_stdio/">
|
|
37
|
+
<img src="https://img.shields.io/pypi/pyversions/swarmauri_middleware_stdio" alt="PyPI - Python Version"/>
|
|
38
|
+
</a>
|
|
39
|
+
<a href="https://pypi.org/project/swarmauri_middleware_stdio/">
|
|
40
|
+
<img src="https://img.shields.io/pypi/l/swarmauri_middleware_stdio" alt="PyPI - License"/>
|
|
41
|
+
</a>
|
|
42
|
+
<a href="https://pypi.org/project/swarmauri_middleware_stdio/">
|
|
43
|
+
<img src="https://img.shields.io/pypi/v/swarmauri_middleware_stdio?label=swarmauri_middleware_stdio&color=green" alt="PyPI - swarmauri_middleware_stdio"/>
|
|
44
|
+
</a>
|
|
45
|
+
</p>
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
# Swarmauri Middleware Stdio
|
|
50
|
+
|
|
51
|
+
`swarmauri_middleware_stdio` provides a lightweight FastAPI middleware that
|
|
52
|
+
logs incoming requests and outgoing responses to standard output using
|
|
53
|
+
Python's logging module. It is handy for development and debugging when a
|
|
54
|
+
full logging stack is unnecessary.
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
Pick the tool that matches your workflow:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# pip
|
|
62
|
+
pip install swarmauri_middleware_stdio
|
|
63
|
+
|
|
64
|
+
# Poetry
|
|
65
|
+
poetry add swarmauri_middleware_stdio
|
|
66
|
+
|
|
67
|
+
# uv
|
|
68
|
+
pip install uv # install uv if it's not already available
|
|
69
|
+
uv add swarmauri_middleware_stdio
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Usage
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
import logging
|
|
76
|
+
import sys
|
|
77
|
+
|
|
78
|
+
from fastapi import FastAPI, Request
|
|
79
|
+
from swarmauri_middleware_stdio import StdioMiddleware
|
|
80
|
+
|
|
81
|
+
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
|
|
82
|
+
|
|
83
|
+
app = FastAPI()
|
|
84
|
+
stdio = StdioMiddleware()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@app.middleware("http")
|
|
88
|
+
async def log_to_stdout(request: Request, call_next):
|
|
89
|
+
return await stdio.dispatch(request, call_next)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@app.get("/")
|
|
93
|
+
async def hello() -> dict[str, str]:
|
|
94
|
+
return {"message": "hello"}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## How It Works
|
|
98
|
+
|
|
99
|
+
`StdioMiddleware` uses Python's logging facilities under the logger name
|
|
100
|
+
`swarmauri_middleware_stdio.StdioMiddleware`. Each request produces an `INFO`
|
|
101
|
+
record before the downstream handler runs, and the matching response status is
|
|
102
|
+
logged afterwards. Configure logging (as in the example above) to route those
|
|
103
|
+
messages to stdout or another destination appropriate for your deployment.
|
|
104
|
+
|
|
105
|
+
When the middleware is active you should see output similar to:
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
INFO swarmauri_middleware_stdio.StdioMiddleware STDIO Request: GET /
|
|
109
|
+
INFO swarmauri_middleware_stdio.StdioMiddleware STDIO Response: 200
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Want to help?
|
|
113
|
+
|
|
114
|
+
If you want to contribute to swarmauri-sdk, read up on our
|
|
115
|
+
[guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
|
|
116
|
+
that will help you get started.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
swarmauri_middleware_stdio/StdioMiddleware.py,sha256=SpSKSf7sNj8VtsE8nJZqUyjFKWYMXWiPXkEmaG--lGQ,1372
|
|
2
|
+
swarmauri_middleware_stdio/__init__.py,sha256=TaTxFCg09iBqg3owQ7XRBATZjT1Nkt7q5hW1A30lRgc,465
|
|
3
|
+
swarmauri_middleware_stdio-0.8.0.dev33.dist-info/METADATA,sha256=EOEz7e7c4-f3TAZBf-L57IEq8RXA_vQ9_So-9IlOVbI,4063
|
|
4
|
+
swarmauri_middleware_stdio-0.8.0.dev33.dist-info/WHEEL,sha256=kJCRJT_g0adfAJzTx2GUMmS80rTJIVHRCfG0DQgLq3o,88
|
|
5
|
+
swarmauri_middleware_stdio-0.8.0.dev33.dist-info/entry_points.txt,sha256=J0DUs0NdOmnR8YD2ZonEpzd5-pGxgbm2hD4X-SQgRkE,84
|
|
6
|
+
swarmauri_middleware_stdio-0.8.0.dev33.dist-info/licenses/LICENSE,sha256=0HKc44dKbrMG14HqJiqvfYxx_yL728OafjnFnSgsAW8,11347
|
|
7
|
+
swarmauri_middleware_stdio-0.8.0.dev33.dist-info/RECORD,,
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: swarmauri_middleware_stdio
|
|
3
|
-
Version: 0.8.0.dev5
|
|
4
|
-
Summary: Middleware that logs requests and responses to standard output
|
|
5
|
-
License: Apache-2.0
|
|
6
|
-
Author: Jacob Stewart
|
|
7
|
-
Author-email: jacob@swarmauri.com
|
|
8
|
-
Requires-Python: >=3.10,<3.13
|
|
9
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
-
Classifier: Natural Language :: English
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
-
Classifier: Development Status :: 3 - Alpha
|
|
16
|
-
Requires-Dist: fastapi
|
|
17
|
-
Requires-Dist: swarmauri_base
|
|
18
|
-
Requires-Dist: swarmauri_core
|
|
19
|
-
Requires-Dist: swarmauri_standard
|
|
20
|
-
Description-Content-Type: text/markdown
|
|
21
|
-
|
|
22
|
-

|
|
23
|
-
|
|
24
|
-
<p align="center">
|
|
25
|
-
<a href="https://pypi.org/project/swarmauri_middleware_stdio/">
|
|
26
|
-
<img src="https://img.shields.io/pypi/dm/swarmauri_middleware_stdio" alt="PyPI - Downloads"/>
|
|
27
|
-
</a>
|
|
28
|
-
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_stdio/">
|
|
29
|
-
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_stdio.svg"/>
|
|
30
|
-
</a>
|
|
31
|
-
<a href="https://pypi.org/project/swarmauri_middleware_stdio/">
|
|
32
|
-
<img src="https://img.shields.io/pypi/pyversions/swarmauri_middleware_stdio" alt="PyPI - Python Version"/>
|
|
33
|
-
</a>
|
|
34
|
-
<a href="https://pypi.org/project/swarmauri_middleware_stdio/">
|
|
35
|
-
<img src="https://img.shields.io/pypi/l/swarmauri_middleware_stdio" alt="PyPI - License"/>
|
|
36
|
-
</a>
|
|
37
|
-
<a href="https://pypi.org/project/swarmauri_middleware_stdio/">
|
|
38
|
-
<img src="https://img.shields.io/pypi/v/swarmauri_middleware_stdio?label=swarmauri_middleware_stdio&color=green" alt="PyPI - swarmauri_middleware_stdio"/>
|
|
39
|
-
</a>
|
|
40
|
-
</p>
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
# Swarmauri Middleware Stdio
|
|
45
|
-
|
|
46
|
-
Middleware that logs requests and responses to standard output.
|
|
47
|
-
|
|
48
|
-
## Usage
|
|
49
|
-
|
|
50
|
-
```python
|
|
51
|
-
from fastapi import FastAPI
|
|
52
|
-
from swarmauri_middleware_stdio import StdioMiddleware
|
|
53
|
-
|
|
54
|
-
app = FastAPI()
|
|
55
|
-
app.middleware("http")(StdioMiddleware().dispatch)
|
|
56
|
-
|
|
57
|
-
@app.get("/")
|
|
58
|
-
async def hello() -> dict[str, str]:
|
|
59
|
-
return {"message": "hello"}
|
|
60
|
-
```
|
|
61
|
-
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
swarmauri_middleware_stdio/StdioMiddleware.py,sha256=nTG6fg-zA47lBJI8P91AkQneigPF2uF5F94HymBdIMQ,869
|
|
2
|
-
swarmauri_middleware_stdio/__init__.py,sha256=5mCVUQvM9NN2ZXQ7djZhZQ1Tul19UVI3a7VWm-8CSo0,389
|
|
3
|
-
swarmauri_middleware_stdio-0.8.0.dev5.dist-info/LICENSE,sha256=0HKc44dKbrMG14HqJiqvfYxx_yL728OafjnFnSgsAW8,11347
|
|
4
|
-
swarmauri_middleware_stdio-0.8.0.dev5.dist-info/METADATA,sha256=C88UEjRJhnfK4ZYoTOBxD1mvZEoGGwRUsi8fn7hTLBk,2328
|
|
5
|
-
swarmauri_middleware_stdio-0.8.0.dev5.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
6
|
-
swarmauri_middleware_stdio-0.8.0.dev5.dist-info/entry_points.txt,sha256=J0DUs0NdOmnR8YD2ZonEpzd5-pGxgbm2hD4X-SQgRkE,84
|
|
7
|
-
swarmauri_middleware_stdio-0.8.0.dev5.dist-info/RECORD,,
|
|
File without changes
|