Skip to main content

APISpec plugin handling Starlette.

Project description

Plugin for APISpec handling Starlette

pypi version Build status Coverage Code style: black Number of tests Number of downloads

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",
    }
})

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

  1. python 3.6+ must be installed
  2. Use pip to install module:
python -m pip install apispec_starlette

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apispec_starlette-0.0.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apispec_starlette-0.0.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file apispec_starlette-0.0.1.tar.gz.

File metadata

  • Download URL: apispec_starlette-0.0.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.1

File hashes

Hashes for apispec_starlette-0.0.1.tar.gz
Algorithm Hash digest
SHA256 231871c0c29ec39db8d927d2325392e2d7be062ac231dd43c03b3d9d9668df57
MD5 c008242612293c4cd4643c6f4621a4c0
BLAKE2b-256 fc441fad310c9af6cbf93c048460207c678a26f4822885c59cda1ea8ef7ed37f

See more details on using hashes here.

File details

Details for the file apispec_starlette-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: apispec_starlette-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.1

File hashes

Hashes for apispec_starlette-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a641ecc5f59a6c6274f06b370ba814032fafd241d28403e54787b5754dfbb29f
MD5 46d67b3ee9097944bf8c372e98846def
BLAKE2b-256 7193d74bc8647073325716658a47c04f5f16d60bac9f463a83a625b7d261ab94

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page