rapidoc 0.1.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
+ .venv/
2
+ __pycache__/
3
+ *.egg-info/
4
+ dist/
5
+ .pytest_cache/
6
+ # One rapidoc release, copied in by scripts/sync_assets.py (build output of packages/rapidoc)
7
+ src/rapidoc/assets/
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Mrinmoy Majumdar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
rapidoc-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,82 @@
1
+ Metadata-Version: 2.5
2
+ Name: rapidoc
3
+ Version: 0.1.0
4
+ Summary: RapiDoc for Python web frameworks: serves an interactive OpenAPI reference (<rapi-doc>) from a FastAPI or Starlette app
5
+ Project-URL: Homepage, https://rapidocui.com
6
+ Project-URL: Repository, https://github.com/rapi-doc/RapiDoc
7
+ Project-URL: Issues, https://github.com/rapi-doc/RapiDoc/issues
8
+ Author-email: Mrinmoy Majumdar <mrin9@yahoo.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE.txt
11
+ Keywords: api documentation,fastapi,openapi,rapidoc,rapidoc-integration,starlette,swagger ui
12
+ Classifier: Framework :: FastAPI
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Software Development :: Documentation
15
+ Requires-Python: >=3.10
16
+ Provides-Extra: dev
17
+ Requires-Dist: fastapi>=0.100; extra == 'dev'
18
+ Requires-Dist: httpx>=0.24; extra == 'dev'
19
+ Requires-Dist: pytest>=7; extra == 'dev'
20
+ Requires-Dist: uvicorn>=0.23; extra == 'dev'
21
+ Provides-Extra: fastapi
22
+ Requires-Dist: fastapi>=0.100; extra == 'fastapi'
23
+ Provides-Extra: starlette
24
+ Requires-Dist: starlette>=0.27; extra == 'starlette'
25
+ Description-Content-Type: text/markdown
26
+
27
+ # rapidoc (Python)
28
+
29
+ Serves a [RapiDoc](https://rapidocui.com) API reference from a [FastAPI](https://fastapi.tiangolo.com) or Starlette app: an interactive page for your OpenAPI document, with a console to try requests.
30
+
31
+ ```bash
32
+ pip install rapidoc
33
+ ```
34
+
35
+ ```python
36
+ from fastapi import FastAPI
37
+ from rapidoc.fastapi import setup_rapidoc
38
+
39
+ app = FastAPI(docs_url=None, redoc_url=None)
40
+
41
+ setup_rapidoc(app)
42
+ ```
43
+
44
+ Open `/docs`. The page reads the app's own `/openapi.json`, and nothing is loaded from another site: the package carries the RapiDoc bundle.
45
+
46
+ FastAPI serves Swagger UI at `/docs` unless you create the app with `docs_url=None`. To keep Swagger UI, give RapiDoc another path: `setup_rapidoc(app, path="/reference")`.
47
+
48
+ ## Options
49
+
50
+ | Option | Default | |
51
+ | :--- | :--- | :--- |
52
+ | `path` | `/docs` | Where the reference is served, within the app |
53
+ | `spec_url` | the app's `openapi_url` | URL of the OpenAPI document. A path starting with `/` is a path of the app |
54
+ | `spec` | | The OpenAPI document itself (a dict or JSON text), written into the page |
55
+ | `title` | the app's title + "API Reference" | Page title |
56
+ | `assets` | `"bundled"` | `"bundled"`: the app serves `rapidoc-min.js`. `"cdn"`: the browser loads the same version from jsDelivr, checked against its SRI hash. `{"script_url": ..., "integrity": ...}`: a URL of your own |
57
+ | `options` | | [Attributes of `<rapi-doc>`](https://rapidocui.com/api/): `{"render_style": "focused", "allow_try": False}`. Names can be written with underscores, hyphens or in camelCase |
58
+ | `head`, `css` | | Markup and CSS added to the page as given |
59
+ | `lang` | `en` | Language of the page |
60
+ | `nonce` | | Content-Security-Policy nonce, or a function that takes the request and returns it |
61
+ | `enabled` | `True` | `False` adds nothing, for example outside development |
62
+
63
+ These are the options of every RapiDoc integration, in Python naming.
64
+
65
+ ## Behind a proxy
66
+
67
+ When a proxy strips a path prefix, run the app with that prefix as its `root_path` (`uvicorn app:app --root-path /api`, or `FastAPI(root_path="/api")`). The page then uses the prefix for the bundle, the OpenAPI document and the OAuth return page, as FastAPI's own docs do.
68
+
69
+ ## Starlette
70
+
71
+ `from rapidoc.starlette import setup_rapidoc` is the same function, for any Starlette app. Starlette has no OpenAPI endpoint of its own, so pass `spec_url` or `spec`.
72
+
73
+ ## Notes
74
+
75
+ - Each release ships one version of `rapidoc`: `rapidoc.rapidoc_version()`.
76
+ - The routes are left out of the app's OpenAPI document.
77
+ - OAuth sign-in returns to `{path}/oauth-receiver.html`, which the app serves on its own origin, also with `assets="cdn"`.
78
+ - [`examples/app.py`](./examples/app.py) is a complete app.
79
+
80
+ - The package itself requires no framework; `rapidoc.fastapi` uses the Starlette that FastAPI installs. `rapidoc.contract` is the RapiDoc integration contract in plain Python, for building an integration for another framework.
81
+
82
+ Python 3.10 or later; Starlette 0.27 or later. MIT.
@@ -0,0 +1,56 @@
1
+ # rapidoc (Python)
2
+
3
+ Serves a [RapiDoc](https://rapidocui.com) API reference from a [FastAPI](https://fastapi.tiangolo.com) or Starlette app: an interactive page for your OpenAPI document, with a console to try requests.
4
+
5
+ ```bash
6
+ pip install rapidoc
7
+ ```
8
+
9
+ ```python
10
+ from fastapi import FastAPI
11
+ from rapidoc.fastapi import setup_rapidoc
12
+
13
+ app = FastAPI(docs_url=None, redoc_url=None)
14
+
15
+ setup_rapidoc(app)
16
+ ```
17
+
18
+ Open `/docs`. The page reads the app's own `/openapi.json`, and nothing is loaded from another site: the package carries the RapiDoc bundle.
19
+
20
+ FastAPI serves Swagger UI at `/docs` unless you create the app with `docs_url=None`. To keep Swagger UI, give RapiDoc another path: `setup_rapidoc(app, path="/reference")`.
21
+
22
+ ## Options
23
+
24
+ | Option | Default | |
25
+ | :--- | :--- | :--- |
26
+ | `path` | `/docs` | Where the reference is served, within the app |
27
+ | `spec_url` | the app's `openapi_url` | URL of the OpenAPI document. A path starting with `/` is a path of the app |
28
+ | `spec` | | The OpenAPI document itself (a dict or JSON text), written into the page |
29
+ | `title` | the app's title + "API Reference" | Page title |
30
+ | `assets` | `"bundled"` | `"bundled"`: the app serves `rapidoc-min.js`. `"cdn"`: the browser loads the same version from jsDelivr, checked against its SRI hash. `{"script_url": ..., "integrity": ...}`: a URL of your own |
31
+ | `options` | | [Attributes of `<rapi-doc>`](https://rapidocui.com/api/): `{"render_style": "focused", "allow_try": False}`. Names can be written with underscores, hyphens or in camelCase |
32
+ | `head`, `css` | | Markup and CSS added to the page as given |
33
+ | `lang` | `en` | Language of the page |
34
+ | `nonce` | | Content-Security-Policy nonce, or a function that takes the request and returns it |
35
+ | `enabled` | `True` | `False` adds nothing, for example outside development |
36
+
37
+ These are the options of every RapiDoc integration, in Python naming.
38
+
39
+ ## Behind a proxy
40
+
41
+ When a proxy strips a path prefix, run the app with that prefix as its `root_path` (`uvicorn app:app --root-path /api`, or `FastAPI(root_path="/api")`). The page then uses the prefix for the bundle, the OpenAPI document and the OAuth return page, as FastAPI's own docs do.
42
+
43
+ ## Starlette
44
+
45
+ `from rapidoc.starlette import setup_rapidoc` is the same function, for any Starlette app. Starlette has no OpenAPI endpoint of its own, so pass `spec_url` or `spec`.
46
+
47
+ ## Notes
48
+
49
+ - Each release ships one version of `rapidoc`: `rapidoc.rapidoc_version()`.
50
+ - The routes are left out of the app's OpenAPI document.
51
+ - OAuth sign-in returns to `{path}/oauth-receiver.html`, which the app serves on its own origin, also with `assets="cdn"`.
52
+ - [`examples/app.py`](./examples/app.py) is a complete app.
53
+
54
+ - The package itself requires no framework; `rapidoc.fastapi` uses the Starlette that FastAPI installs. `rapidoc.contract` is the RapiDoc integration contract in plain Python, for building an integration for another framework.
55
+
56
+ Python 3.10 or later; Starlette 0.27 or later. MIT.
@@ -0,0 +1,15 @@
1
+ """uvicorn examples.app:app --port 4403 → http://localhost:4403/docs"""
2
+
3
+ from fastapi import FastAPI
4
+
5
+ from rapidoc.fastapi import setup_rapidoc
6
+
7
+ app = FastAPI(title="FastAPI example", version="1.0.0", docs_url=None, redoc_url=None)
8
+
9
+
10
+ @app.get("/hello", tags=["Greetings"], summary="Say hello")
11
+ def hello(name: str = "world") -> dict[str, str]:
12
+ return {"message": f"Hello, {name}!"}
13
+
14
+
15
+ setup_rapidoc(app, options={"render_style": "focused", "color_scheme": "light", "show_header": False})
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "rapidoc"
7
+ version = "0.1.0"
8
+ description = "RapiDoc for Python web frameworks: serves an interactive OpenAPI reference (<rapi-doc>) from a FastAPI or Starlette app"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE.txt"]
12
+ requires-python = ">=3.10"
13
+ authors = [{ name = "Mrinmoy Majumdar", email = "mrin9@yahoo.com" }]
14
+ keywords = ["fastapi", "starlette", "openapi", "rapidoc", "rapidoc-integration", "api documentation", "swagger ui"]
15
+ classifiers = [
16
+ "Framework :: FastAPI",
17
+ "Programming Language :: Python :: 3",
18
+ "Topic :: Software Development :: Documentation",
19
+ ]
20
+ # No framework is required to install: rapidoc.contract is plain Python, and rapidoc.fastapi uses the
21
+ # Starlette that FastAPI already brings.
22
+ dependencies = []
23
+
24
+ [project.optional-dependencies]
25
+ starlette = ["starlette>=0.27"]
26
+ fastapi = ["fastapi>=0.100"]
27
+ dev = ["fastapi>=0.100", "httpx>=0.24", "pytest>=7", "uvicorn>=0.23"]
28
+
29
+ [project.urls]
30
+ Homepage = "https://rapidocui.com"
31
+ Repository = "https://github.com/rapi-doc/RapiDoc"
32
+ Issues = "https://github.com/rapi-doc/RapiDoc/issues"
33
+
34
+ [tool.hatch.build.targets.wheel]
35
+ packages = ["src/rapidoc"]
36
+ # The rapidoc bundle is copied in by scripts/sync_assets.py and is not in git
37
+ artifacts = ["src/rapidoc/assets/*"]
38
+
39
+ [tool.hatch.build.targets.sdist]
40
+ include = ["src", "tests", "scripts", "examples", "README.md", "LICENSE.txt"]
41
+ artifacts = ["src/rapidoc/assets/*"]
42
+
43
+ [tool.pytest.ini_options]
44
+ testpaths = ["tests"]
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env python3
2
+ """Copies one rapidoc release into the package: the bundle, its license file and integration.json.
3
+
4
+ python scripts/sync_assets.py # from the monorepo's packages/rapidoc/dist
5
+ python scripts/sync_assets.py --from DIR # from another dist folder
6
+ python scripts/sync_assets.py --npm # from the npm registry, the version in RAPIDOC_VERSION
7
+ python scripts/sync_assets.py --npm 12.2.0 # from the npm registry, another version
8
+
9
+ The three files must come from the same release: integration.json carries the SRI hash of the bundle.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import argparse
15
+ import io
16
+ import json
17
+ import shutil
18
+ import tarfile
19
+ import urllib.request
20
+ from pathlib import Path
21
+
22
+ PROJECT = Path(__file__).resolve().parents[1]
23
+ ASSETS = PROJECT / "src/rapidoc/assets"
24
+ FILES = ["rapidoc-min.js", "rapidoc-min.js.LICENSE.txt", "integration.json"]
25
+
26
+
27
+ def from_directory(source: Path) -> None:
28
+ missing = [name for name in FILES if not (source / name).exists()]
29
+ if missing:
30
+ raise SystemExit(f"{source} has no {', '.join(missing)}; build rapidoc first (npm run build:rapidoc)")
31
+ for name in FILES:
32
+ shutil.copyfile(source / name, ASSETS / name)
33
+
34
+
35
+ def from_npm(version: str) -> None:
36
+ url = f"https://registry.npmjs.org/rapidoc/-/rapidoc-{version}.tgz"
37
+ with urllib.request.urlopen(url) as response: # noqa: S310 (a fixed https registry URL)
38
+ archive = tarfile.open(fileobj=io.BytesIO(response.read()), mode="r:gz")
39
+ for name in FILES:
40
+ member = archive.extractfile(f"package/dist/{name}")
41
+ if member is None:
42
+ raise SystemExit(f"rapidoc {version} has no dist/{name}")
43
+ (ASSETS / name).write_bytes(member.read())
44
+
45
+
46
+ def main() -> None:
47
+ parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
48
+ parser.add_argument("--from", dest="source", type=Path, default=PROJECT.parents[1] / "packages/rapidoc/dist")
49
+ parser.add_argument(
50
+ "--npm",
51
+ metavar="VERSION",
52
+ nargs="?",
53
+ const=(PROJECT / "RAPIDOC_VERSION").read_text(encoding="utf-8").strip(),
54
+ help="download this rapidoc release from npm (default: the version in RAPIDOC_VERSION)",
55
+ )
56
+ args = parser.parse_args()
57
+ ASSETS.mkdir(parents=True, exist_ok=True)
58
+ if args.npm:
59
+ from_npm(args.npm)
60
+ else:
61
+ from_directory(args.source)
62
+ version = json.loads((ASSETS / "integration.json").read_text(encoding="utf-8"))["version"]
63
+ print(f"rapidoc {version} in {ASSETS.relative_to(PROJECT)}:", ", ".join(FILES))
64
+
65
+
66
+ if __name__ == "__main__":
67
+ main()
@@ -0,0 +1,41 @@
1
+ """RapiDoc for Python web frameworks.
2
+
3
+ from fastapi import FastAPI
4
+ from rapidoc.fastapi import setup_rapidoc
5
+
6
+ app = FastAPI(docs_url=None, redoc_url=None)
7
+ setup_rapidoc(app) # the reference at /docs, reading the app's /openapi.json
8
+
9
+ ``rapidoc.contract`` is the RapiDoc integration contract in Python (a port of ``@rapidoc/embed``): the page,
10
+ the routes and the attributes. A framework module (``rapidoc.fastapi``, ``rapidoc.starlette``) only maps
11
+ them to that framework's routes. This module imports no framework.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ from pathlib import Path
18
+ from typing import Any
19
+
20
+ from . import contract
21
+
22
+ __all__ = ["rapidoc_version", "rapidoc_manifest", "contract", "ASSETS"]
23
+
24
+ #: One rapidoc release: the bundle, its license file and integration.json
25
+ ASSETS = Path(__file__).parent / "assets"
26
+
27
+
28
+ def rapidoc_manifest() -> dict[str, Any]:
29
+ """``integration.json`` of the rapidoc release this package ships: version, files, SRI hashes."""
30
+ file = ASSETS / "integration.json"
31
+ if not file.exists():
32
+ raise RuntimeError(
33
+ "rapidoc: the rapidoc bundle is missing from this installation "
34
+ "(in a source checkout, run scripts/sync_assets.py)"
35
+ )
36
+ return json.loads(file.read_text(encoding="utf-8"))
37
+
38
+
39
+ def rapidoc_version() -> str:
40
+ """The version of rapidoc this package serves."""
41
+ return rapidoc_manifest()["version"]
@@ -0,0 +1,43 @@
1
+ {
2
+ "contract": 1,
3
+ "name": "rapidoc",
4
+ "version": "12.2.0",
5
+ "elements": [
6
+ "rapi-doc",
7
+ "rapi-doc-mini",
8
+ "oauth-receiver"
9
+ ],
10
+ "cdn": "https://cdn.jsdelivr.net/npm/rapidoc@12.2.0/dist/",
11
+ "files": {
12
+ "rapidoc-min.js": {
13
+ "role": "script",
14
+ "contentType": "text/javascript; charset=utf-8",
15
+ "bytes": 643136,
16
+ "integrity": "sha384-1JA7hsG9FwOzHQnEH+aOO9WV+k74Ft3W1rjU1P7E4RtAXHaVqDP8sa49oGLhuzHD"
17
+ },
18
+ "rapidoc-min.js.LICENSE.txt": {
19
+ "role": "license",
20
+ "contentType": "text/plain; charset=utf-8",
21
+ "bytes": 19073,
22
+ "integrity": "sha384-f2/nGiQja338BGgbRRM9Qb++auJfKpfflao4DEGOVuXc+Y2ORfDs1MugRjYeLXbu"
23
+ },
24
+ "oauth-receiver.html": {
25
+ "role": "oauth-receiver",
26
+ "contentType": "text/html; charset=utf-8",
27
+ "bytes": 236,
28
+ "integrity": "sha384-rfos5ZPmmjObE/xd+YkxUxo2Pj7jgdyLD4FaC9OiacqFZIh53ENId1EYcXyOCcLW"
29
+ },
30
+ "rapidoc-flow-min.js": {
31
+ "role": "flow-script",
32
+ "contentType": "text/javascript; charset=utf-8",
33
+ "bytes": 213829,
34
+ "integrity": "sha384-asDo0SV5f87CcYYk9KjQKpLggdr8OBXYrd/8TV2MvLF/YHGYG9K/9n0OYJUSn/5P"
35
+ },
36
+ "rapidoc-flow-min.js.LICENSE.txt": {
37
+ "role": "flow-license",
38
+ "contentType": "text/plain; charset=utf-8",
39
+ "bytes": 8286,
40
+ "integrity": "sha384-oaDE7s/9ktovzg47bUf0BY+Ksq+YFB84dQKb+WJbfNfk3E7Nd/PUx2RlQZwUS25W"
41
+ }
42
+ }
43
+ }