swarmauri_middleware_time 0.8.0.dev46__tar.gz → 0.11.0__tar.gz
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_time-0.11.0/NOTICE +7 -0
- swarmauri_middleware_time-0.11.0/PKG-INFO +409 -0
- swarmauri_middleware_time-0.11.0/README.md +381 -0
- {swarmauri_middleware_time-0.8.0.dev46 → swarmauri_middleware_time-0.11.0}/pyproject.toml +59 -9
- {swarmauri_middleware_time-0.8.0.dev46 → swarmauri_middleware_time-0.11.0}/swarmauri_middleware_time/TimerMiddleware.py +17 -5
- swarmauri_middleware_time-0.8.0.dev46/PKG-INFO +0 -127
- swarmauri_middleware_time-0.8.0.dev46/README.md +0 -100
- {swarmauri_middleware_time-0.8.0.dev46 → swarmauri_middleware_time-0.11.0}/LICENSE +0 -0
- {swarmauri_middleware_time-0.8.0.dev46 → swarmauri_middleware_time-0.11.0}/swarmauri_middleware_time/__init__.py +0 -0
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swarmauri_middleware_time
|
|
3
|
+
Version: 0.11.0
|
|
4
|
+
Summary: Middleware for tracking request processing time in Swarmauri applications
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
License-File: NOTICE
|
|
8
|
+
Keywords: swarmauri,sdk,standards,middleware,time
|
|
9
|
+
Author: Jacob Stewart
|
|
10
|
+
Author-email: jacob@swarmauri.com
|
|
11
|
+
Requires-Python: >=3.10,<3.15
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Requires-Dist: starlette
|
|
23
|
+
Requires-Dist: swarmauri_base
|
|
24
|
+
Requires-Dist: swarmauri_core
|
|
25
|
+
Requires-Dist: swarmauri_standard
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# swarmauri_middleware_time
|
|
29
|
+
|
|
30
|
+
<!-- readme-standards:begin branding -->
|
|
31
|
+
<p align="center"><a href="https://github.com/swarmauri/swarmauri-sdk"><img src="https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri.brand.theme.svg" alt="Swarmauri SDK" width="300"></a></p>
|
|
32
|
+
<p align="center"><strong>swarmauri_middleware_time</strong></p>
|
|
33
|
+
<p align="center">Middleware for tracking request processing time in Swarmauri applications</p>
|
|
34
|
+
<p align="center">
|
|
35
|
+
<a href="https://pypi.org/project/swarmauri_middleware_time/"><img alt="pypi: swarmauri_middleware_time" src="https://img.shields.io/pypi/v/swarmauri_middleware_time?labelColor=1E293B&color=1D4ED8"></a>
|
|
36
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml"><img alt="Source version: 0.11.0" src="https://img.shields.io/static/v1?label=Source%20version&message=0.11.0&labelColor=1E293B&color=4338CA"></a>
|
|
37
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml"><img alt="Python: >=3.10,<3.15" src="https://img.shields.io/static/v1?label=Python&message=%3E%3D3.10%2C%3C3.15&labelColor=1E293B&color=0F766E"></a>
|
|
38
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml"><img alt="Layer: standards" src="https://img.shields.io/static/v1?label=Layer&message=standards&labelColor=1E293B&color=6D28D9"></a>
|
|
39
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/README.md#lifecycle-and-migration"><img alt="Lifecycle: active" src="https://img.shields.io/static/v1?label=Lifecycle&message=active&labelColor=1E293B&color=166534"></a>
|
|
40
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/static/v1?label=License&message=Apache-2.0&labelColor=1E293B&color=86198F"></a>
|
|
41
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/NOTICE"><img alt="Notice: attribution" src="https://img.shields.io/static/v1?label=Notice&message=attribution&labelColor=1E293B&color=86198F"></a>
|
|
42
|
+
</p>
|
|
43
|
+
<p align="center">
|
|
44
|
+
<a href="https://pypi.org/project/swarmauri_middleware_time/"><img alt="Monthly PyPI downloads: swarmauri_middleware_time" src="https://img.shields.io/pypi/dm/swarmauri_middleware_time?labelColor=1E293B&color=0E7490"></a>
|
|
45
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/README.md"><img alt="README hits: swarmauri_middleware_time" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/pkgs/40-standards/swarmauri_middleware_time/README.md.svg?label=README%20hits&labelColor=1E293B&color=0E7490"></a>
|
|
46
|
+
</p>
|
|
47
|
+
<p align="center">
|
|
48
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="README standards: CI gate" src="https://img.shields.io/static/v1?label=README%20standards&message=CI%20gate&labelColor=1E293B&color=1D4ED8"></a>
|
|
49
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/tests/unit/test_readme_sources.py"><img alt="Tests: example source" src="https://img.shields.io/static/v1?label=Tests&message=example%20source&labelColor=1E293B&color=0F766E"></a>
|
|
50
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/README.md#certification-status"><img alt="Certification: not certified" src="https://img.shields.io/static/v1?label=Certification&message=not%20certified&labelColor=1E293B&color=92400E"></a>
|
|
51
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md"><img alt="Governance: repository policy" src="https://img.shields.io/static/v1?label=Governance&message=repository%20policy&labelColor=1E293B&color=4338CA"></a>
|
|
52
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="Evidence: source and CI" src="https://img.shields.io/static/v1?label=Evidence&message=source%20and%20CI&labelColor=1E293B&color=6D28D9"></a>
|
|
53
|
+
</p>
|
|
54
|
+
<p align="center"><a href="#overview">Overview</a> · <a href="#installation">Installation</a> · <a href="#quick-start">Quick Start</a> · <a href="#usage">Usage</a> · <a href="#public-api-and-import-surfaces">API</a> · <a href="#contributing">Contributing</a> · <a href="#governance">Governance</a> · <a href="#license">License</a></p>
|
|
55
|
+
<!-- readme-standards:end branding -->
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Overview
|
|
60
|
+
|
|
61
|
+
### Summary
|
|
62
|
+
|
|
63
|
+
Middleware for tracking request processing time in Swarmauri applications.
|
|
64
|
+
|
|
65
|
+
### Why This Package
|
|
66
|
+
|
|
67
|
+
`swarmauri_middleware_time` isolates this responsibility: Middleware for tracking request processing time in Swarmauri applications. Its [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/swarmauri_middleware_time/__init__.py) exposes `TimerMiddleware`, allowing consumers to select this package without treating adjacent packages as part of its public contract.
|
|
68
|
+
|
|
69
|
+
### When to Use
|
|
70
|
+
|
|
71
|
+
Choose `swarmauri_middleware_time` when your integration needs middleware for tracking request processing time in Swarmauri applications. Match the imports below to your application boundary and install its declared dependencies before using the example.
|
|
72
|
+
|
|
73
|
+
### Features
|
|
74
|
+
|
|
75
|
+
- Logs when each request starts and when it completes using Python's `logging` module.
|
|
76
|
+
- Measures the total time spent handling a request and attaches `X-Request-Duration`
|
|
77
|
+
and `X-Request-Start-Time` headers to the response.
|
|
78
|
+
- Raises an `HTTPException` with status code `500` if an unexpected error occurs
|
|
79
|
+
while the downstream handler is executing.
|
|
80
|
+
|
|
81
|
+
### Non-Goals
|
|
82
|
+
|
|
83
|
+
`swarmauri_middleware_time` owns middleware for tracking request processing time in Swarmauri applications. Its imports do not by themselves configure credentials, deploy a service, or certify the behavior of its consumers. Dependencies and neighboring packages retain their own documented responsibilities.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Getting Started
|
|
88
|
+
|
|
89
|
+
### Prerequisites
|
|
90
|
+
|
|
91
|
+
Python `>=3.10,<3.15` is required. The [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml) declares runtime dependencies including `starlette`, `swarmauri-core`, `swarmauri-base`, `swarmauri-standard`. Read the example’s inputs and service requirements before execution.
|
|
92
|
+
|
|
93
|
+
### Installation
|
|
94
|
+
|
|
95
|
+
#### uv
|
|
96
|
+
|
|
97
|
+
<!-- readme-standards:begin installation.uv -->
|
|
98
|
+
```bash
|
|
99
|
+
uv add swarmauri_middleware_time
|
|
100
|
+
```
|
|
101
|
+
<!-- readme-standards:end installation.uv -->
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
# Install uv if it is not already available
|
|
105
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
106
|
+
|
|
107
|
+
# Add the middleware to your project
|
|
108
|
+
uv add swarmauri_middleware_time
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### pip
|
|
112
|
+
|
|
113
|
+
<!-- readme-standards:begin installation.pip -->
|
|
114
|
+
```bash
|
|
115
|
+
python -m pip install swarmauri_middleware_time
|
|
116
|
+
```
|
|
117
|
+
<!-- readme-standards:end installation.pip -->
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
pip install swarmauri_middleware_time
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
#### Poetry
|
|
124
|
+
|
|
125
|
+
<!-- readme-standards:begin installation.poetry -->
|
|
126
|
+
```bash
|
|
127
|
+
poetry add swarmauri_middleware_time
|
|
128
|
+
```
|
|
129
|
+
<!-- readme-standards:end installation.poetry -->
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
poetry add swarmauri_middleware_time
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Quick Start
|
|
136
|
+
|
|
137
|
+
#### Example
|
|
138
|
+
|
|
139
|
+
<!-- readme-standards:begin example.quick-start -->
|
|
140
|
+
Source: [docs/readme/quick_start.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/docs/readme/quick_start.py).
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from starlette.applications import Starlette
|
|
144
|
+
from starlette.middleware.base import BaseHTTPMiddleware
|
|
145
|
+
from starlette.requests import Request
|
|
146
|
+
from starlette.responses import JSONResponse
|
|
147
|
+
from starlette.testclient import TestClient
|
|
148
|
+
|
|
149
|
+
from swarmauri_middleware_time import TimerMiddleware
|
|
150
|
+
|
|
151
|
+
app = Starlette()
|
|
152
|
+
timer_middleware = TimerMiddleware()
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
async def add_timer(request: Request, call_next):
|
|
156
|
+
return await timer_middleware.dispatch(request, call_next)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
app.add_middleware(BaseHTTPMiddleware, dispatch=add_timer)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
async def ping(_request):
|
|
163
|
+
return JSONResponse({"message": "pong"})
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
app.add_route("/ping", ping)
|
|
167
|
+
|
|
168
|
+
if __name__ == "__main__":
|
|
169
|
+
client = TestClient(app)
|
|
170
|
+
response = client.get("/ping")
|
|
171
|
+
|
|
172
|
+
assert response.json() == {"message": "pong"}
|
|
173
|
+
assert "X-Request-Duration" in response.headers
|
|
174
|
+
assert float(response.headers["X-Request-Duration"]) >= 0.0
|
|
175
|
+
assert "X-Request-Start-Time" in response.headers
|
|
176
|
+
|
|
177
|
+
print("Duration header:", response.headers["X-Request-Duration"])
|
|
178
|
+
print("Start time header:", response.headers["X-Request-Start-Time"])
|
|
179
|
+
```
|
|
180
|
+
<!-- readme-standards:end example.quick-start -->
|
|
181
|
+
|
|
182
|
+
#### Expected Result
|
|
183
|
+
|
|
184
|
+
The example demonstrates the documented `swarmauri_middleware_time` source boundary or workflow. Complete its required configuration first. README CI checks the maintained source’s syntax and declarations; it does not claim that external services or the application workflow were exercised.
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## Usage
|
|
189
|
+
|
|
190
|
+
### Common Workflows
|
|
191
|
+
|
|
192
|
+
<!-- readme-standards:begin example.usage -->
|
|
193
|
+
Source: [docs/readme/usage.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/docs/readme/usage.py).
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
from starlette.applications import Starlette
|
|
197
|
+
from starlette.middleware.base import BaseHTTPMiddleware
|
|
198
|
+
from starlette.requests import Request
|
|
199
|
+
from starlette.responses import JSONResponse
|
|
200
|
+
from starlette.testclient import TestClient
|
|
201
|
+
|
|
202
|
+
from swarmauri_middleware_time import TimerMiddleware
|
|
203
|
+
|
|
204
|
+
app = Starlette()
|
|
205
|
+
timer_middleware = TimerMiddleware()
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
async def add_timer(request: Request, call_next):
|
|
209
|
+
return await timer_middleware.dispatch(request, call_next)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
app.add_middleware(BaseHTTPMiddleware, dispatch=add_timer)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
async def ping(_request):
|
|
216
|
+
return JSONResponse({"message": "pong"})
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
app.add_route("/ping", ping)
|
|
220
|
+
|
|
221
|
+
if __name__ == "__main__":
|
|
222
|
+
client = TestClient(app)
|
|
223
|
+
response = client.get("/ping")
|
|
224
|
+
|
|
225
|
+
assert response.json() == {"message": "pong"}
|
|
226
|
+
assert "X-Request-Duration" in response.headers
|
|
227
|
+
assert float(response.headers["X-Request-Duration"]) >= 0.0
|
|
228
|
+
assert "X-Request-Start-Time" in response.headers
|
|
229
|
+
|
|
230
|
+
print("Duration header:", response.headers["X-Request-Duration"])
|
|
231
|
+
print("Start time header:", response.headers["X-Request-Start-Time"])
|
|
232
|
+
```
|
|
233
|
+
<!-- readme-standards:end example.usage -->
|
|
234
|
+
|
|
235
|
+
Instantiate the middleware once and register its `dispatch` method with
|
|
236
|
+
Starlette’s `BaseHTTPMiddleware`.
|
|
237
|
+
|
|
238
|
+
### Configuration
|
|
239
|
+
|
|
240
|
+
Configure `swarmauri_middleware_time` through the APIs in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/swarmauri_middleware_time/__init__.py); its [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml) describes installation requirements, not an implicit service configuration. No additional package-global configuration contract is inferred from dependencies.
|
|
241
|
+
|
|
242
|
+
### Error Handling
|
|
243
|
+
|
|
244
|
+
The inspected `swarmauri_middleware_time` source raises `HTTPException`. Handle these at the calling boundary and consult the implementation for the triggering conditions.
|
|
245
|
+
|
|
246
|
+
### Best Practices
|
|
247
|
+
|
|
248
|
+
Use the explicit `swarmauri_middleware_time` imports documented below and keep collaborator configuration with the caller. Run the package’s relevant tests after changing `TimerMiddleware`; an import or successful installation alone does not establish its runtime guarantees.
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Package Boundary
|
|
253
|
+
|
|
254
|
+
### What It Owns
|
|
255
|
+
|
|
256
|
+
`swarmauri_middleware_time` is located in `standards` and owns middleware for tracking request processing time in Swarmauri applications. Source-declared APIs include `TimerMiddleware`. The [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml) records its direct dependency boundary.
|
|
257
|
+
|
|
258
|
+
### Public API and Import Surfaces
|
|
259
|
+
|
|
260
|
+
Import namespace: `swarmauri_middleware_time`.
|
|
261
|
+
|
|
262
|
+
Source-declared exports or types: `TimerMiddleware`.
|
|
263
|
+
|
|
264
|
+
Inspect [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/swarmauri_middleware_time/__init__.py) for exact signatures; this inventory does not designate every internal module as stable.
|
|
265
|
+
|
|
266
|
+
### Entry Points
|
|
267
|
+
|
|
268
|
+
<!-- readme-standards:begin entry-points -->
|
|
269
|
+
- `swarmauri.middlewares` → `TimerMiddleware` → `swarmauri_middleware_time:TimerMiddleware`
|
|
270
|
+
<!-- readme-standards:end entry-points -->
|
|
271
|
+
|
|
272
|
+
### Injected Dependencies
|
|
273
|
+
|
|
274
|
+
The direct installation dependencies of `swarmauri_middleware_time` are `starlette`, `swarmauri-core`, `swarmauri-base`, `swarmauri-standard`. These declarations do not imply automatic provider selection. Pass collaborators through the explicit constructors or call signatures in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/swarmauri_middleware_time/__init__.py).
|
|
275
|
+
|
|
276
|
+
### Protocol Consumers
|
|
277
|
+
|
|
278
|
+
No direct package-manifest dependency on `swarmauri_middleware_time` was found in the audited three-repository inventory. External consumers may still use its documented imports or commands.
|
|
279
|
+
|
|
280
|
+
### Extensions
|
|
281
|
+
|
|
282
|
+
For `swarmauri_middleware_time`, use the source-declared public interfaces (`TimerMiddleware`) when composing or extending behavior. Its entry-point section below is authoritative for registered plugins; no additional extension loader is inferred from the package name.
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Operations and Readiness
|
|
287
|
+
|
|
288
|
+
### Operational Requirements
|
|
289
|
+
|
|
290
|
+
Operate `swarmauri_middleware_time` according to its actual entry points and collaborators. The dependency and Python requirements in the [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml) are prerequisites; deployment topology, credentials, and readiness remain the responsibility of the consuming application unless explicitly documented above.
|
|
291
|
+
|
|
292
|
+
### Health and Observability
|
|
293
|
+
|
|
294
|
+
This README does not establish a standalone health endpoint for `swarmauri_middleware_time`. Observe the concrete caller’s results, exceptions, and existing test reports. An application that embeds this package must define its own health and telemetry contract.
|
|
295
|
+
|
|
296
|
+
### Security and Resource Limits
|
|
297
|
+
|
|
298
|
+
Apply the input, credential, and resource constraints implemented in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/swarmauri_middleware_time/__init__.py). The `swarmauri_middleware_time` README gate is a documentation check, not a security review or a substitute for the implementation’s limits and caller authorization.
|
|
299
|
+
|
|
300
|
+
### Compatibility
|
|
301
|
+
|
|
302
|
+
This source version of `swarmauri_middleware_time` declares Python `>=3.10,<3.15`. Consult its dependency constraints before upgrading. Source-version and registry-version badges have separate meanings; this migration makes no additional platform or interoperability certification claim.
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## Verification
|
|
307
|
+
|
|
308
|
+
### Tests
|
|
309
|
+
|
|
310
|
+
Run `python -m pytest tests/unit/test_readme_sources.py` from the `swarmauri_middleware_time` package directory for the maintained example source checks (Python compilation and non-Python file presence). Existing package tests include:
|
|
311
|
+
|
|
312
|
+
- [tests/test_readme_example.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/tests/test_readme_example.py)
|
|
313
|
+
- [tests/i9n/test_i9n__init__.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/tests/i9n/test_i9n__init__.py)
|
|
314
|
+
- [tests/unit/test_TimerMiddleware.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/tests/unit/test_TimerMiddleware.py)
|
|
315
|
+
|
|
316
|
+
The repository README gate also checks the required heading tree, metadata, managed fragments, and referenced files.
|
|
317
|
+
|
|
318
|
+
### Certification Status
|
|
319
|
+
|
|
320
|
+
No external certification is asserted for `swarmauri_middleware_time` by this documentation migration. README conformance, example syntax, runtime tests, and protocol or security certification are distinct evidence scopes.
|
|
321
|
+
|
|
322
|
+
### Evidence
|
|
323
|
+
|
|
324
|
+
The [README standards CI](https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml) records mechanical documentation results for its tested commit. The [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/swarmauri_middleware_time/__init__.py) and example sources support the package-boundary description; external runtime behavior requires its own test evidence.
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
## FAQ
|
|
329
|
+
|
|
330
|
+
### Why
|
|
331
|
+
|
|
332
|
+
**Why select this package?** `swarmauri_middleware_time` provides middleware for tracking request processing time in Swarmauri applications; use its own API boundary rather than assuming neighboring packages are bundled or configured automatically.
|
|
333
|
+
|
|
334
|
+
### How
|
|
335
|
+
|
|
336
|
+
**How do I start?** Install or synchronize the environment under Getting Started, follow the maintained example for `swarmauri_middleware_time`, and consult [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/swarmauri_middleware_time/__init__.py) for the exact types and signatures involved.
|
|
337
|
+
|
|
338
|
+
### When
|
|
339
|
+
|
|
340
|
+
**When should I validate an upgrade?** Recheck `swarmauri_middleware_time` whenever its source version, declared collaborators, configuration, or caller changes. Run relevant behavioral tests in addition to the README gate before promotion.
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
## Documentation and Related Packages
|
|
345
|
+
|
|
346
|
+
### More Documentation
|
|
347
|
+
|
|
348
|
+
The [repository contribution guide](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md), [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/swarmauri_middleware_time/__init__.py), and [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml) provide the supporting context for `swarmauri_middleware_time`. The [README policy](https://github.com/groupsum/readme-standards/blob/master/docs/outline.md) defines the common document structure.
|
|
349
|
+
|
|
350
|
+
### Related Packages
|
|
351
|
+
|
|
352
|
+
- [swarmauri_base](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/20-bases/swarmauri_base/README.md): Reusable Swarmauri base classes, mixins, and dynamic Pydantic component models for composable intelligence infrastructure.
|
|
353
|
+
- [swarmauri_core](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/10-interfaces/swarmauri_core/README.md): Core interface contracts and shared types for Swarmauri composable intelligence infrastructure components.
|
|
354
|
+
- [swarmauri_standard](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/30-standard-kernel/swarmauri_standard/README.md): First-party Swarmauri standard components for agents, tools, parsers, vectors, model adapters, and composable intelligence workflows.
|
|
355
|
+
|
|
356
|
+
### Project Links
|
|
357
|
+
|
|
358
|
+
<!-- readme-standards:begin project-links -->
|
|
359
|
+
- [pypi: swarmauri_middleware_time](https://pypi.org/project/swarmauri_middleware_time/)
|
|
360
|
+
<!-- readme-standards:end project-links -->
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
## Contributing
|
|
365
|
+
|
|
366
|
+
### How to Contribute
|
|
367
|
+
|
|
368
|
+
If you want to contribute to swarmauri-sdk, read up on our [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/contributing.md) that will help you get started.
|
|
369
|
+
|
|
370
|
+
### Development Setup
|
|
371
|
+
|
|
372
|
+
Work from the `pkgs/40-standards/swarmauri_middleware_time` checkout. Synchronize its declared development environment with uv, then run the relevant package tests and `python -m pytest tests/unit/test_readme_sources.py`. The repository’s dedicated README job installs `readme-standards==0.1.3` without resolving unrelated runtime packages.
|
|
373
|
+
|
|
374
|
+
### Notes for Maintainers
|
|
375
|
+
|
|
376
|
+
Edit authored prose directly in this `swarmauri_middleware_time` README. Update source examples in `docs/readme/`, then run `readme-standards render --root . --write` from the package directory and review the diff. Required headings and generated blocks come from package-guide-v1.
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
## Governance
|
|
381
|
+
|
|
382
|
+
### Ownership and Decision Making
|
|
383
|
+
|
|
384
|
+
Changes to `swarmauri_middleware_time` follow the maintainer review process of [swarmauri/swarmauri-sdk](https://github.com/swarmauri/swarmauri-sdk) and its contribution guide. Author attribution remains in the [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml); this README does not assign new publishing or administrative authority.
|
|
385
|
+
|
|
386
|
+
### Standards and Policies
|
|
387
|
+
|
|
388
|
+
`swarmauri_middleware_time` follows the versioned [package-guide-v1 outline](https://github.com/groupsum/readme-standards/blob/master/docs/outline.md). All fixed headings, hierarchy, order, separators, and package-specific branding are checked by CI; reviewers assess the accuracy and usefulness of authored claims.
|
|
389
|
+
|
|
390
|
+
### Lifecycle and Migration
|
|
391
|
+
|
|
392
|
+
The `swarmauri_middleware_time` source version is `0.11.0`.
|
|
393
|
+
|
|
394
|
+
---
|
|
395
|
+
|
|
396
|
+
## License and Attribution
|
|
397
|
+
|
|
398
|
+
### License
|
|
399
|
+
|
|
400
|
+
<!-- readme-standards:begin license -->
|
|
401
|
+
Licensed under `Apache-2.0`. See [LICENSE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/LICENSE).
|
|
402
|
+
<!-- readme-standards:end license -->
|
|
403
|
+
|
|
404
|
+
### Notices
|
|
405
|
+
|
|
406
|
+
<!-- readme-standards:begin notices -->
|
|
407
|
+
See [NOTICE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/NOTICE) for attribution.
|
|
408
|
+
<!-- readme-standards:end notices -->
|
|
409
|
+
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
# swarmauri_middleware_time
|
|
2
|
+
|
|
3
|
+
<!-- readme-standards:begin branding -->
|
|
4
|
+
<p align="center"><a href="https://github.com/swarmauri/swarmauri-sdk"><img src="https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri.brand.theme.svg" alt="Swarmauri SDK" width="300"></a></p>
|
|
5
|
+
<p align="center"><strong>swarmauri_middleware_time</strong></p>
|
|
6
|
+
<p align="center">Middleware for tracking request processing time in Swarmauri applications</p>
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://pypi.org/project/swarmauri_middleware_time/"><img alt="pypi: swarmauri_middleware_time" src="https://img.shields.io/pypi/v/swarmauri_middleware_time?labelColor=1E293B&color=1D4ED8"></a>
|
|
9
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml"><img alt="Source version: 0.11.0" src="https://img.shields.io/static/v1?label=Source%20version&message=0.11.0&labelColor=1E293B&color=4338CA"></a>
|
|
10
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml"><img alt="Python: >=3.10,<3.15" src="https://img.shields.io/static/v1?label=Python&message=%3E%3D3.10%2C%3C3.15&labelColor=1E293B&color=0F766E"></a>
|
|
11
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml"><img alt="Layer: standards" src="https://img.shields.io/static/v1?label=Layer&message=standards&labelColor=1E293B&color=6D28D9"></a>
|
|
12
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/README.md#lifecycle-and-migration"><img alt="Lifecycle: active" src="https://img.shields.io/static/v1?label=Lifecycle&message=active&labelColor=1E293B&color=166534"></a>
|
|
13
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/static/v1?label=License&message=Apache-2.0&labelColor=1E293B&color=86198F"></a>
|
|
14
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/NOTICE"><img alt="Notice: attribution" src="https://img.shields.io/static/v1?label=Notice&message=attribution&labelColor=1E293B&color=86198F"></a>
|
|
15
|
+
</p>
|
|
16
|
+
<p align="center">
|
|
17
|
+
<a href="https://pypi.org/project/swarmauri_middleware_time/"><img alt="Monthly PyPI downloads: swarmauri_middleware_time" src="https://img.shields.io/pypi/dm/swarmauri_middleware_time?labelColor=1E293B&color=0E7490"></a>
|
|
18
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/README.md"><img alt="README hits: swarmauri_middleware_time" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/pkgs/40-standards/swarmauri_middleware_time/README.md.svg?label=README%20hits&labelColor=1E293B&color=0E7490"></a>
|
|
19
|
+
</p>
|
|
20
|
+
<p align="center">
|
|
21
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="README standards: CI gate" src="https://img.shields.io/static/v1?label=README%20standards&message=CI%20gate&labelColor=1E293B&color=1D4ED8"></a>
|
|
22
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/tests/unit/test_readme_sources.py"><img alt="Tests: example source" src="https://img.shields.io/static/v1?label=Tests&message=example%20source&labelColor=1E293B&color=0F766E"></a>
|
|
23
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/README.md#certification-status"><img alt="Certification: not certified" src="https://img.shields.io/static/v1?label=Certification&message=not%20certified&labelColor=1E293B&color=92400E"></a>
|
|
24
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md"><img alt="Governance: repository policy" src="https://img.shields.io/static/v1?label=Governance&message=repository%20policy&labelColor=1E293B&color=4338CA"></a>
|
|
25
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="Evidence: source and CI" src="https://img.shields.io/static/v1?label=Evidence&message=source%20and%20CI&labelColor=1E293B&color=6D28D9"></a>
|
|
26
|
+
</p>
|
|
27
|
+
<p align="center"><a href="#overview">Overview</a> · <a href="#installation">Installation</a> · <a href="#quick-start">Quick Start</a> · <a href="#usage">Usage</a> · <a href="#public-api-and-import-surfaces">API</a> · <a href="#contributing">Contributing</a> · <a href="#governance">Governance</a> · <a href="#license">License</a></p>
|
|
28
|
+
<!-- readme-standards:end branding -->
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Overview
|
|
33
|
+
|
|
34
|
+
### Summary
|
|
35
|
+
|
|
36
|
+
Middleware for tracking request processing time in Swarmauri applications.
|
|
37
|
+
|
|
38
|
+
### Why This Package
|
|
39
|
+
|
|
40
|
+
`swarmauri_middleware_time` isolates this responsibility: Middleware for tracking request processing time in Swarmauri applications. Its [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/swarmauri_middleware_time/__init__.py) exposes `TimerMiddleware`, allowing consumers to select this package without treating adjacent packages as part of its public contract.
|
|
41
|
+
|
|
42
|
+
### When to Use
|
|
43
|
+
|
|
44
|
+
Choose `swarmauri_middleware_time` when your integration needs middleware for tracking request processing time in Swarmauri applications. Match the imports below to your application boundary and install its declared dependencies before using the example.
|
|
45
|
+
|
|
46
|
+
### Features
|
|
47
|
+
|
|
48
|
+
- Logs when each request starts and when it completes using Python's `logging` module.
|
|
49
|
+
- Measures the total time spent handling a request and attaches `X-Request-Duration`
|
|
50
|
+
and `X-Request-Start-Time` headers to the response.
|
|
51
|
+
- Raises an `HTTPException` with status code `500` if an unexpected error occurs
|
|
52
|
+
while the downstream handler is executing.
|
|
53
|
+
|
|
54
|
+
### Non-Goals
|
|
55
|
+
|
|
56
|
+
`swarmauri_middleware_time` owns middleware for tracking request processing time in Swarmauri applications. Its imports do not by themselves configure credentials, deploy a service, or certify the behavior of its consumers. Dependencies and neighboring packages retain their own documented responsibilities.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Getting Started
|
|
61
|
+
|
|
62
|
+
### Prerequisites
|
|
63
|
+
|
|
64
|
+
Python `>=3.10,<3.15` is required. The [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml) declares runtime dependencies including `starlette`, `swarmauri-core`, `swarmauri-base`, `swarmauri-standard`. Read the example’s inputs and service requirements before execution.
|
|
65
|
+
|
|
66
|
+
### Installation
|
|
67
|
+
|
|
68
|
+
#### uv
|
|
69
|
+
|
|
70
|
+
<!-- readme-standards:begin installation.uv -->
|
|
71
|
+
```bash
|
|
72
|
+
uv add swarmauri_middleware_time
|
|
73
|
+
```
|
|
74
|
+
<!-- readme-standards:end installation.uv -->
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Install uv if it is not already available
|
|
78
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
79
|
+
|
|
80
|
+
# Add the middleware to your project
|
|
81
|
+
uv add swarmauri_middleware_time
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### pip
|
|
85
|
+
|
|
86
|
+
<!-- readme-standards:begin installation.pip -->
|
|
87
|
+
```bash
|
|
88
|
+
python -m pip install swarmauri_middleware_time
|
|
89
|
+
```
|
|
90
|
+
<!-- readme-standards:end installation.pip -->
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install swarmauri_middleware_time
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### Poetry
|
|
97
|
+
|
|
98
|
+
<!-- readme-standards:begin installation.poetry -->
|
|
99
|
+
```bash
|
|
100
|
+
poetry add swarmauri_middleware_time
|
|
101
|
+
```
|
|
102
|
+
<!-- readme-standards:end installation.poetry -->
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
poetry add swarmauri_middleware_time
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Quick Start
|
|
109
|
+
|
|
110
|
+
#### Example
|
|
111
|
+
|
|
112
|
+
<!-- readme-standards:begin example.quick-start -->
|
|
113
|
+
Source: [docs/readme/quick_start.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/docs/readme/quick_start.py).
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from starlette.applications import Starlette
|
|
117
|
+
from starlette.middleware.base import BaseHTTPMiddleware
|
|
118
|
+
from starlette.requests import Request
|
|
119
|
+
from starlette.responses import JSONResponse
|
|
120
|
+
from starlette.testclient import TestClient
|
|
121
|
+
|
|
122
|
+
from swarmauri_middleware_time import TimerMiddleware
|
|
123
|
+
|
|
124
|
+
app = Starlette()
|
|
125
|
+
timer_middleware = TimerMiddleware()
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
async def add_timer(request: Request, call_next):
|
|
129
|
+
return await timer_middleware.dispatch(request, call_next)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
app.add_middleware(BaseHTTPMiddleware, dispatch=add_timer)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
async def ping(_request):
|
|
136
|
+
return JSONResponse({"message": "pong"})
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
app.add_route("/ping", ping)
|
|
140
|
+
|
|
141
|
+
if __name__ == "__main__":
|
|
142
|
+
client = TestClient(app)
|
|
143
|
+
response = client.get("/ping")
|
|
144
|
+
|
|
145
|
+
assert response.json() == {"message": "pong"}
|
|
146
|
+
assert "X-Request-Duration" in response.headers
|
|
147
|
+
assert float(response.headers["X-Request-Duration"]) >= 0.0
|
|
148
|
+
assert "X-Request-Start-Time" in response.headers
|
|
149
|
+
|
|
150
|
+
print("Duration header:", response.headers["X-Request-Duration"])
|
|
151
|
+
print("Start time header:", response.headers["X-Request-Start-Time"])
|
|
152
|
+
```
|
|
153
|
+
<!-- readme-standards:end example.quick-start -->
|
|
154
|
+
|
|
155
|
+
#### Expected Result
|
|
156
|
+
|
|
157
|
+
The example demonstrates the documented `swarmauri_middleware_time` source boundary or workflow. Complete its required configuration first. README CI checks the maintained source’s syntax and declarations; it does not claim that external services or the application workflow were exercised.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Usage
|
|
162
|
+
|
|
163
|
+
### Common Workflows
|
|
164
|
+
|
|
165
|
+
<!-- readme-standards:begin example.usage -->
|
|
166
|
+
Source: [docs/readme/usage.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/docs/readme/usage.py).
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
from starlette.applications import Starlette
|
|
170
|
+
from starlette.middleware.base import BaseHTTPMiddleware
|
|
171
|
+
from starlette.requests import Request
|
|
172
|
+
from starlette.responses import JSONResponse
|
|
173
|
+
from starlette.testclient import TestClient
|
|
174
|
+
|
|
175
|
+
from swarmauri_middleware_time import TimerMiddleware
|
|
176
|
+
|
|
177
|
+
app = Starlette()
|
|
178
|
+
timer_middleware = TimerMiddleware()
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
async def add_timer(request: Request, call_next):
|
|
182
|
+
return await timer_middleware.dispatch(request, call_next)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
app.add_middleware(BaseHTTPMiddleware, dispatch=add_timer)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
async def ping(_request):
|
|
189
|
+
return JSONResponse({"message": "pong"})
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
app.add_route("/ping", ping)
|
|
193
|
+
|
|
194
|
+
if __name__ == "__main__":
|
|
195
|
+
client = TestClient(app)
|
|
196
|
+
response = client.get("/ping")
|
|
197
|
+
|
|
198
|
+
assert response.json() == {"message": "pong"}
|
|
199
|
+
assert "X-Request-Duration" in response.headers
|
|
200
|
+
assert float(response.headers["X-Request-Duration"]) >= 0.0
|
|
201
|
+
assert "X-Request-Start-Time" in response.headers
|
|
202
|
+
|
|
203
|
+
print("Duration header:", response.headers["X-Request-Duration"])
|
|
204
|
+
print("Start time header:", response.headers["X-Request-Start-Time"])
|
|
205
|
+
```
|
|
206
|
+
<!-- readme-standards:end example.usage -->
|
|
207
|
+
|
|
208
|
+
Instantiate the middleware once and register its `dispatch` method with
|
|
209
|
+
Starlette’s `BaseHTTPMiddleware`.
|
|
210
|
+
|
|
211
|
+
### Configuration
|
|
212
|
+
|
|
213
|
+
Configure `swarmauri_middleware_time` through the APIs in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/swarmauri_middleware_time/__init__.py); its [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml) describes installation requirements, not an implicit service configuration. No additional package-global configuration contract is inferred from dependencies.
|
|
214
|
+
|
|
215
|
+
### Error Handling
|
|
216
|
+
|
|
217
|
+
The inspected `swarmauri_middleware_time` source raises `HTTPException`. Handle these at the calling boundary and consult the implementation for the triggering conditions.
|
|
218
|
+
|
|
219
|
+
### Best Practices
|
|
220
|
+
|
|
221
|
+
Use the explicit `swarmauri_middleware_time` imports documented below and keep collaborator configuration with the caller. Run the package’s relevant tests after changing `TimerMiddleware`; an import or successful installation alone does not establish its runtime guarantees.
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## Package Boundary
|
|
226
|
+
|
|
227
|
+
### What It Owns
|
|
228
|
+
|
|
229
|
+
`swarmauri_middleware_time` is located in `standards` and owns middleware for tracking request processing time in Swarmauri applications. Source-declared APIs include `TimerMiddleware`. The [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml) records its direct dependency boundary.
|
|
230
|
+
|
|
231
|
+
### Public API and Import Surfaces
|
|
232
|
+
|
|
233
|
+
Import namespace: `swarmauri_middleware_time`.
|
|
234
|
+
|
|
235
|
+
Source-declared exports or types: `TimerMiddleware`.
|
|
236
|
+
|
|
237
|
+
Inspect [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/swarmauri_middleware_time/__init__.py) for exact signatures; this inventory does not designate every internal module as stable.
|
|
238
|
+
|
|
239
|
+
### Entry Points
|
|
240
|
+
|
|
241
|
+
<!-- readme-standards:begin entry-points -->
|
|
242
|
+
- `swarmauri.middlewares` → `TimerMiddleware` → `swarmauri_middleware_time:TimerMiddleware`
|
|
243
|
+
<!-- readme-standards:end entry-points -->
|
|
244
|
+
|
|
245
|
+
### Injected Dependencies
|
|
246
|
+
|
|
247
|
+
The direct installation dependencies of `swarmauri_middleware_time` are `starlette`, `swarmauri-core`, `swarmauri-base`, `swarmauri-standard`. These declarations do not imply automatic provider selection. Pass collaborators through the explicit constructors or call signatures in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/swarmauri_middleware_time/__init__.py).
|
|
248
|
+
|
|
249
|
+
### Protocol Consumers
|
|
250
|
+
|
|
251
|
+
No direct package-manifest dependency on `swarmauri_middleware_time` was found in the audited three-repository inventory. External consumers may still use its documented imports or commands.
|
|
252
|
+
|
|
253
|
+
### Extensions
|
|
254
|
+
|
|
255
|
+
For `swarmauri_middleware_time`, use the source-declared public interfaces (`TimerMiddleware`) when composing or extending behavior. Its entry-point section below is authoritative for registered plugins; no additional extension loader is inferred from the package name.
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Operations and Readiness
|
|
260
|
+
|
|
261
|
+
### Operational Requirements
|
|
262
|
+
|
|
263
|
+
Operate `swarmauri_middleware_time` according to its actual entry points and collaborators. The dependency and Python requirements in the [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml) are prerequisites; deployment topology, credentials, and readiness remain the responsibility of the consuming application unless explicitly documented above.
|
|
264
|
+
|
|
265
|
+
### Health and Observability
|
|
266
|
+
|
|
267
|
+
This README does not establish a standalone health endpoint for `swarmauri_middleware_time`. Observe the concrete caller’s results, exceptions, and existing test reports. An application that embeds this package must define its own health and telemetry contract.
|
|
268
|
+
|
|
269
|
+
### Security and Resource Limits
|
|
270
|
+
|
|
271
|
+
Apply the input, credential, and resource constraints implemented in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/swarmauri_middleware_time/__init__.py). The `swarmauri_middleware_time` README gate is a documentation check, not a security review or a substitute for the implementation’s limits and caller authorization.
|
|
272
|
+
|
|
273
|
+
### Compatibility
|
|
274
|
+
|
|
275
|
+
This source version of `swarmauri_middleware_time` declares Python `>=3.10,<3.15`. Consult its dependency constraints before upgrading. Source-version and registry-version badges have separate meanings; this migration makes no additional platform or interoperability certification claim.
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## Verification
|
|
280
|
+
|
|
281
|
+
### Tests
|
|
282
|
+
|
|
283
|
+
Run `python -m pytest tests/unit/test_readme_sources.py` from the `swarmauri_middleware_time` package directory for the maintained example source checks (Python compilation and non-Python file presence). Existing package tests include:
|
|
284
|
+
|
|
285
|
+
- [tests/test_readme_example.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/tests/test_readme_example.py)
|
|
286
|
+
- [tests/i9n/test_i9n__init__.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/tests/i9n/test_i9n__init__.py)
|
|
287
|
+
- [tests/unit/test_TimerMiddleware.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/tests/unit/test_TimerMiddleware.py)
|
|
288
|
+
|
|
289
|
+
The repository README gate also checks the required heading tree, metadata, managed fragments, and referenced files.
|
|
290
|
+
|
|
291
|
+
### Certification Status
|
|
292
|
+
|
|
293
|
+
No external certification is asserted for `swarmauri_middleware_time` by this documentation migration. README conformance, example syntax, runtime tests, and protocol or security certification are distinct evidence scopes.
|
|
294
|
+
|
|
295
|
+
### Evidence
|
|
296
|
+
|
|
297
|
+
The [README standards CI](https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml) records mechanical documentation results for its tested commit. The [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/swarmauri_middleware_time/__init__.py) and example sources support the package-boundary description; external runtime behavior requires its own test evidence.
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## FAQ
|
|
302
|
+
|
|
303
|
+
### Why
|
|
304
|
+
|
|
305
|
+
**Why select this package?** `swarmauri_middleware_time` provides middleware for tracking request processing time in Swarmauri applications; use its own API boundary rather than assuming neighboring packages are bundled or configured automatically.
|
|
306
|
+
|
|
307
|
+
### How
|
|
308
|
+
|
|
309
|
+
**How do I start?** Install or synchronize the environment under Getting Started, follow the maintained example for `swarmauri_middleware_time`, and consult [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/swarmauri_middleware_time/__init__.py) for the exact types and signatures involved.
|
|
310
|
+
|
|
311
|
+
### When
|
|
312
|
+
|
|
313
|
+
**When should I validate an upgrade?** Recheck `swarmauri_middleware_time` whenever its source version, declared collaborators, configuration, or caller changes. Run relevant behavioral tests in addition to the README gate before promotion.
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## Documentation and Related Packages
|
|
318
|
+
|
|
319
|
+
### More Documentation
|
|
320
|
+
|
|
321
|
+
The [repository contribution guide](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md), [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/swarmauri_middleware_time/__init__.py), and [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml) provide the supporting context for `swarmauri_middleware_time`. The [README policy](https://github.com/groupsum/readme-standards/blob/master/docs/outline.md) defines the common document structure.
|
|
322
|
+
|
|
323
|
+
### Related Packages
|
|
324
|
+
|
|
325
|
+
- [swarmauri_base](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/20-bases/swarmauri_base/README.md): Reusable Swarmauri base classes, mixins, and dynamic Pydantic component models for composable intelligence infrastructure.
|
|
326
|
+
- [swarmauri_core](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/10-interfaces/swarmauri_core/README.md): Core interface contracts and shared types for Swarmauri composable intelligence infrastructure components.
|
|
327
|
+
- [swarmauri_standard](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/30-standard-kernel/swarmauri_standard/README.md): First-party Swarmauri standard components for agents, tools, parsers, vectors, model adapters, and composable intelligence workflows.
|
|
328
|
+
|
|
329
|
+
### Project Links
|
|
330
|
+
|
|
331
|
+
<!-- readme-standards:begin project-links -->
|
|
332
|
+
- [pypi: swarmauri_middleware_time](https://pypi.org/project/swarmauri_middleware_time/)
|
|
333
|
+
<!-- readme-standards:end project-links -->
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## Contributing
|
|
338
|
+
|
|
339
|
+
### How to Contribute
|
|
340
|
+
|
|
341
|
+
If you want to contribute to swarmauri-sdk, read up on our [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/contributing.md) that will help you get started.
|
|
342
|
+
|
|
343
|
+
### Development Setup
|
|
344
|
+
|
|
345
|
+
Work from the `pkgs/40-standards/swarmauri_middleware_time` checkout. Synchronize its declared development environment with uv, then run the relevant package tests and `python -m pytest tests/unit/test_readme_sources.py`. The repository’s dedicated README job installs `readme-standards==0.1.3` without resolving unrelated runtime packages.
|
|
346
|
+
|
|
347
|
+
### Notes for Maintainers
|
|
348
|
+
|
|
349
|
+
Edit authored prose directly in this `swarmauri_middleware_time` README. Update source examples in `docs/readme/`, then run `readme-standards render --root . --write` from the package directory and review the diff. Required headings and generated blocks come from package-guide-v1.
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## Governance
|
|
354
|
+
|
|
355
|
+
### Ownership and Decision Making
|
|
356
|
+
|
|
357
|
+
Changes to `swarmauri_middleware_time` follow the maintainer review process of [swarmauri/swarmauri-sdk](https://github.com/swarmauri/swarmauri-sdk) and its contribution guide. Author attribution remains in the [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/pyproject.toml); this README does not assign new publishing or administrative authority.
|
|
358
|
+
|
|
359
|
+
### Standards and Policies
|
|
360
|
+
|
|
361
|
+
`swarmauri_middleware_time` follows the versioned [package-guide-v1 outline](https://github.com/groupsum/readme-standards/blob/master/docs/outline.md). All fixed headings, hierarchy, order, separators, and package-specific branding are checked by CI; reviewers assess the accuracy and usefulness of authored claims.
|
|
362
|
+
|
|
363
|
+
### Lifecycle and Migration
|
|
364
|
+
|
|
365
|
+
The `swarmauri_middleware_time` source version is `0.11.0`.
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
## License and Attribution
|
|
370
|
+
|
|
371
|
+
### License
|
|
372
|
+
|
|
373
|
+
<!-- readme-standards:begin license -->
|
|
374
|
+
Licensed under `Apache-2.0`. See [LICENSE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/LICENSE).
|
|
375
|
+
<!-- readme-standards:end license -->
|
|
376
|
+
|
|
377
|
+
### Notices
|
|
378
|
+
|
|
379
|
+
<!-- readme-standards:begin notices -->
|
|
380
|
+
See [NOTICE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/NOTICE) for attribution.
|
|
381
|
+
<!-- readme-standards:end notices -->
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "swarmauri_middleware_time"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.11.0"
|
|
4
4
|
description = "Middleware for tracking request processing time in Swarmauri applications"
|
|
5
5
|
license = "Apache-2.0"
|
|
6
6
|
readme = "README.md"
|
|
7
7
|
repository = "http://github.com/swarmauri/swarmauri-sdk/pkgs/pkgs/swarmauri_middleware_time/"
|
|
8
|
-
requires-python = ">=3.10,<3.
|
|
8
|
+
requires-python = ">=3.10,<3.15"
|
|
9
9
|
classifiers = [
|
|
10
|
-
"License :: OSI Approved :: Apache Software License",
|
|
11
10
|
"Natural Language :: English",
|
|
12
|
-
"Programming Language :: Python :: 3.10",
|
|
13
|
-
"Programming Language :: Python :: 3.11",
|
|
14
|
-
"Programming Language :: Python :: 3.12",
|
|
15
|
-
"Programming Language :: Python :: 3.13",
|
|
16
11
|
"Development Status :: 3 - Alpha",
|
|
17
12
|
"Programming Language :: Python",
|
|
18
13
|
"Programming Language :: Python :: 3",
|
|
19
14
|
"Programming Language :: Python :: 3 :: Only",
|
|
15
|
+
"Programming Language :: Python :: 3.10",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Programming Language :: Python :: 3.14",
|
|
20
20
|
]
|
|
21
21
|
authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
|
|
22
22
|
dependencies = [
|
|
23
|
-
"
|
|
23
|
+
"starlette",
|
|
24
24
|
"swarmauri_core",
|
|
25
25
|
"swarmauri_base",
|
|
26
26
|
"swarmauri_standard",
|
|
@@ -32,6 +32,7 @@ keywords = [
|
|
|
32
32
|
'middleware',
|
|
33
33
|
'time',
|
|
34
34
|
]
|
|
35
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
35
36
|
|
|
36
37
|
[tool.uv.sources]
|
|
37
38
|
swarmauri_core = { workspace = true }
|
|
@@ -60,6 +61,54 @@ log_cli_date_format = "%Y-%m-%d %H:%M:%S"
|
|
|
60
61
|
asyncio_mode = "auto"
|
|
61
62
|
asyncio_default_fixture_loop_scope = "function"
|
|
62
63
|
|
|
64
|
+
[tool.readme_standards]
|
|
65
|
+
policy = "package-guide-v1"
|
|
66
|
+
readme = "README.md"
|
|
67
|
+
brand = "swarmauri"
|
|
68
|
+
brand_catalog = "../../../tools/readme/brands.toml"
|
|
69
|
+
repository = "https://github.com/swarmauri/swarmauri-sdk"
|
|
70
|
+
ref = "master"
|
|
71
|
+
package_path = "pkgs/40-standards/swarmauri_middleware_time"
|
|
72
|
+
layer = "standards"
|
|
73
|
+
lifecycle = "active"
|
|
74
|
+
license_file = "LICENSE"
|
|
75
|
+
notice_file = "NOTICE"
|
|
76
|
+
|
|
77
|
+
[tool.readme_standards.distributions.pypi]
|
|
78
|
+
name = "swarmauri_middleware_time"
|
|
79
|
+
published = true
|
|
80
|
+
|
|
81
|
+
[tool.readme_standards.examples.quick_start]
|
|
82
|
+
source = "docs/readme/quick_start.py"
|
|
83
|
+
test = "tests/unit/test_readme_sources.py"
|
|
84
|
+
language = "python"
|
|
85
|
+
expected_exit_code = 0
|
|
86
|
+
|
|
87
|
+
[tool.readme_standards.examples.usage]
|
|
88
|
+
source = "docs/readme/usage.py"
|
|
89
|
+
test = "tests/unit/test_readme_sources.py"
|
|
90
|
+
language = "python"
|
|
91
|
+
expected_exit_code = 0
|
|
92
|
+
|
|
93
|
+
[tool.readme_standards.statuses.readme]
|
|
94
|
+
label = "CI gate"
|
|
95
|
+
url = "https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"
|
|
96
|
+
|
|
97
|
+
[tool.readme_standards.statuses.tests]
|
|
98
|
+
label = "example source"
|
|
99
|
+
url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/tests/unit/test_readme_sources.py"
|
|
100
|
+
|
|
101
|
+
[tool.readme_standards.statuses.certification]
|
|
102
|
+
label = "not certified"
|
|
103
|
+
url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_time/README.md#certification-status"
|
|
104
|
+
|
|
105
|
+
[tool.readme_standards.statuses.governance]
|
|
106
|
+
label = "repository policy"
|
|
107
|
+
url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md"
|
|
108
|
+
|
|
109
|
+
[tool.readme_standards.statuses.evidence]
|
|
110
|
+
label = "source and CI"
|
|
111
|
+
url = "https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"
|
|
63
112
|
[build-system]
|
|
64
113
|
requires = ["poetry-core>=1.0.0"]
|
|
65
114
|
build-backend = "poetry.core.masonry.api"
|
|
@@ -72,11 +121,12 @@ dev = [
|
|
|
72
121
|
"pytest-json-report>=1.5.0",
|
|
73
122
|
"pytest-mock>=3.12.0",
|
|
74
123
|
"python-dotenv",
|
|
75
|
-
"
|
|
124
|
+
"httpx>=0.27",
|
|
76
125
|
"flake8>=7.0",
|
|
77
126
|
"pytest-timeout>=2.3.1",
|
|
78
127
|
"ruff>=0.9.9",
|
|
79
128
|
"pytest-benchmark>=4.0.0",
|
|
129
|
+
"readme-standards==0.1.3; python_version >= \"3.11\"",
|
|
80
130
|
]
|
|
81
131
|
|
|
82
132
|
[project.entry-points.'swarmauri.middlewares']
|
|
@@ -2,7 +2,8 @@ import logging
|
|
|
2
2
|
import time
|
|
3
3
|
from typing import Any, Callable
|
|
4
4
|
|
|
5
|
-
from
|
|
5
|
+
from starlette.exceptions import HTTPException
|
|
6
|
+
from starlette.requests import Request
|
|
6
7
|
from swarmauri_base.ComponentBase import ComponentBase
|
|
7
8
|
from swarmauri_base.middlewares.MiddlewareBase import MiddlewareBase
|
|
8
9
|
|
|
@@ -25,7 +26,9 @@ class TimerMiddleware(MiddlewareBase, ComponentBase):
|
|
|
25
26
|
async def dispatch(
|
|
26
27
|
self, request: Request, call_next: Callable[[Request], Any]
|
|
27
28
|
) -> Any:
|
|
28
|
-
"""
|
|
29
|
+
"""
|
|
30
|
+
Dispatches the request to the next middleware in the chain while
|
|
31
|
+
tracking time.
|
|
29
32
|
|
|
30
33
|
This method measures the time taken for processing the request
|
|
31
34
|
from start to finish. It logs the start time, processes the
|
|
@@ -47,7 +50,10 @@ class TimerMiddleware(MiddlewareBase, ComponentBase):
|
|
|
47
50
|
# Record the start time of the request
|
|
48
51
|
start_time = time.time()
|
|
49
52
|
_LOGGER.info(
|
|
50
|
-
|
|
53
|
+
(
|
|
54
|
+
f"Request {request.method} {request.url.path} started at "
|
|
55
|
+
f"{start_time}"
|
|
56
|
+
)
|
|
51
57
|
)
|
|
52
58
|
|
|
53
59
|
try:
|
|
@@ -56,14 +62,20 @@ class TimerMiddleware(MiddlewareBase, ComponentBase):
|
|
|
56
62
|
except Exception as e:
|
|
57
63
|
# Log any exceptions that occur during processing
|
|
58
64
|
_LOGGER.error(
|
|
59
|
-
|
|
65
|
+
(
|
|
66
|
+
f"Error processing request {request.method} "
|
|
67
|
+
f"{request.url.path}: {str(e)}"
|
|
68
|
+
)
|
|
60
69
|
)
|
|
61
70
|
raise HTTPException(status_code=500, detail=str(e))
|
|
62
71
|
|
|
63
72
|
# Calculate the total time taken
|
|
64
73
|
total_time = time.time() - start_time
|
|
65
74
|
_LOGGER.info(
|
|
66
|
-
|
|
75
|
+
(
|
|
76
|
+
f"Request {request.method} {request.url.path} completed in "
|
|
77
|
+
f"{total_time:.4f} seconds"
|
|
78
|
+
)
|
|
67
79
|
)
|
|
68
80
|
|
|
69
81
|
# Fix: Add timing headers to the response
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: swarmauri_middleware_time
|
|
3
|
-
Version: 0.8.0.dev46
|
|
4
|
-
Summary: Middleware for tracking request processing time in Swarmauri applications
|
|
5
|
-
License-Expression: Apache-2.0
|
|
6
|
-
License-File: LICENSE
|
|
7
|
-
Keywords: swarmauri,sdk,standards,middleware,time
|
|
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_time/">
|
|
31
|
-
<img src="https://img.shields.io/pypi/dm/swarmauri_middleware_time" alt="PyPI - Downloads"/>
|
|
32
|
-
</a>
|
|
33
|
-
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_time/">
|
|
34
|
-
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_time.svg"/>
|
|
35
|
-
</a>
|
|
36
|
-
<a href="https://pypi.org/project/swarmauri_middleware_time/">
|
|
37
|
-
<img src="https://img.shields.io/pypi/pyversions/swarmauri_middleware_time" alt="PyPI - Python Version"/>
|
|
38
|
-
</a>
|
|
39
|
-
<a href="https://pypi.org/project/swarmauri_middleware_time/">
|
|
40
|
-
<img src="https://img.shields.io/pypi/l/swarmauri_middleware_time" alt="PyPI - License"/>
|
|
41
|
-
</a>
|
|
42
|
-
<a href="https://pypi.org/project/swarmauri_middleware_time/">
|
|
43
|
-
<img src="https://img.shields.io/pypi/v/swarmauri_middleware_time?label=swarmauri_middleware_time&color=green" alt="PyPI - swarmauri_middleware_time"/>
|
|
44
|
-
</a>
|
|
45
|
-
</p>
|
|
46
|
-
|
|
47
|
-
---
|
|
48
|
-
|
|
49
|
-
# Swarmauri Middleware Time
|
|
50
|
-
|
|
51
|
-
Middleware for tracking request processing time in Swarmauri applications.
|
|
52
|
-
|
|
53
|
-
## Features
|
|
54
|
-
|
|
55
|
-
- Logs when each request starts and when it completes using Python's `logging` module.
|
|
56
|
-
- Measures the total time spent handling a request and attaches `X-Request-Duration`
|
|
57
|
-
and `X-Request-Start-Time` headers to the response.
|
|
58
|
-
- Raises an `HTTPException` with status code `500` if an unexpected error occurs
|
|
59
|
-
while the downstream handler is executing.
|
|
60
|
-
|
|
61
|
-
## Installation
|
|
62
|
-
|
|
63
|
-
### pip
|
|
64
|
-
|
|
65
|
-
```bash
|
|
66
|
-
pip install swarmauri_middleware_time
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### Poetry
|
|
70
|
-
|
|
71
|
-
```bash
|
|
72
|
-
poetry add swarmauri_middleware_time
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### uv
|
|
76
|
-
|
|
77
|
-
```bash
|
|
78
|
-
# Install uv if it is not already available
|
|
79
|
-
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
80
|
-
|
|
81
|
-
# Add the middleware to your project
|
|
82
|
-
uv add swarmauri_middleware_time
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## Usage
|
|
86
|
-
|
|
87
|
-
The middleware exposes a standard `dispatch` method that matches FastAPI's middleware
|
|
88
|
-
interface. Instantiate it once and forward requests through `dispatch` inside an
|
|
89
|
-
`@app.middleware("http")` hook:
|
|
90
|
-
|
|
91
|
-
```python
|
|
92
|
-
from fastapi import FastAPI, Request
|
|
93
|
-
from starlette.testclient import TestClient
|
|
94
|
-
|
|
95
|
-
from swarmauri_middleware_time import TimerMiddleware
|
|
96
|
-
|
|
97
|
-
app = FastAPI()
|
|
98
|
-
timer_middleware = TimerMiddleware()
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
@app.middleware("http")
|
|
102
|
-
async def add_timer(request: Request, call_next):
|
|
103
|
-
return await timer_middleware.dispatch(request, call_next)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
@app.get("/ping")
|
|
107
|
-
async def ping():
|
|
108
|
-
return {"message": "pong"}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if __name__ == "__main__":
|
|
112
|
-
client = TestClient(app)
|
|
113
|
-
response = client.get("/ping")
|
|
114
|
-
|
|
115
|
-
assert response.json() == {"message": "pong"}
|
|
116
|
-
assert "X-Request-Duration" in response.headers
|
|
117
|
-
assert float(response.headers["X-Request-Duration"]) >= 0.0
|
|
118
|
-
assert "X-Request-Start-Time" in response.headers
|
|
119
|
-
|
|
120
|
-
print("Duration header:", response.headers["X-Request-Duration"])
|
|
121
|
-
print("Start time header:", response.headers["X-Request-Start-Time"])
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
## Want to help?
|
|
125
|
-
|
|
126
|
-
If you want to contribute to swarmauri-sdk, read up on our [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/contributing.md) that will help you get started.
|
|
127
|
-
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
|
-
<p align="center">
|
|
4
|
-
<a href="https://pypi.org/project/swarmauri_middleware_time/">
|
|
5
|
-
<img src="https://img.shields.io/pypi/dm/swarmauri_middleware_time" alt="PyPI - Downloads"/>
|
|
6
|
-
</a>
|
|
7
|
-
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_time/">
|
|
8
|
-
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_time.svg"/>
|
|
9
|
-
</a>
|
|
10
|
-
<a href="https://pypi.org/project/swarmauri_middleware_time/">
|
|
11
|
-
<img src="https://img.shields.io/pypi/pyversions/swarmauri_middleware_time" alt="PyPI - Python Version"/>
|
|
12
|
-
</a>
|
|
13
|
-
<a href="https://pypi.org/project/swarmauri_middleware_time/">
|
|
14
|
-
<img src="https://img.shields.io/pypi/l/swarmauri_middleware_time" alt="PyPI - License"/>
|
|
15
|
-
</a>
|
|
16
|
-
<a href="https://pypi.org/project/swarmauri_middleware_time/">
|
|
17
|
-
<img src="https://img.shields.io/pypi/v/swarmauri_middleware_time?label=swarmauri_middleware_time&color=green" alt="PyPI - swarmauri_middleware_time"/>
|
|
18
|
-
</a>
|
|
19
|
-
</p>
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
# Swarmauri Middleware Time
|
|
24
|
-
|
|
25
|
-
Middleware for tracking request processing time in Swarmauri applications.
|
|
26
|
-
|
|
27
|
-
## Features
|
|
28
|
-
|
|
29
|
-
- Logs when each request starts and when it completes using Python's `logging` module.
|
|
30
|
-
- Measures the total time spent handling a request and attaches `X-Request-Duration`
|
|
31
|
-
and `X-Request-Start-Time` headers to the response.
|
|
32
|
-
- Raises an `HTTPException` with status code `500` if an unexpected error occurs
|
|
33
|
-
while the downstream handler is executing.
|
|
34
|
-
|
|
35
|
-
## Installation
|
|
36
|
-
|
|
37
|
-
### pip
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
pip install swarmauri_middleware_time
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### Poetry
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
poetry add swarmauri_middleware_time
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### uv
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
# Install uv if it is not already available
|
|
53
|
-
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
54
|
-
|
|
55
|
-
# Add the middleware to your project
|
|
56
|
-
uv add swarmauri_middleware_time
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## Usage
|
|
60
|
-
|
|
61
|
-
The middleware exposes a standard `dispatch` method that matches FastAPI's middleware
|
|
62
|
-
interface. Instantiate it once and forward requests through `dispatch` inside an
|
|
63
|
-
`@app.middleware("http")` hook:
|
|
64
|
-
|
|
65
|
-
```python
|
|
66
|
-
from fastapi import FastAPI, Request
|
|
67
|
-
from starlette.testclient import TestClient
|
|
68
|
-
|
|
69
|
-
from swarmauri_middleware_time import TimerMiddleware
|
|
70
|
-
|
|
71
|
-
app = FastAPI()
|
|
72
|
-
timer_middleware = TimerMiddleware()
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
@app.middleware("http")
|
|
76
|
-
async def add_timer(request: Request, call_next):
|
|
77
|
-
return await timer_middleware.dispatch(request, call_next)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
@app.get("/ping")
|
|
81
|
-
async def ping():
|
|
82
|
-
return {"message": "pong"}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if __name__ == "__main__":
|
|
86
|
-
client = TestClient(app)
|
|
87
|
-
response = client.get("/ping")
|
|
88
|
-
|
|
89
|
-
assert response.json() == {"message": "pong"}
|
|
90
|
-
assert "X-Request-Duration" in response.headers
|
|
91
|
-
assert float(response.headers["X-Request-Duration"]) >= 0.0
|
|
92
|
-
assert "X-Request-Start-Time" in response.headers
|
|
93
|
-
|
|
94
|
-
print("Duration header:", response.headers["X-Request-Duration"])
|
|
95
|
-
print("Start time header:", response.headers["X-Request-Start-Time"])
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## Want to help?
|
|
99
|
-
|
|
100
|
-
If you want to contribute to swarmauri-sdk, read up on our [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/contributing.md) that will help you get started.
|
|
File without changes
|
|
File without changes
|