swarmauri_middleware_time 0.8.0.dev3__tar.gz → 0.8.0.dev32__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.
@@ -1,8 +1,10 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: swarmauri_middleware_time
3
- Version: 0.8.0.dev3
3
+ Version: 0.8.0.dev32
4
4
  Summary: Middleware for tracking request processing time in Swarmauri applications
5
- License: Apache-2.0
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Keywords: swarmauri,sdk,standards,middleware,time
6
8
  Author: Jacob Stewart
7
9
  Author-email: jacob@swarmauri.com
8
10
  Requires-Python: >=3.10,<3.13
@@ -13,13 +15,16 @@ Classifier: Programming Language :: Python :: 3.11
13
15
  Classifier: Programming Language :: Python :: 3.12
14
16
  Classifier: Programming Language :: Python :: 3.13
15
17
  Classifier: Development Status :: 3 - Alpha
18
+ Classifier: Programming Language :: Python
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3 :: Only
16
21
  Requires-Dist: fastapi
17
22
  Requires-Dist: swarmauri_base
18
23
  Requires-Dist: swarmauri_core
19
24
  Requires-Dist: swarmauri_standard
20
25
  Description-Content-Type: text/markdown
21
26
 
22
- ![Swamauri Logo](https://res.cloudinary.com/dbjmpekvl/image/upload/v1730099724/Swarmauri-logo-lockup-2048x757_hww01w.png)
27
+ ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
23
28
 
24
29
  <p align="center">
25
30
  <a href="https://pypi.org/project/swarmauri_middleware_time/">
@@ -43,14 +48,79 @@ Description-Content-Type: text/markdown
43
48
 
44
49
  # Swarmauri Middleware Time
45
50
 
46
- Middleware for tracking request processing time in Swarmauri applications
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.
47
60
 
48
61
  ## Installation
49
62
 
63
+ ### pip
64
+
50
65
  ```bash
51
66
  pip install swarmauri_middleware_time
52
67
  ```
53
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
+
54
124
  ## Want to help?
55
125
 
56
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.
@@ -0,0 +1,100 @@
1
+ ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
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.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "swarmauri_middleware_time"
3
- version = "0.8.0.dev3"
3
+ version = "0.8.0.dev32"
4
4
  description = "Middleware for tracking request processing time in Swarmauri applications"
5
5
  license = "Apache-2.0"
6
6
  readme = "README.md"
@@ -14,6 +14,9 @@ classifiers = [
14
14
  "Programming Language :: Python :: 3.12",
15
15
  "Programming Language :: Python :: 3.13",
16
16
  "Development Status :: 3 - Alpha",
17
+ "Programming Language :: Python",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3 :: Only",
17
20
  ]
18
21
  authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
19
22
  dependencies = [
@@ -22,6 +25,13 @@ dependencies = [
22
25
  "swarmauri_base",
23
26
  "swarmauri_standard",
24
27
  ]
28
+ keywords = [
29
+ 'swarmauri',
30
+ 'sdk',
31
+ 'standards',
32
+ 'middleware',
33
+ 'time',
34
+ ]
25
35
 
26
36
  [tool.uv.sources]
27
37
  swarmauri_core = { workspace = true }
@@ -40,6 +50,7 @@ markers = [
40
50
  "xfail: Expected failures",
41
51
  "acceptance: Acceptance tests",
42
52
  "perf: Performance tests that measure execution time and resource usage",
53
+ "example: Documentation examples",
43
54
  ]
44
55
  timeout = 300
45
56
  log_cli = true
@@ -1,35 +0,0 @@
1
- ![Swamauri Logo](https://res.cloudinary.com/dbjmpekvl/image/upload/v1730099724/Swarmauri-logo-lockup-2048x757_hww01w.png)
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
- ## Installation
28
-
29
- ```bash
30
- pip install swarmauri_middleware_time
31
- ```
32
-
33
- ## Want to help?
34
-
35
- 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.