swarmauri_middleware_session 0.8.0.dev48__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.
@@ -0,0 +1,7 @@
1
+ swarmauri_middleware_session
2
+
3
+ Distribution: swarmauri_middleware_session
4
+ Repository: https://github.com/swarmauri/swarmauri-sdk
5
+
6
+ Author attribution: Jacob Stewart.
7
+ Licensed under Apache-2.0; see LICENSE.
@@ -0,0 +1,436 @@
1
+ Metadata-Version: 2.4
2
+ Name: swarmauri_middleware_session
3
+ Version: 0.11.0
4
+ Summary: Session middleware for maintaining session state across requests.
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ License-File: NOTICE
8
+ Keywords: swarmauri,sdk,standards,middleware,session
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_session
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_session</strong></p>
33
+ <p align="center">Session middleware for maintaining session state across requests.</p>
34
+ <p align="center">
35
+ <a href="https://pypi.org/project/swarmauri_middleware_session/"><img alt="pypi: swarmauri_middleware_session" src="https://img.shields.io/pypi/v/swarmauri_middleware_session?labelColor=1E293B&amp;color=1D4ED8"></a>
36
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/pyproject.toml"><img alt="Source version: 0.11.0" src="https://img.shields.io/static/v1?label=Source%20version&amp;message=0.11.0&amp;labelColor=1E293B&amp;color=4338CA"></a>
37
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/pyproject.toml"><img alt="Python: &gt;=3.10,&lt;3.15" src="https://img.shields.io/static/v1?label=Python&amp;message=%3E%3D3.10%2C%3C3.15&amp;labelColor=1E293B&amp;color=0F766E"></a>
38
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/pyproject.toml"><img alt="Layer: standards" src="https://img.shields.io/static/v1?label=Layer&amp;message=standards&amp;labelColor=1E293B&amp;color=6D28D9"></a>
39
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/README.md#lifecycle-and-migration"><img alt="Lifecycle: active" src="https://img.shields.io/static/v1?label=Lifecycle&amp;message=active&amp;labelColor=1E293B&amp;color=166534"></a>
40
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/static/v1?label=License&amp;message=Apache-2.0&amp;labelColor=1E293B&amp;color=86198F"></a>
41
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/NOTICE"><img alt="Notice: attribution" src="https://img.shields.io/static/v1?label=Notice&amp;message=attribution&amp;labelColor=1E293B&amp;color=86198F"></a>
42
+ </p>
43
+ <p align="center">
44
+ <a href="https://pypi.org/project/swarmauri_middleware_session/"><img alt="Monthly PyPI downloads: swarmauri_middleware_session" src="https://img.shields.io/pypi/dm/swarmauri_middleware_session?labelColor=1E293B&amp;color=0E7490"></a>
45
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/README.md"><img alt="README hits: swarmauri_middleware_session" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/pkgs/40-standards/swarmauri_middleware_session/README.md.svg?label=README%20hits&amp;labelColor=1E293B&amp;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&amp;message=CI%20gate&amp;labelColor=1E293B&amp;color=1D4ED8"></a>
49
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/tests/unit/test_readme_sources.py"><img alt="Tests: example source" src="https://img.shields.io/static/v1?label=Tests&amp;message=example%20source&amp;labelColor=1E293B&amp;color=0F766E"></a>
50
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/README.md#certification-status"><img alt="Certification: not certified" src="https://img.shields.io/static/v1?label=Certification&amp;message=not%20certified&amp;labelColor=1E293B&amp;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&amp;message=repository%20policy&amp;labelColor=1E293B&amp;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&amp;message=source%20and%20CI&amp;labelColor=1E293B&amp;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
+ Session middleware for Starlette applications that keeps a
64
+ lightweight, in-memory session store synchronized with every request and
65
+ response.
66
+
67
+ - Accepts an incoming session identifier from the `X-Session-ID` request header
68
+ (customisable through `session_header`).
69
+ - Falls back to generating a new UUID session identifier and persists it on the
70
+ response when none is supplied.
71
+ - Stores per-session data in `session_storage`, allowing subsequent requests to
72
+ reuse state keyed by the same identifier.
73
+ - Writes the active session id to `request.state.session_id` and mirrors it in
74
+ the `session_id` response cookie (customisable through `session_cookie`).
75
+ - Uses a configurable `max_age` to control the lifetime of the emitted cookie.
76
+
77
+ ### Why This Package
78
+
79
+ `swarmauri_middleware_session` isolates this responsibility: Session middleware for maintaining session state across requests. Its [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/swarmauri_middleware_session/__init__.py) exposes `SessionMiddleware`, allowing consumers to select this package without treating adjacent packages as part of its public contract.
80
+
81
+ ### When to Use
82
+
83
+ Choose `swarmauri_middleware_session` when your integration needs session middleware for maintaining session state across requests. Match the imports below to your application boundary and install its declared dependencies before using the example.
84
+
85
+ ### Features
86
+
87
+ - `SessionMiddleware`: Session middleware for maintaining session state across requests.
88
+
89
+ ### Non-Goals
90
+
91
+ `swarmauri_middleware_session` owns session middleware for maintaining session state across requests. 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.
92
+
93
+ ---
94
+
95
+ ## Getting Started
96
+
97
+ ### Prerequisites
98
+
99
+ Python `>=3.10,<3.15` is required. The [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/pyproject.toml) declares runtime dependencies including `starlette`, `swarmauri-core`, `swarmauri-base`, `swarmauri-standard`. Read the example’s inputs and service requirements before execution.
100
+
101
+ ### Installation
102
+
103
+ Install from PyPI using the toolchain that fits your workflow.
104
+
105
+ #### uv
106
+
107
+ <!-- readme-standards:begin installation.uv -->
108
+ ```bash
109
+ uv add swarmauri_middleware_session
110
+ ```
111
+ <!-- readme-standards:end installation.uv -->
112
+
113
+ ```bash
114
+ uv venv
115
+ source .venv/bin/activate
116
+ uv pip install swarmauri_middleware_session
117
+ ```
118
+
119
+ #### pip
120
+
121
+ <!-- readme-standards:begin installation.pip -->
122
+ ```bash
123
+ python -m pip install swarmauri_middleware_session
124
+ ```
125
+ <!-- readme-standards:end installation.pip -->
126
+
127
+ ```bash
128
+ pip install swarmauri_middleware_session
129
+ ```
130
+
131
+ #### Poetry
132
+
133
+ <!-- readme-standards:begin installation.poetry -->
134
+ ```bash
135
+ poetry add swarmauri_middleware_session
136
+ ```
137
+ <!-- readme-standards:end installation.poetry -->
138
+
139
+ ```bash
140
+ poetry add swarmauri_middleware_session
141
+ ```
142
+
143
+ ### Quick Start
144
+
145
+ #### Example
146
+
147
+ <!-- readme-standards:begin example.quick-start -->
148
+ Source: [docs/readme/quick_start.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/docs/readme/quick_start.py).
149
+
150
+ ```python
151
+ from starlette.applications import Starlette
152
+ from starlette.middleware.base import BaseHTTPMiddleware
153
+ from starlette.requests import Request
154
+ from starlette.responses import JSONResponse
155
+ from starlette.testclient import TestClient
156
+
157
+ from swarmauri_middleware_session import SessionMiddleware
158
+
159
+
160
+ app = Starlette()
161
+ session_middleware = SessionMiddleware()
162
+
163
+
164
+ async def attach_session(request: Request, call_next):
165
+ return await session_middleware.dispatch(request, call_next)
166
+
167
+
168
+ app.add_middleware(BaseHTTPMiddleware, dispatch=attach_session)
169
+
170
+
171
+ async def greet(request: Request):
172
+ session_id = request.state.session_id
173
+ session_data = session_middleware.session_storage.setdefault(
174
+ session_id, {}
175
+ )
176
+ session_data["visits"] = session_data.get("visits", 0) + 1
177
+ return JSONResponse(
178
+ {"session_id": session_id, "visits": session_data["visits"]}
179
+ )
180
+
181
+
182
+ app.add_route("/greet", greet)
183
+
184
+ client = TestClient(app)
185
+
186
+ first_response = client.get("/greet")
187
+ first_data = first_response.json()
188
+
189
+ second_response = client.get(
190
+ "/greet", headers={"X-Session-ID": first_response.headers["X-Session-ID"]}
191
+ )
192
+ second_data = second_response.json()
193
+
194
+ print(first_data)
195
+ print(second_data)
196
+ ```
197
+ <!-- readme-standards:end example.quick-start -->
198
+
199
+ Running the example prints the initial visit count followed by an incremented
200
+ visit count for the same session, demonstrating how the middleware keeps track
201
+ of state across requests.
202
+
203
+ #### Expected Result
204
+
205
+ The example demonstrates the documented `swarmauri_middleware_session` 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.
206
+
207
+ ---
208
+
209
+ ## Usage
210
+
211
+ ### Common Workflows
212
+
213
+ <!-- readme-standards:begin example.usage -->
214
+ Source: [docs/readme/usage.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/docs/readme/usage.py).
215
+
216
+ ```python
217
+ from starlette.applications import Starlette
218
+ from starlette.middleware.base import BaseHTTPMiddleware
219
+ from starlette.requests import Request
220
+ from starlette.responses import JSONResponse
221
+ from starlette.testclient import TestClient
222
+
223
+ from swarmauri_middleware_session import SessionMiddleware
224
+
225
+
226
+ app = Starlette()
227
+ session_middleware = SessionMiddleware()
228
+
229
+
230
+ async def attach_session(request: Request, call_next):
231
+ return await session_middleware.dispatch(request, call_next)
232
+
233
+
234
+ app.add_middleware(BaseHTTPMiddleware, dispatch=attach_session)
235
+
236
+
237
+ async def greet(request: Request):
238
+ session_id = request.state.session_id
239
+ session_data = session_middleware.session_storage.setdefault(
240
+ session_id, {}
241
+ )
242
+ session_data["visits"] = session_data.get("visits", 0) + 1
243
+ return JSONResponse(
244
+ {"session_id": session_id, "visits": session_data["visits"]}
245
+ )
246
+
247
+
248
+ app.add_route("/greet", greet)
249
+
250
+ client = TestClient(app)
251
+
252
+ first_response = client.get("/greet")
253
+ first_data = first_response.json()
254
+
255
+ second_response = client.get(
256
+ "/greet", headers={"X-Session-ID": first_response.headers["X-Session-ID"]}
257
+ )
258
+ second_data = second_response.json()
259
+
260
+ print(first_data)
261
+ print(second_data)
262
+ ```
263
+ <!-- readme-standards:end example.usage -->
264
+
265
+ ### Configuration
266
+
267
+ Configure `swarmauri_middleware_session` through the APIs in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/swarmauri_middleware_session/__init__.py); its [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/pyproject.toml) describes installation requirements, not an implicit service configuration. No additional package-global configuration contract is inferred from dependencies.
268
+
269
+ ### Error Handling
270
+
271
+ The inspected `swarmauri_middleware_session` source does not establish a package-wide exception hierarchy. Preserve errors from its declared dependencies and validate inputs using the specific public contract in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/swarmauri_middleware_session/__init__.py).
272
+
273
+ ### Best Practices
274
+
275
+ Use the explicit `swarmauri_middleware_session` imports documented below and keep collaborator configuration with the caller. Run the package’s relevant tests after changing `SessionMiddleware`; an import or successful installation alone does not establish its runtime guarantees.
276
+
277
+ ---
278
+
279
+ ## Package Boundary
280
+
281
+ ### What It Owns
282
+
283
+ `swarmauri_middleware_session` is located in `standards` and owns session middleware for maintaining session state across requests. Source-declared APIs include `SessionMiddleware`. The [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/pyproject.toml) records its direct dependency boundary.
284
+
285
+ ### Public API and Import Surfaces
286
+
287
+ Import namespace: `swarmauri_middleware_session`.
288
+
289
+ Source-declared exports or types: `SessionMiddleware`.
290
+
291
+ Inspect [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/swarmauri_middleware_session/__init__.py) for exact signatures; this inventory does not designate every internal module as stable.
292
+
293
+ ### Entry Points
294
+
295
+ <!-- readme-standards:begin entry-points -->
296
+ - `swarmauri.middlewares` → `SessionMiddleware` → `swarmauri_middleware_session:SessionMiddleware`
297
+ <!-- readme-standards:end entry-points -->
298
+
299
+ ### Injected Dependencies
300
+
301
+ The direct installation dependencies of `swarmauri_middleware_session` 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_session/swarmauri_middleware_session/__init__.py).
302
+
303
+ ### Protocol Consumers
304
+
305
+ No direct package-manifest dependency on `swarmauri_middleware_session` was found in the audited three-repository inventory. External consumers may still use its documented imports or commands.
306
+
307
+ ### Extensions
308
+
309
+ For `swarmauri_middleware_session`, use the source-declared public interfaces (`SessionMiddleware`) 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.
310
+
311
+ ---
312
+
313
+ ## Operations and Readiness
314
+
315
+ ### Operational Requirements
316
+
317
+ Operate `swarmauri_middleware_session` 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_session/pyproject.toml) are prerequisites; deployment topology, credentials, and readiness remain the responsibility of the consuming application unless explicitly documented above.
318
+
319
+ ### Health and Observability
320
+
321
+ This README does not establish a standalone health endpoint for `swarmauri_middleware_session`. 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.
322
+
323
+ ### Security and Resource Limits
324
+
325
+ Apply the input, credential, and resource constraints implemented in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/swarmauri_middleware_session/__init__.py). The `swarmauri_middleware_session` README gate is a documentation check, not a security review or a substitute for the implementation’s limits and caller authorization.
326
+
327
+ ### Compatibility
328
+
329
+ This source version of `swarmauri_middleware_session` 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.
330
+
331
+ ---
332
+
333
+ ## Verification
334
+
335
+ ### Tests
336
+
337
+ Run `python -m pytest tests/unit/test_readme_sources.py` from the `swarmauri_middleware_session` package directory for the maintained example source checks (Python compilation and non-Python file presence). Existing package tests include:
338
+
339
+ - [tests/test_readme_example.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/tests/test_readme_example.py)
340
+ - [tests/i9n/test_i9n__init__.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/tests/i9n/test_i9n__init__.py)
341
+ - [tests/unit/test_SessionMiddleware.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/tests/unit/test_SessionMiddleware.py)
342
+
343
+ The repository README gate also checks the required heading tree, metadata, managed fragments, and referenced files.
344
+
345
+ ### Certification Status
346
+
347
+ No external certification is asserted for `swarmauri_middleware_session` by this documentation migration. README conformance, example syntax, runtime tests, and protocol or security certification are distinct evidence scopes.
348
+
349
+ ### Evidence
350
+
351
+ 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_session/swarmauri_middleware_session/__init__.py) and example sources support the package-boundary description; external runtime behavior requires its own test evidence.
352
+
353
+ ---
354
+
355
+ ## FAQ
356
+
357
+ ### Why
358
+
359
+ **Why select this package?** `swarmauri_middleware_session` provides session middleware for maintaining session state across requests; use its own API boundary rather than assuming neighboring packages are bundled or configured automatically.
360
+
361
+ ### How
362
+
363
+ **How do I start?** Install or synchronize the environment under Getting Started, follow the maintained example for `swarmauri_middleware_session`, and consult [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/swarmauri_middleware_session/__init__.py) for the exact types and signatures involved.
364
+
365
+ ### When
366
+
367
+ **When should I validate an upgrade?** Recheck `swarmauri_middleware_session` whenever its source version, declared collaborators, configuration, or caller changes. Run relevant behavioral tests in addition to the README gate before promotion.
368
+
369
+ ---
370
+
371
+ ## Documentation and Related Packages
372
+
373
+ ### More Documentation
374
+
375
+ 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_session/swarmauri_middleware_session/__init__.py), and [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/pyproject.toml) provide the supporting context for `swarmauri_middleware_session`. The [README policy](https://github.com/groupsum/readme-standards/blob/master/docs/outline.md) defines the common document structure.
376
+
377
+ ### Related Packages
378
+
379
+ - [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.
380
+ - [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.
381
+ - [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.
382
+
383
+ ### Project Links
384
+
385
+ <!-- readme-standards:begin project-links -->
386
+ - [pypi: swarmauri_middleware_session](https://pypi.org/project/swarmauri_middleware_session/)
387
+ <!-- readme-standards:end project-links -->
388
+
389
+ ---
390
+
391
+ ## Contributing
392
+
393
+ ### How to Contribute
394
+
395
+ 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.
396
+
397
+ ### Development Setup
398
+
399
+ Work from the `pkgs/40-standards/swarmauri_middleware_session` 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.
400
+
401
+ ### Notes for Maintainers
402
+
403
+ Edit authored prose directly in this `swarmauri_middleware_session` 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.
404
+
405
+ ---
406
+
407
+ ## Governance
408
+
409
+ ### Ownership and Decision Making
410
+
411
+ Changes to `swarmauri_middleware_session` 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_session/pyproject.toml); this README does not assign new publishing or administrative authority.
412
+
413
+ ### Standards and Policies
414
+
415
+ `swarmauri_middleware_session` 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.
416
+
417
+ ### Lifecycle and Migration
418
+
419
+ The `swarmauri_middleware_session` source version is `0.11.0`.
420
+
421
+ ---
422
+
423
+ ## License and Attribution
424
+
425
+ ### License
426
+
427
+ <!-- readme-standards:begin license -->
428
+ Licensed under `Apache-2.0`. See [LICENSE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/LICENSE).
429
+ <!-- readme-standards:end license -->
430
+
431
+ ### Notices
432
+
433
+ <!-- readme-standards:begin notices -->
434
+ See [NOTICE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/NOTICE) for attribution.
435
+ <!-- readme-standards:end notices -->
436
+
@@ -0,0 +1,408 @@
1
+ # swarmauri_middleware_session
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_session</strong></p>
6
+ <p align="center">Session middleware for maintaining session state across requests.</p>
7
+ <p align="center">
8
+ <a href="https://pypi.org/project/swarmauri_middleware_session/"><img alt="pypi: swarmauri_middleware_session" src="https://img.shields.io/pypi/v/swarmauri_middleware_session?labelColor=1E293B&amp;color=1D4ED8"></a>
9
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/pyproject.toml"><img alt="Source version: 0.11.0" src="https://img.shields.io/static/v1?label=Source%20version&amp;message=0.11.0&amp;labelColor=1E293B&amp;color=4338CA"></a>
10
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/pyproject.toml"><img alt="Python: &gt;=3.10,&lt;3.15" src="https://img.shields.io/static/v1?label=Python&amp;message=%3E%3D3.10%2C%3C3.15&amp;labelColor=1E293B&amp;color=0F766E"></a>
11
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/pyproject.toml"><img alt="Layer: standards" src="https://img.shields.io/static/v1?label=Layer&amp;message=standards&amp;labelColor=1E293B&amp;color=6D28D9"></a>
12
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/README.md#lifecycle-and-migration"><img alt="Lifecycle: active" src="https://img.shields.io/static/v1?label=Lifecycle&amp;message=active&amp;labelColor=1E293B&amp;color=166534"></a>
13
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/static/v1?label=License&amp;message=Apache-2.0&amp;labelColor=1E293B&amp;color=86198F"></a>
14
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/NOTICE"><img alt="Notice: attribution" src="https://img.shields.io/static/v1?label=Notice&amp;message=attribution&amp;labelColor=1E293B&amp;color=86198F"></a>
15
+ </p>
16
+ <p align="center">
17
+ <a href="https://pypi.org/project/swarmauri_middleware_session/"><img alt="Monthly PyPI downloads: swarmauri_middleware_session" src="https://img.shields.io/pypi/dm/swarmauri_middleware_session?labelColor=1E293B&amp;color=0E7490"></a>
18
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/README.md"><img alt="README hits: swarmauri_middleware_session" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/pkgs/40-standards/swarmauri_middleware_session/README.md.svg?label=README%20hits&amp;labelColor=1E293B&amp;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&amp;message=CI%20gate&amp;labelColor=1E293B&amp;color=1D4ED8"></a>
22
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/tests/unit/test_readme_sources.py"><img alt="Tests: example source" src="https://img.shields.io/static/v1?label=Tests&amp;message=example%20source&amp;labelColor=1E293B&amp;color=0F766E"></a>
23
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/README.md#certification-status"><img alt="Certification: not certified" src="https://img.shields.io/static/v1?label=Certification&amp;message=not%20certified&amp;labelColor=1E293B&amp;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&amp;message=repository%20policy&amp;labelColor=1E293B&amp;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&amp;message=source%20and%20CI&amp;labelColor=1E293B&amp;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
+ Session middleware for Starlette applications that keeps a
37
+ lightweight, in-memory session store synchronized with every request and
38
+ response.
39
+
40
+ - Accepts an incoming session identifier from the `X-Session-ID` request header
41
+ (customisable through `session_header`).
42
+ - Falls back to generating a new UUID session identifier and persists it on the
43
+ response when none is supplied.
44
+ - Stores per-session data in `session_storage`, allowing subsequent requests to
45
+ reuse state keyed by the same identifier.
46
+ - Writes the active session id to `request.state.session_id` and mirrors it in
47
+ the `session_id` response cookie (customisable through `session_cookie`).
48
+ - Uses a configurable `max_age` to control the lifetime of the emitted cookie.
49
+
50
+ ### Why This Package
51
+
52
+ `swarmauri_middleware_session` isolates this responsibility: Session middleware for maintaining session state across requests. Its [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/swarmauri_middleware_session/__init__.py) exposes `SessionMiddleware`, allowing consumers to select this package without treating adjacent packages as part of its public contract.
53
+
54
+ ### When to Use
55
+
56
+ Choose `swarmauri_middleware_session` when your integration needs session middleware for maintaining session state across requests. Match the imports below to your application boundary and install its declared dependencies before using the example.
57
+
58
+ ### Features
59
+
60
+ - `SessionMiddleware`: Session middleware for maintaining session state across requests.
61
+
62
+ ### Non-Goals
63
+
64
+ `swarmauri_middleware_session` owns session middleware for maintaining session state across requests. 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.
65
+
66
+ ---
67
+
68
+ ## Getting Started
69
+
70
+ ### Prerequisites
71
+
72
+ Python `>=3.10,<3.15` is required. The [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/pyproject.toml) declares runtime dependencies including `starlette`, `swarmauri-core`, `swarmauri-base`, `swarmauri-standard`. Read the example’s inputs and service requirements before execution.
73
+
74
+ ### Installation
75
+
76
+ Install from PyPI using the toolchain that fits your workflow.
77
+
78
+ #### uv
79
+
80
+ <!-- readme-standards:begin installation.uv -->
81
+ ```bash
82
+ uv add swarmauri_middleware_session
83
+ ```
84
+ <!-- readme-standards:end installation.uv -->
85
+
86
+ ```bash
87
+ uv venv
88
+ source .venv/bin/activate
89
+ uv pip install swarmauri_middleware_session
90
+ ```
91
+
92
+ #### pip
93
+
94
+ <!-- readme-standards:begin installation.pip -->
95
+ ```bash
96
+ python -m pip install swarmauri_middleware_session
97
+ ```
98
+ <!-- readme-standards:end installation.pip -->
99
+
100
+ ```bash
101
+ pip install swarmauri_middleware_session
102
+ ```
103
+
104
+ #### Poetry
105
+
106
+ <!-- readme-standards:begin installation.poetry -->
107
+ ```bash
108
+ poetry add swarmauri_middleware_session
109
+ ```
110
+ <!-- readme-standards:end installation.poetry -->
111
+
112
+ ```bash
113
+ poetry add swarmauri_middleware_session
114
+ ```
115
+
116
+ ### Quick Start
117
+
118
+ #### Example
119
+
120
+ <!-- readme-standards:begin example.quick-start -->
121
+ Source: [docs/readme/quick_start.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/docs/readme/quick_start.py).
122
+
123
+ ```python
124
+ from starlette.applications import Starlette
125
+ from starlette.middleware.base import BaseHTTPMiddleware
126
+ from starlette.requests import Request
127
+ from starlette.responses import JSONResponse
128
+ from starlette.testclient import TestClient
129
+
130
+ from swarmauri_middleware_session import SessionMiddleware
131
+
132
+
133
+ app = Starlette()
134
+ session_middleware = SessionMiddleware()
135
+
136
+
137
+ async def attach_session(request: Request, call_next):
138
+ return await session_middleware.dispatch(request, call_next)
139
+
140
+
141
+ app.add_middleware(BaseHTTPMiddleware, dispatch=attach_session)
142
+
143
+
144
+ async def greet(request: Request):
145
+ session_id = request.state.session_id
146
+ session_data = session_middleware.session_storage.setdefault(
147
+ session_id, {}
148
+ )
149
+ session_data["visits"] = session_data.get("visits", 0) + 1
150
+ return JSONResponse(
151
+ {"session_id": session_id, "visits": session_data["visits"]}
152
+ )
153
+
154
+
155
+ app.add_route("/greet", greet)
156
+
157
+ client = TestClient(app)
158
+
159
+ first_response = client.get("/greet")
160
+ first_data = first_response.json()
161
+
162
+ second_response = client.get(
163
+ "/greet", headers={"X-Session-ID": first_response.headers["X-Session-ID"]}
164
+ )
165
+ second_data = second_response.json()
166
+
167
+ print(first_data)
168
+ print(second_data)
169
+ ```
170
+ <!-- readme-standards:end example.quick-start -->
171
+
172
+ Running the example prints the initial visit count followed by an incremented
173
+ visit count for the same session, demonstrating how the middleware keeps track
174
+ of state across requests.
175
+
176
+ #### Expected Result
177
+
178
+ The example demonstrates the documented `swarmauri_middleware_session` 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.
179
+
180
+ ---
181
+
182
+ ## Usage
183
+
184
+ ### Common Workflows
185
+
186
+ <!-- readme-standards:begin example.usage -->
187
+ Source: [docs/readme/usage.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/docs/readme/usage.py).
188
+
189
+ ```python
190
+ from starlette.applications import Starlette
191
+ from starlette.middleware.base import BaseHTTPMiddleware
192
+ from starlette.requests import Request
193
+ from starlette.responses import JSONResponse
194
+ from starlette.testclient import TestClient
195
+
196
+ from swarmauri_middleware_session import SessionMiddleware
197
+
198
+
199
+ app = Starlette()
200
+ session_middleware = SessionMiddleware()
201
+
202
+
203
+ async def attach_session(request: Request, call_next):
204
+ return await session_middleware.dispatch(request, call_next)
205
+
206
+
207
+ app.add_middleware(BaseHTTPMiddleware, dispatch=attach_session)
208
+
209
+
210
+ async def greet(request: Request):
211
+ session_id = request.state.session_id
212
+ session_data = session_middleware.session_storage.setdefault(
213
+ session_id, {}
214
+ )
215
+ session_data["visits"] = session_data.get("visits", 0) + 1
216
+ return JSONResponse(
217
+ {"session_id": session_id, "visits": session_data["visits"]}
218
+ )
219
+
220
+
221
+ app.add_route("/greet", greet)
222
+
223
+ client = TestClient(app)
224
+
225
+ first_response = client.get("/greet")
226
+ first_data = first_response.json()
227
+
228
+ second_response = client.get(
229
+ "/greet", headers={"X-Session-ID": first_response.headers["X-Session-ID"]}
230
+ )
231
+ second_data = second_response.json()
232
+
233
+ print(first_data)
234
+ print(second_data)
235
+ ```
236
+ <!-- readme-standards:end example.usage -->
237
+
238
+ ### Configuration
239
+
240
+ Configure `swarmauri_middleware_session` through the APIs in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/swarmauri_middleware_session/__init__.py); its [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/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_session` source does not establish a package-wide exception hierarchy. Preserve errors from its declared dependencies and validate inputs using the specific public contract in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/swarmauri_middleware_session/__init__.py).
245
+
246
+ ### Best Practices
247
+
248
+ Use the explicit `swarmauri_middleware_session` imports documented below and keep collaborator configuration with the caller. Run the package’s relevant tests after changing `SessionMiddleware`; 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_session` is located in `standards` and owns session middleware for maintaining session state across requests. Source-declared APIs include `SessionMiddleware`. The [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/pyproject.toml) records its direct dependency boundary.
257
+
258
+ ### Public API and Import Surfaces
259
+
260
+ Import namespace: `swarmauri_middleware_session`.
261
+
262
+ Source-declared exports or types: `SessionMiddleware`.
263
+
264
+ Inspect [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/swarmauri_middleware_session/__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` → `SessionMiddleware` → `swarmauri_middleware_session:SessionMiddleware`
270
+ <!-- readme-standards:end entry-points -->
271
+
272
+ ### Injected Dependencies
273
+
274
+ The direct installation dependencies of `swarmauri_middleware_session` 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_session/swarmauri_middleware_session/__init__.py).
275
+
276
+ ### Protocol Consumers
277
+
278
+ No direct package-manifest dependency on `swarmauri_middleware_session` 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_session`, use the source-declared public interfaces (`SessionMiddleware`) 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_session` 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_session/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_session`. 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_session/swarmauri_middleware_session/__init__.py). The `swarmauri_middleware_session` 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_session` 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_session` 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_session/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_session/tests/i9n/test_i9n__init__.py)
314
+ - [tests/unit/test_SessionMiddleware.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/tests/unit/test_SessionMiddleware.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_session` 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_session/swarmauri_middleware_session/__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_session` provides session middleware for maintaining session state across requests; 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_session`, and consult [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/swarmauri_middleware_session/__init__.py) for the exact types and signatures involved.
337
+
338
+ ### When
339
+
340
+ **When should I validate an upgrade?** Recheck `swarmauri_middleware_session` 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_session/swarmauri_middleware_session/__init__.py), and [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/pyproject.toml) provide the supporting context for `swarmauri_middleware_session`. 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_session](https://pypi.org/project/swarmauri_middleware_session/)
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_session` 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_session` 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_session` 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_session/pyproject.toml); this README does not assign new publishing or administrative authority.
385
+
386
+ ### Standards and Policies
387
+
388
+ `swarmauri_middleware_session` 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_session` 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_session/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_session/NOTICE) for attribution.
408
+ <!-- readme-standards:end notices -->
@@ -1,26 +1,26 @@
1
1
  [project]
2
2
  name = "swarmauri_middleware_session"
3
- version = "0.8.0.dev48"
3
+ version = "0.11.0"
4
4
  description = "Session middleware for maintaining session state across requests."
5
5
  license = "Apache-2.0"
6
6
  readme = "README.md"
7
7
  repository = "http://github.com/swarmauri/swarmauri-sdk/pkgs/pkgs/swarmauri_middleware_session/"
8
- requires-python = ">=3.10,<3.13"
8
+ requires-python = ">=3.10,<3.15"
9
9
  classifiers = [
10
- "License :: OSI Approved :: Apache Software License",
11
10
  "Natural Language :: English",
11
+ "Development Status :: 3 - Alpha",
12
+ "Programming Language :: Python",
13
+ "Programming Language :: Python :: 3",
14
+ "Programming Language :: Python :: 3 :: Only",
12
15
  "Programming Language :: Python :: 3.10",
13
16
  "Programming Language :: Python :: 3.11",
14
17
  "Programming Language :: Python :: 3.12",
15
18
  "Programming Language :: Python :: 3.13",
16
- "Development Status :: 3 - Alpha",
17
- "Programming Language :: Python",
18
- "Programming Language :: Python :: 3",
19
- "Programming Language :: Python :: 3 :: Only"
19
+ "Programming Language :: Python :: 3.14",
20
20
  ]
21
21
  authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
22
22
  dependencies = [
23
- "fastapi",
23
+ "starlette",
24
24
  "swarmauri_core",
25
25
  "swarmauri_base",
26
26
  "swarmauri_standard",
@@ -32,6 +32,7 @@ keywords = [
32
32
  'middleware',
33
33
  'session',
34
34
  ]
35
+ license-files = ["LICENSE", "NOTICE"]
35
36
 
36
37
  [tool.uv.sources]
37
38
  swarmauri_core = { workspace = true }
@@ -59,6 +60,54 @@ log_cli_format = "%(asctime)s [%(levelname)s] %(message)s"
59
60
  log_cli_date_format = "%Y-%m-%d %H:%M:%S"
60
61
  asyncio_default_fixture_loop_scope = "function"
61
62
 
63
+ [tool.readme_standards]
64
+ policy = "package-guide-v1"
65
+ readme = "README.md"
66
+ brand = "swarmauri"
67
+ brand_catalog = "../../../tools/readme/brands.toml"
68
+ repository = "https://github.com/swarmauri/swarmauri-sdk"
69
+ ref = "master"
70
+ package_path = "pkgs/40-standards/swarmauri_middleware_session"
71
+ layer = "standards"
72
+ lifecycle = "active"
73
+ license_file = "LICENSE"
74
+ notice_file = "NOTICE"
75
+
76
+ [tool.readme_standards.distributions.pypi]
77
+ name = "swarmauri_middleware_session"
78
+ published = true
79
+
80
+ [tool.readme_standards.examples.quick_start]
81
+ source = "docs/readme/quick_start.py"
82
+ test = "tests/unit/test_readme_sources.py"
83
+ language = "python"
84
+ expected_exit_code = 0
85
+
86
+ [tool.readme_standards.examples.usage]
87
+ source = "docs/readme/usage.py"
88
+ test = "tests/unit/test_readme_sources.py"
89
+ language = "python"
90
+ expected_exit_code = 0
91
+
92
+ [tool.readme_standards.statuses.readme]
93
+ label = "CI gate"
94
+ url = "https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"
95
+
96
+ [tool.readme_standards.statuses.tests]
97
+ label = "example source"
98
+ url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/tests/unit/test_readme_sources.py"
99
+
100
+ [tool.readme_standards.statuses.certification]
101
+ label = "not certified"
102
+ url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_middleware_session/README.md#certification-status"
103
+
104
+ [tool.readme_standards.statuses.governance]
105
+ label = "repository policy"
106
+ url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md"
107
+
108
+ [tool.readme_standards.statuses.evidence]
109
+ label = "source and CI"
110
+ url = "https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"
62
111
  [build-system]
63
112
  requires = ["poetry-core>=1.0.0"]
64
113
  build-backend = "poetry.core.masonry.api"
@@ -70,11 +119,12 @@ dev = [
70
119
  "pytest-xdist>=3.6.1",
71
120
  "pytest-json-report>=1.5.0",
72
121
  "python-dotenv",
73
- "requests>=2.32.3",
122
+ "httpx>=0.27",
74
123
  "flake8>=7.0",
75
124
  "pytest-timeout>=2.3.1",
76
125
  "ruff>=0.9.9",
77
126
  "pytest-benchmark>=4.0.0",
127
+ "readme-standards==0.1.3; python_version >= \"3.11\"",
78
128
  ]
79
129
 
80
130
  [project.entry-points.'swarmauri.middlewares']
@@ -1,7 +1,7 @@
1
1
  import logging
2
2
  from typing import Any, Callable, Dict, Optional
3
3
 
4
- from fastapi import Request
4
+ from starlette.requests import Request
5
5
  from swarmauri_base.ComponentBase import ComponentBase
6
6
  from swarmauri_base.middlewares.MiddlewareBase import MiddlewareBase
7
7
 
@@ -20,7 +20,8 @@ class SessionMiddleware(MiddlewareBase, ComponentBase):
20
20
  session_storage: Dict[str, Dict] = {} # Storage for session data
21
21
  session_header: str = "X-Session-ID" # Header name for session ID
22
22
  session_cookie: str = "session_id" # Cookie name for session ID
23
- max_age: int = 3600 # Default session expiration in seconds
23
+ max_age: int = 3600 # Default session expiration in
24
+ seconds
24
25
 
25
26
  Methods:
26
27
  dispatch: Implements the core middleware dispatch logic
@@ -40,7 +41,9 @@ class SessionMiddleware(MiddlewareBase, ComponentBase):
40
41
  **kwargs: Any,
41
42
  ) -> None:
42
43
  super().__init__(**kwargs)
43
- self.session_storage = session_storage if session_storage is not None else {}
44
+ self.session_storage = (
45
+ session_storage if session_storage is not None else {}
46
+ )
44
47
  self.session_header = session_header or "X-Session-ID"
45
48
  self.session_cookie = session_cookie or "session_id"
46
49
  self.max_age = max_age
@@ -48,10 +51,14 @@ class SessionMiddleware(MiddlewareBase, ComponentBase):
48
51
  async def dispatch(
49
52
  self, request: Request, call_next: Callable[[Request], Any]
50
53
  ) -> Any:
51
- """Dispatches the request to the next middleware in the chain while maintaining session state.
54
+ """
55
+ Dispatches the request to the next middleware in the chain while
56
+ maintaining session state.
52
57
 
53
- This method processes the request to check for an existing session or create a new one.
54
- It ensures that session state is maintained across requests by setting appropriate
58
+ This method processes the request to check for an existing session or
59
+ create a new one.
60
+ It ensures that session state is maintained across requests by setting
61
+ appropriate
55
62
  headers or cookies.
56
63
 
57
64
  Args:
@@ -71,7 +78,10 @@ class SessionMiddleware(MiddlewareBase, ComponentBase):
71
78
  # Session exists - update session storage
72
79
  if session_id not in self.session_storage:
73
80
  logger.warning(
74
- f"Session ID {session_id} exists in header but not in storage"
81
+ (
82
+ f"Session ID {session_id} exists in header but not in "
83
+ f"storage"
84
+ )
75
85
  )
76
86
  # Create new session data
77
87
  self.session_storage[session_id] = {}
@@ -105,7 +115,8 @@ class SessionMiddleware(MiddlewareBase, ComponentBase):
105
115
  """Generates a unique session ID.
106
116
 
107
117
  This method creates a new unique identifier for the session. You
108
- can override this method to implement custom session ID generation logic.
118
+ can override this method to implement custom session ID generation
119
+ logic.
109
120
 
110
121
  Returns:
111
122
  A unique session ID as a string
@@ -1,139 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: swarmauri_middleware_session
3
- Version: 0.8.0.dev48
4
- Summary: Session middleware for maintaining session state across requests.
5
- License-Expression: Apache-2.0
6
- License-File: LICENSE
7
- Keywords: swarmauri,sdk,standards,middleware,session
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
- ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
28
-
29
- <p align="center">
30
- <a href="https://pypi.org/project/swarmauri_middleware_session/">
31
- <img src="https://img.shields.io/pypi/dm/swarmauri_middleware_session" alt="PyPI - Downloads"/>
32
- </a>
33
- <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_session/">
34
- <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_session.svg"/>
35
- </a>
36
- <a href="https://pypi.org/project/swarmauri_middleware_session/">
37
- <img src="https://img.shields.io/pypi/pyversions/swarmauri_middleware_session" alt="PyPI - Python Version"/>
38
- </a>
39
- <a href="https://pypi.org/project/swarmauri_middleware_session/">
40
- <img src="https://img.shields.io/pypi/l/swarmauri_middleware_session" alt="PyPI - License"/>
41
- </a>
42
- <a href="https://pypi.org/project/swarmauri_middleware_session/">
43
- <img src="https://img.shields.io/pypi/v/swarmauri_middleware_session?label=swarmauri_middleware_session&color=green" alt="PyPI - swarmauri_middleware_session"/>
44
- </a>
45
- </p>
46
-
47
- ---
48
-
49
- # Swarmauri Middleware Session
50
-
51
- Session middleware for FastAPI and Starlette style applications that keeps a
52
- lightweight, in-memory session store synchronized with every request and
53
- response.
54
-
55
- ## Overview
56
-
57
- - Accepts an incoming session identifier from the `X-Session-ID` request header
58
- (customisable through `session_header`).
59
- - Falls back to generating a new UUID session identifier and persists it on the
60
- response when none is supplied.
61
- - Stores per-session data in `session_storage`, allowing subsequent requests to
62
- reuse state keyed by the same identifier.
63
- - Writes the active session id to `request.state.session_id` and mirrors it in
64
- the `session_id` response cookie (customisable through `session_cookie`).
65
- - Uses a configurable `max_age` to control the lifetime of the emitted cookie.
66
-
67
- ## Installation
68
-
69
- Install from PyPI using the toolchain that fits your workflow.
70
-
71
- ### pip
72
-
73
- ```bash
74
- pip install swarmauri_middleware_session
75
- ```
76
-
77
- ### Poetry
78
-
79
- ```bash
80
- poetry add swarmauri_middleware_session
81
- ```
82
-
83
- ### uv
84
-
85
- ```bash
86
- uv venv
87
- source .venv/bin/activate
88
- uv pip install swarmauri_middleware_session
89
- ```
90
-
91
- ## Example
92
-
93
- ```python
94
- from fastapi import FastAPI, Request
95
- from fastapi.responses import JSONResponse
96
- from fastapi.testclient import TestClient
97
-
98
- from swarmauri_middleware_session import SessionMiddleware
99
-
100
-
101
- app = FastAPI()
102
- session_middleware = SessionMiddleware()
103
-
104
-
105
- @app.middleware("http")
106
- async def attach_session(request: Request, call_next):
107
- return await session_middleware.dispatch(request, call_next)
108
-
109
-
110
- @app.get("/greet")
111
- async def greet(request: Request):
112
- session_id = request.state.session_id
113
- session_data = session_middleware.session_storage.setdefault(session_id, {})
114
- session_data["visits"] = session_data.get("visits", 0) + 1
115
- return JSONResponse({"session_id": session_id, "visits": session_data["visits"]})
116
-
117
-
118
- client = TestClient(app)
119
-
120
- first_response = client.get("/greet")
121
- first_data = first_response.json()
122
-
123
- second_response = client.get(
124
- "/greet", headers={"X-Session-ID": first_response.headers["X-Session-ID"]}
125
- )
126
- second_data = second_response.json()
127
-
128
- print(first_data)
129
- print(second_data)
130
- ```
131
-
132
- Running the example prints the initial visit count followed by an incremented
133
- visit count for the same session, demonstrating how the middleware keeps track
134
- of state across requests.
135
-
136
- ## Want to help?
137
-
138
- 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.
139
-
@@ -1,112 +0,0 @@
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_session/">
5
- <img src="https://img.shields.io/pypi/dm/swarmauri_middleware_session" alt="PyPI - Downloads"/>
6
- </a>
7
- <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_session/">
8
- <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_session.svg"/>
9
- </a>
10
- <a href="https://pypi.org/project/swarmauri_middleware_session/">
11
- <img src="https://img.shields.io/pypi/pyversions/swarmauri_middleware_session" alt="PyPI - Python Version"/>
12
- </a>
13
- <a href="https://pypi.org/project/swarmauri_middleware_session/">
14
- <img src="https://img.shields.io/pypi/l/swarmauri_middleware_session" alt="PyPI - License"/>
15
- </a>
16
- <a href="https://pypi.org/project/swarmauri_middleware_session/">
17
- <img src="https://img.shields.io/pypi/v/swarmauri_middleware_session?label=swarmauri_middleware_session&color=green" alt="PyPI - swarmauri_middleware_session"/>
18
- </a>
19
- </p>
20
-
21
- ---
22
-
23
- # Swarmauri Middleware Session
24
-
25
- Session middleware for FastAPI and Starlette style applications that keeps a
26
- lightweight, in-memory session store synchronized with every request and
27
- response.
28
-
29
- ## Overview
30
-
31
- - Accepts an incoming session identifier from the `X-Session-ID` request header
32
- (customisable through `session_header`).
33
- - Falls back to generating a new UUID session identifier and persists it on the
34
- response when none is supplied.
35
- - Stores per-session data in `session_storage`, allowing subsequent requests to
36
- reuse state keyed by the same identifier.
37
- - Writes the active session id to `request.state.session_id` and mirrors it in
38
- the `session_id` response cookie (customisable through `session_cookie`).
39
- - Uses a configurable `max_age` to control the lifetime of the emitted cookie.
40
-
41
- ## Installation
42
-
43
- Install from PyPI using the toolchain that fits your workflow.
44
-
45
- ### pip
46
-
47
- ```bash
48
- pip install swarmauri_middleware_session
49
- ```
50
-
51
- ### Poetry
52
-
53
- ```bash
54
- poetry add swarmauri_middleware_session
55
- ```
56
-
57
- ### uv
58
-
59
- ```bash
60
- uv venv
61
- source .venv/bin/activate
62
- uv pip install swarmauri_middleware_session
63
- ```
64
-
65
- ## Example
66
-
67
- ```python
68
- from fastapi import FastAPI, Request
69
- from fastapi.responses import JSONResponse
70
- from fastapi.testclient import TestClient
71
-
72
- from swarmauri_middleware_session import SessionMiddleware
73
-
74
-
75
- app = FastAPI()
76
- session_middleware = SessionMiddleware()
77
-
78
-
79
- @app.middleware("http")
80
- async def attach_session(request: Request, call_next):
81
- return await session_middleware.dispatch(request, call_next)
82
-
83
-
84
- @app.get("/greet")
85
- async def greet(request: Request):
86
- session_id = request.state.session_id
87
- session_data = session_middleware.session_storage.setdefault(session_id, {})
88
- session_data["visits"] = session_data.get("visits", 0) + 1
89
- return JSONResponse({"session_id": session_id, "visits": session_data["visits"]})
90
-
91
-
92
- client = TestClient(app)
93
-
94
- first_response = client.get("/greet")
95
- first_data = first_response.json()
96
-
97
- second_response = client.get(
98
- "/greet", headers={"X-Session-ID": first_response.headers["X-Session-ID"]}
99
- )
100
- second_data = second_response.json()
101
-
102
- print(first_data)
103
- print(second_data)
104
- ```
105
-
106
- Running the example prints the initial visit count followed by an incremented
107
- visit count for the same session, demonstrating how the middleware keeps track
108
- of state across requests.
109
-
110
- ## Want to help?
111
-
112
- 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.