Skip to main content

⚠️ This package is being replaced by Sanic Extensions. The project will continue to be monitored, but no new features or major development is anticipated. Sanic Extensions contains a near 1:1 upgrade if you are using Sanic OpenAPI with OAS3. Ask in the forums or discord server for questions about upgrading.

Sanic OpenAPI

Build Status PyPI PyPI Code style: black codecov

Give your Sanic API a UI and OpenAPI documentation, all for the price of free!

Example Swagger UI

Check out open collective to learn more about helping to fund Sanic.

Installation

pip install sanic-openapi

Add Swagger UI with the OpenAPI spec:

from sanic_openapi import swagger_blueprint

app.blueprint(swagger_blueprint)

You'll now have a Swagger UI at the URL /swagger/ and an OpenAPI 2.0 spec at /swagger/swagger.json. Your routes will be automatically categorized by their blueprints.

OpenAPI 2

Here is an example to use Sanic-OpenAPI 2:

from sanic import Sanic
from sanic.response import json
from sanic_openapi import openapi2_blueprint

app = Sanic(name="AwesomeApi")
app.blueprint(openapi2_blueprint)


@app.route("/")
async def test(request):
    return json({"hello": "world"})


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)

And you can get your Swagger document at http://localhost:8000/swagger like this:

OpenAPI 3

Here is an example to use Sanic-OpenAPI 3:

from sanic import Sanic
from sanic.response import json
from sanic_openapi import openapi3_blueprint

app = Sanic(name="AwesomeApi")
app.blueprint(openapi3_blueprint)


@app.route("/")
async def test(request):
    return json({"hello": "world"})


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)

And you can get your Swagger document at http://localhost:8000/swagger like this:

Documentation

Please check the documentation on Readthedocs

Contribution

Any contribution is welcome. If you don't know how to getting started, please check issues first and check our Contributing Guide to start you contribution.

Metadata

Release files for sanic-openapi 21.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sanic-openapi 21.12.0
File Size Uploaded
sanic-openapi-21.12.0.tar.gz 5.1 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for sanic-openapi 21.12.0
File Interpreter ABI Platform
sanic_openapi-21.12.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.3 MB

Release files / sanic-openapi-21.12.0.tar.gz

Download URL sanic-openapi-21.12.0.tar.gz
Size 5.1 MB
Tags Source
SHA-256 checksum
How to use checksums
7cda62234d08c965f739eaac6b059e8f244d87061d97335c57287fd6ae16bf52
BLAKE2b-256 checksum
How to use checksums
14c3ddfd75ee001957af2a15727a101c476c83a15203ee878f172e8c58a64727
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

Release files / sanic_openapi-21.12.0-py3-none-any.whl

Download URL sanic_openapi-21.12.0-py3-none-any.whl
Size 5.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
35412cf7c59777c0c6af60967890d30386be40395f69dc50ae88859e9143f484
BLAKE2b-256 checksum
How to use checksums
f89dc62c8c8466375a8f07129ddd81cf99d3573abfa16b643dca9021a2f4c76d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

Release history Release notifications | RSS feed

This release

21.12.0 This release

2 release files

21.6.1

2 release files

21.3.2

1 release file

21.3.1

1 release file

21.3.0

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.0

2 release files

0.4.0

1 release file

0.3.0

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.7

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page