Plugin for APISpec handling Starlette
This module should not be considered as stable as it is still under development.
However a stable version can be expected by mid March 2020 and any issue or pull request is welcome at any time.
Provides a plugin to use with APISpec to be able to handle Starlette endpoints.
StarlettePlugin usage
from starlette.applications import Starlette
from apispec import APISpec
from apispec_starlette import StarlettePlugin
app = Starlette()
spec = APISpec(
title="My API",
version="0.0.1",
openapi_version="2.0",
plugins=[StarlettePlugin(app)],
)
Documenting responses inside endpoint docstring
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from apispec import APISpec
from apispec_starlette import StarlettePlugin
app = Starlette()
spec = APISpec(
title="My API",
version="0.0.1",
openapi_version="2.0",
plugins=[StarlettePlugin(app)],
)
@app.route("/my_endpoint")
def my_endpoint():
"""
responses:
200:
description: "Action performed"
schema:
properties:
status:
type: string
type: object
"""
return JSONResponse({"status": "test"})
Documenting responses outside of endpoint docstring
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from apispec import APISpec
from apispec_starlette import StarlettePlugin, document_response
app = Starlette()
spec = APISpec(
title="My API",
version="0.0.1",
openapi_version="2.0",
plugins=[StarlettePlugin(app)],
)
@app.route("/my_endpoint")
def my_endpoint():
return JSONResponse({"status": "test"})
document_response(spec, endpoint="/my_endpoint", method="get", status_code=200, response={
"description": "Action performed",
"schema": {
"properties": {"status": {"type": "string"}},
"type": "object",
}
})
Documenting OAuth2 security outside of endpoint docstring
from starlette.applications import Starlette
from starlette.middleware import Middleware
from starlette.middleware.authentication import AuthenticationMiddleware
from starlette.authentication import requires, AuthenticationBackend
from starlette.responses import JSONResponse
from apispec import APISpec
from apispec_starlette import StarlettePlugin, document_endpoint_oauth2_authentication, document_oauth2_authentication
# TODO Replace by your OAuth2 backend
app = Starlette(middleware=[Middleware(AuthenticationMiddleware, backend=AuthenticationBackend())])
spec = APISpec(
title="My API",
version="0.0.1",
openapi_version="2.0",
plugins=[StarlettePlugin(app)],
)
# TODO Adjust parameters
document_oauth2_authentication(spec, authorization_url="http://authorization_url", flow="implicit", scopes={"scope1": "Description of scope 1", "scope2": "Description of scope 2"})
@requires(scopes=["scope1", "scope2"])
@app.route("/my_endpoint")
def my_endpoint():
return JSONResponse({"status": "test"})
document_endpoint_oauth2_authentication(spec, endpoint="/my_endpoint", method="get", required_scopes=["scope1", "scope2"])
Add a /swagger.json endpoint
Your endpoints can be automatically discovered and documented when requesting /swagger.json
from starlette.applications import Starlette
from apispec_starlette import add_swagger_json_endpoint
app = Starlette()
spec = add_swagger_json_endpoint(app=app)
How to install
- python 3.6+ must be installed
- Use pip to install module:
python -m pip install apispec_starlette
Metadata
Release files for apispec-starlette 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| apispec_starlette-0.0.3.tar.gz | 5.7 kB | Without provenance | Details for apispec_starlette-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| apispec_starlette-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for apispec_starlette-0.0.3-py3-none-any.whl |
Total release size: 13.2 kB
Release files / apispec_starlette-0.0.3.tar.gz
| Download URL | apispec_starlette-0.0.3.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f40c96e2533069ac9cf9903486c96679edb9789cccadc508865b1f63bee4190
|
|
BLAKE2b-256 checksum How to use checksums |
5248997e847d477a332a4b2357f010282c44f0c41e07d7345c01707aff6690bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.1
|
Release files / apispec_starlette-0.0.3-py3-none-any.whl
| Download URL | apispec_starlette-0.0.3-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
73bde5d6244d8365a365750b3e57812f2174f5e55a0612f565b4130a0d3050c0
|
|
BLAKE2b-256 checksum How to use checksums |
4f934c524aefdf63a992a83dbafa8c1939a165e0f127f27e951672a66e1055aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.1
|
Security for apispec-starlette 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.