Easily document your Sanic API with a UI.
Project description
⚠️ 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
Give your Sanic API a UI and OpenAPI documentation, all for the price of free!
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sanic-openapi-21.12.0.tar.gz
.
File metadata
- Download URL: sanic-openapi-21.12.0.tar.gz
- Upload date:
- Size: 5.1 MB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cda62234d08c965f739eaac6b059e8f244d87061d97335c57287fd6ae16bf52 |
|
MD5 | cbf8df36b97edc4f307b9f23bde8985b |
|
BLAKE2b-256 | 14c3ddfd75ee001957af2a15727a101c476c83a15203ee878f172e8c58a64727 |
File details
Details for the file sanic_openapi-21.12.0-py3-none-any.whl
.
File metadata
- Download URL: sanic_openapi-21.12.0-py3-none-any.whl
- Upload date:
- Size: 5.2 MB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35412cf7c59777c0c6af60967890d30386be40395f69dc50ae88859e9143f484 |
|
MD5 | 4e308ee4cc4cc02c081284a271afd6e3 |
|
BLAKE2b-256 | f89dc62c8c8466375a8f07129ddd81cf99d3573abfa16b643dca9021a2f4c76d |