qstd-openapi 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,324 @@
1
+ Metadata-Version: 2.4
2
+ Name: qstd-openapi
3
+ Version: 0.1.0
4
+ Summary: A framework-agnostic, declarative OpenAPI 3.1/3.0 generator: decorators, error classes, webhooks and document aggregation, with Pydantic and Sanic integrations (FastAPI and Pydantic 1 — experimental).
5
+ Author-email: QuisEgoSum <subbotin.evdokim@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/QuisEgoSum/qstd-openapi
8
+ Project-URL: Repository, https://github.com/QuisEgoSum/qstd-openapi
9
+ Project-URL: Changelog, https://github.com/QuisEgoSum/qstd-openapi/blob/main/CHANGELOG.md
10
+ Project-URL: Documentation, https://github.com/QuisEgoSum/qstd-openapi/tree/main/docs
11
+ Keywords: openapi,swagger,redoc,pydantic,sanic,fastapi,documentation
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Topic :: Software Development :: Documentation
15
+ Classifier: Framework :: Pydantic :: 2
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Operating System :: OS Independent
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.9
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: typing_extensions>=4.7
28
+ Provides-Extra: pydantic
29
+ Requires-Dist: pydantic<3,>=2.6; extra == "pydantic"
30
+ Provides-Extra: pydantic-v1
31
+ Requires-Dist: pydantic<2,>=1.10; extra == "pydantic-v1"
32
+ Provides-Extra: validate
33
+ Requires-Dist: openapi-spec-validator>=0.7; extra == "validate"
34
+ Provides-Extra: sanic
35
+ Requires-Dist: sanic>=23.12; extra == "sanic"
36
+ Provides-Extra: fastapi
37
+ Requires-Dist: fastapi>=0.110; extra == "fastapi"
38
+ Provides-Extra: yaml
39
+ Requires-Dist: PyYAML>=6; extra == "yaml"
40
+ Provides-Extra: all
41
+ Requires-Dist: pydantic<3,>=2.6; extra == "all"
42
+ Requires-Dist: openapi-spec-validator>=0.7; extra == "all"
43
+ Requires-Dist: sanic>=23.12; extra == "all"
44
+ Requires-Dist: fastapi>=0.110; extra == "all"
45
+ Requires-Dist: PyYAML>=6; extra == "all"
46
+ Provides-Extra: dev
47
+ Requires-Dist: pydantic<3,>=2.6; extra == "dev"
48
+ Requires-Dist: openapi-spec-validator>=0.7; extra == "dev"
49
+ Requires-Dist: sanic>=23.12; extra == "dev"
50
+ Requires-Dist: sanic-testing>=23.12; extra == "dev"
51
+ Requires-Dist: fastapi>=0.110; extra == "dev"
52
+ Requires-Dist: httpx>=0.24; extra == "dev"
53
+ Requires-Dist: PyYAML>=6; extra == "dev"
54
+ Requires-Dist: pytest<9.0,>=8.0; extra == "dev"
55
+ Requires-Dist: tox>=4.26.0; extra == "dev"
56
+ Requires-Dist: pytest-cov<7.0,>=6.0; extra == "dev"
57
+ Requires-Dist: ruff>=0.11.2; extra == "dev"
58
+ Requires-Dist: black>=25.1.0; extra == "dev"
59
+ Requires-Dist: build>=1.2.2; extra == "dev"
60
+ Requires-Dist: twine>=6.1.0; extra == "dev"
61
+ Requires-Dist: pyright>=1.1.402; extra == "dev"
62
+ Requires-Dist: mypy<2,>=1.16; extra == "dev"
63
+ Dynamic: license-file
64
+
65
+ # qstd-openapi
66
+
67
+ Build OpenAPI 3.1 or 3.0 documents from Python code without tying the
68
+ description to one web framework.
69
+
70
+ `qstd-openapi` lets handlers, validators, authentication decorators and other
71
+ layers describe the part of an operation they own. It combines those pieces,
72
+ turns Python types into schemas, reports conflicting descriptions and can
73
+ publish or snapshot the resulting document.
74
+
75
+ The primary integration is Sanic. FastAPI support is experimental.
76
+
77
+ ## Why qstd-openapi
78
+
79
+ - Keep API documentation next to the code that implements each concern.
80
+ - Describe application exceptions as reusable error responses.
81
+ - Use Pydantic models, dataclasses, Python types or raw JSON Schema.
82
+ - Build several documents from the same application with scope filters.
83
+ - Generate stable JSON or YAML for review and CI.
84
+ - Combine existing service documents with path prefixes and component
85
+ namespaces.
86
+ - Produce OpenAPI 3.1 and 3.0.3 from the same description.
87
+
88
+ Metadata is stored on the decorated functions, not in a global registry.
89
+ Creating two `OpenAPI` instances in one process does not mix their state.
90
+
91
+ ## Installation
92
+
93
+ Choose the extras needed by your application:
94
+
95
+ ```bash
96
+ # Sanic with Pydantic schemas and YAML output
97
+ pip install "qstd-openapi[pydantic,sanic,yaml]"
98
+
99
+ # FastAPI integration (experimental)
100
+ pip install "qstd-openapi[pydantic,fastapi]"
101
+
102
+ # Framework-independent document builder
103
+ pip install "qstd-openapi[pydantic]"
104
+ ```
105
+
106
+ Other extras:
107
+
108
+ | Extra | Enables |
109
+ |---|---|
110
+ | `pydantic` | Pydantic 2 models, dataclasses and annotated types |
111
+ | `pydantic-v1` | Pydantic 1.10 support; experimental and incompatible with `pydantic` |
112
+ | `validate` | Validation through `openapi-spec-validator` |
113
+ | `sanic` | Sanic route discovery and documentation endpoints |
114
+ | `fastapi` | FastAPI document augmentation; experimental |
115
+ | `yaml` | YAML input and output |
116
+ | `all` | Every extra except `pydantic-v1` |
117
+
118
+ Python 3.9–3.13 is supported. The base package depends only on
119
+ `typing_extensions`.
120
+
121
+ ## Quick start with Sanic
122
+
123
+ Save this as `app.py`:
124
+
125
+ ```python
126
+ from datetime import datetime, timezone
127
+
128
+ from pydantic import BaseModel, Field
129
+ from sanic import Blueprint, Request, Sanic, response
130
+
131
+ from qstd_openapi import OpenAPI
132
+ from qstd_openapi.sanic import OpenAPIBlueprint, SanicRoutes, mount
133
+ from qstd_openapi.ui import Redoc
134
+
135
+
136
+ class UserRegisterInput(BaseModel):
137
+ email: str
138
+ password: str = Field(min_length=8)
139
+
140
+
141
+ class UserDTO(BaseModel):
142
+ id: int
143
+ email: str
144
+ created_at: datetime
145
+
146
+
147
+ users = OpenAPIBlueprint(Blueprint('Users', url_prefix='/users'))
148
+
149
+
150
+ @users.post(
151
+ '/register',
152
+ tags=['Users'],
153
+ body=UserRegisterInput,
154
+ responses={201: UserDTO},
155
+ )
156
+ async def register_user(request: Request):
157
+ """Register a user."""
158
+ payload = UserRegisterInput.model_validate(request.json)
159
+ user = UserDTO(
160
+ id=1,
161
+ email=payload.email,
162
+ created_at=datetime.now(timezone.utc),
163
+ )
164
+ return response.json(user.model_dump(mode='json'), status=201)
165
+
166
+
167
+ app = Sanic('users_api')
168
+ app.blueprint(users.blueprint)
169
+
170
+ spec = OpenAPI(info={'title': 'Users API', 'version': '1.0.0'})
171
+ spec.include(SanicRoutes(app))
172
+ mount(
173
+ app,
174
+ spec,
175
+ json_path='/openapi.json',
176
+ ui={'/docs': Redoc()},
177
+ )
178
+ ```
179
+
180
+ Run it:
181
+
182
+ ```bash
183
+ sanic app:app --dev
184
+ ```
185
+
186
+ Open `http://127.0.0.1:8000/docs`. The document contains the request and
187
+ response schemas, the docstring summary and an automatically generated
188
+ `operationId`.
189
+
190
+ `OpenAPIBlueprint` accepts Sanic route options and documentation options in
191
+ the same call. If you prefer ordinary framework decorators, the equivalent
192
+ description can be written separately:
193
+
194
+ ```python
195
+ from sanic import Blueprint
196
+
197
+ from qstd_openapi import openapi
198
+
199
+ users_blueprint = Blueprint('Users', url_prefix='/users')
200
+
201
+
202
+ @users_blueprint.post('/register')
203
+ @openapi.describe(
204
+ tags=['Users'],
205
+ body=UserRegisterInput,
206
+ responses={201: UserDTO},
207
+ )
208
+ async def register_user(request):
209
+ ...
210
+ ```
211
+
212
+ ## Documentation can come from any layer
213
+
214
+ A project decorator can declare the security and errors it adds. The handler
215
+ does not need to repeat them:
216
+
217
+ ```python
218
+ import functools
219
+
220
+ from qstd_openapi import openapi
221
+
222
+
223
+ def require_session(func):
224
+ @functools.wraps(func)
225
+ async def wrapper(request, *args, **kwargs):
226
+ # Authenticate the request or raise UnauthorizedError.
227
+ return await func(request, *args, **kwargs)
228
+
229
+ return openapi.attach(
230
+ wrapper,
231
+ security='UserSession',
232
+ errors=[UnauthorizedError],
233
+ )
234
+ ```
235
+
236
+ Metadata is collected through `functools.wraps` chains. Conflicting scalar
237
+ values, duplicate operations, schemas or `operationId` values fail the build
238
+ with both sources named in the error.
239
+
240
+ ## Keep the document in CI
241
+
242
+ Export a stable, reviewable snapshot:
243
+
244
+ ```bash
245
+ python -m qstd_openapi dump users_api.openapi:build_spec \
246
+ -o docs/openapi.json
247
+
248
+ python -m qstd_openapi dump users_api.openapi:build_spec \
249
+ -o docs/openapi.json --check
250
+ ```
251
+
252
+ The target may be an `OpenAPI` instance or a zero-argument factory. A pytest
253
+ helper is also available:
254
+
255
+ ```python
256
+ from qstd_openapi.testing import assert_matches_snapshot
257
+
258
+
259
+ def test_openapi_document() -> None:
260
+ assert_matches_snapshot(build_spec(), 'docs/openapi.json')
261
+ ```
262
+
263
+ Set `QSTD_OPENAPI_UPDATE_SNAPSHOTS=1` to accept an intentional change.
264
+
265
+ ## Documentation
266
+
267
+ - [Getting started][getting-started] — how descriptions become a
268
+ document and which integration to choose.
269
+ - [Describing operations][describing-operations] — decorators,
270
+ `describe()`, parameters, responses, examples and `operationId`.
271
+ - [Schemas and errors][schemas-and-errors] — Pydantic, raw schemas,
272
+ serializer overrides and application error classes.
273
+ - [Sanic integration][sanic] — route discovery, router wrapper and
274
+ documentation endpoints.
275
+ - [FastAPI integration][fastapi] — experimental augment mode and its
276
+ merge rules.
277
+ - [Webhooks and scopes][webhooks-and-scopes] — outbound operations and
278
+ several documents from one application.
279
+ - [Document aggregation][aggregation] — combining existing OpenAPI
280
+ files and rewriting references.
281
+ - [Output and CI][output-and-ci] — JSON/YAML, validation, snapshots and
282
+ OpenAPI 3.0 output.
283
+
284
+ ## Examples
285
+
286
+ The [examples index][examples] contains commands and expected
287
+ results for:
288
+
289
+ - a minimal, single-file Sanic application;
290
+ - a small Sanic service with errors, authentication and a webhook;
291
+ - FastAPI document augmentation;
292
+ - a gateway document assembled from two YAML service documents.
293
+
294
+ Examples return payloads that match their documented schemas and are exercised
295
+ through HTTP clients by the test suite.
296
+
297
+ ## Support status
298
+
299
+ | Area | Status |
300
+ |---|---|
301
+ | OpenAPI 3.1 and 3.0.3 | Supported |
302
+ | Sanic ≥ 23.12 | Supported |
303
+ | Pydantic ≥ 2.6 | Supported |
304
+ | FastAPI ≥ 0.110 | Experimental |
305
+ | Pydantic 1.10 | Experimental; planned for removal |
306
+
307
+ Experimental integrations are covered by automated tests but have not yet
308
+ been verified in a production application. Their behavior may change in a
309
+ minor release before 1.0.
310
+
311
+ ## License
312
+
313
+ MIT, see [LICENSE][license].
314
+
315
+ [aggregation]: https://github.com/QuisEgoSum/qstd-openapi/blob/main/docs/aggregation.md
316
+ [describing-operations]: https://github.com/QuisEgoSum/qstd-openapi/blob/main/docs/describing-operations.md
317
+ [examples]: https://github.com/QuisEgoSum/qstd-openapi/blob/main/examples/README.md
318
+ [fastapi]: https://github.com/QuisEgoSum/qstd-openapi/blob/main/docs/fastapi.md
319
+ [getting-started]: https://github.com/QuisEgoSum/qstd-openapi/blob/main/docs/getting-started.md
320
+ [license]: https://github.com/QuisEgoSum/qstd-openapi/blob/main/LICENSE
321
+ [output-and-ci]: https://github.com/QuisEgoSum/qstd-openapi/blob/main/docs/output-and-ci.md
322
+ [sanic]: https://github.com/QuisEgoSum/qstd-openapi/blob/main/docs/sanic.md
323
+ [schemas-and-errors]: https://github.com/QuisEgoSum/qstd-openapi/blob/main/docs/schemas-and-errors.md
324
+ [webhooks-and-scopes]: https://github.com/QuisEgoSum/qstd-openapi/blob/main/docs/webhooks-and-scopes.md
@@ -0,0 +1,36 @@
1
+ qstd_openapi/__init__.py,sha256=f2aES5XDIBwT5b6KGChUL11kvvqS36Bh38n1jpfteik,1135
2
+ qstd_openapi/__main__.py,sha256=W6fpXkDesicA8LJaix_z18XdxcUrfzTmUyA4hzLW5m0,3756
3
+ qstd_openapi/_compat.py,sha256=AbIsuACsjnVJy68B22hH2K77FK_-oQVmU_Bsabx3g9o,478
4
+ qstd_openapi/errors.py,sha256=lBoNiitdGVRrrdWvlehin_40N3-LrSlN25XFy6MwuUU,3217
5
+ qstd_openapi/fastapi.py,sha256=66rLNFUwQkDEf5REurKkvcLri-EQO3zDsAByqS096hA,15919
6
+ qstd_openapi/markers.py,sha256=POA2O9c4rgbmOY0Y3qad7SP6PBkkC1KVgyLtUh8l7ag,1424
7
+ qstd_openapi/openapi.py,sha256=RNtQ2S1n4NDp3NEAbT2lRuhulyF8o6KdvIzS2CpvtQA,19779
8
+ qstd_openapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ qstd_openapi/pydantic.py,sha256=KdMBa7sFcJQvnVdZG9bnn9pmZaa_xaSYg7dPgpjhc5E,18212
10
+ qstd_openapi/sanic.py,sha256=u_le-thqJY9LuzNZgAXaG_S5VjfpGpDZI5i5bYnqYU4,12388
11
+ qstd_openapi/serialization.py,sha256=SDvYa_Bl6DYOWaKTz0mH7tuzZOoE7-PHFfr_fpFpPow,1775
12
+ qstd_openapi/tags.py,sha256=C8HU6l6aKkm7m954vg361wozkpens43MYUmSjdQANhU,1794
13
+ qstd_openapi/testing.py,sha256=9mvqIVtKbaUMPHyKqQmhkzfAN5q-35RGmVYDVgNO2u4,3560
14
+ qstd_openapi/ui.py,sha256=c8nts_KCaO3qKwVwkZDDXEMjRQ1VV8_o2waGKxH55Lk,3315
15
+ qstd_openapi/contrib/__init__.py,sha256=w0ag0IUzfavF3gK_BunSixFOIEwD-hC16JOZsmVPF3s,61
16
+ qstd_openapi/contrib/app_errors.py,sha256=7FgCDHxCyQrqo6QGu-K6MWpK5VZAsk-ISv4_kOoBOKA,6690
17
+ qstd_openapi/core/__init__.py,sha256=ovYhBNEzNOyLN4Za836mVSqOyLQO4upSNqY7z4I4aaQ,1187
18
+ qstd_openapi/core/document.py,sha256=9F8ypaB34jgB4FjsW5PPtEcIIpwi4ufO3L3wAzmNw5c,39499
19
+ qstd_openapi/core/documents.py,sha256=84o6IcUVZqYKdirhfscyJQg5qBpMxFWRNk50By2B9xc,11450
20
+ qstd_openapi/core/error_responses.py,sha256=Y85ihBVaTqv3zl04surlyOHUuTJ8LJO0q0nV8yECU60,3522
21
+ qstd_openapi/core/filters.py,sha256=d9F_w-Jh7zE30gRG8VcEVTb1B-eUbinhaB_ATodRiRc,2363
22
+ qstd_openapi/core/schemas.py,sha256=rJ9tqEBb5aVe-BVC3kVGKbBFJLp8DybC24tja51cWKE,19797
23
+ qstd_openapi/core/sources.py,sha256=SPeVi8ElTTVMOhroQXmOffWPJa6sQwUxBDBFX4Aw-qE,3204
24
+ qstd_openapi/dialects/__init__.py,sha256=wI1tk9Z2x6l66mJtdwkUMZO5_Xtq0Epb_a0zyhAN1kw,668
25
+ qstd_openapi/dialects/base.py,sha256=CGXz4RfYxoNJieRnptRDpMVB9-Uilm1afSIQOnhtfjk,1391
26
+ qstd_openapi/dialects/openapi30.py,sha256=xqdJdgrBkSYR2JUe8TXfQ683aHZg_p5nlOlx0OsGVQc,11261
27
+ qstd_openapi/dialects/openapi31.py,sha256=kYaM9NZ4YZFo_KOhzT6ewmFfvVTdVt-IBgWtIQsb5is,2647
28
+ qstd_openapi/meta/__init__.py,sha256=GSWy6avdkZ-6sK-bNMRVTldOebgx2Zc0KrYFGBNxcZE,1004
29
+ qstd_openapi/meta/merge.py,sha256=FDUeWgxBOj9rZFIYFshc8Jo5nDGZLr722Mlu40_-nMc,9016
30
+ qstd_openapi/meta/model.py,sha256=76VLgyTGzYZ2OgEwcwRiQW8CBEWmp-AZOWM99hD5NE0,4814
31
+ qstd_openapi/meta/storage.py,sha256=jTucStoEQZWHC2GEOmNICEJowUCOal51amViKsVSxxc,3905
32
+ qstd_openapi-0.1.0.dist-info/licenses/LICENSE,sha256=8ttfldrsfj9XFYhRVzqKSoiIaMO3GwANViNantIRxek,1067
33
+ qstd_openapi-0.1.0.dist-info/METADATA,sha256=PLnsvavjNqhfkjH82NGH1hf2dDU11MF5-WTUXjiLvVI,10863
34
+ qstd_openapi-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
35
+ qstd_openapi-0.1.0.dist-info/top_level.txt,sha256=xV8GAxXqA8Fk7hshFvJ_Mm9fuoT1NpzllaxcFy0QGmg,13
36
+ qstd_openapi-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 QuisEgoSum
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ qstd_openapi