Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sanic-org/sanic-openapi
Easily document your Sanic API with a UI
https://github.com/sanic-org/sanic-openapi
openapi python sanic swagger-ui
Last synced: 1 day ago
JSON representation
Easily document your Sanic API with a UI
- Host: GitHub
- URL: https://github.com/sanic-org/sanic-openapi
- Owner: sanic-org
- License: mit
- Created: 2017-01-11T05:59:22.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2022-12-16T12:42:33.000Z (about 2 years ago)
- Last Synced: 2024-10-29T15:13:50.395Z (2 months ago)
- Topics: openapi, python, sanic, swagger-ui
- Language: Python
- Homepage: https://sanic-openapi.readthedocs.io/
- Size: 13.8 MB
- Stars: 505
- Watchers: 22
- Forks: 107
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-sanic - Sanic-OpenAPI
README
⚠️ This package is being replaced by [Sanic Extensions](https://sanicframework.org/en/plugins/sanic-ext/getting-started.html). 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](https://community.sanicframework.org/) or [discord server](https://discord.gg/FARQzAEMAA) for questions about upgrading.
# Sanic OpenAPI
[![Build Status](https://travis-ci.com/sanic-org/sanic-openapi.svg?branch=master)](https://travis-ci.com/sanic-org/sanic-openapi)
[![PyPI](https://img.shields.io/pypi/v/sanic-openapi.svg)](https://pypi.python.org/pypi/sanic-openapi/)
[![PyPI](https://img.shields.io/pypi/pyversions/sanic-openapi.svg)](https://pypi.python.org/pypi/sanic-openapi/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black)
[![codecov](https://codecov.io/gh/sanic-org/sanic-openapi/branch/master/graph/badge.svg)](https://codecov.io/gh/sanic-org/sanic-openapi)Give your Sanic API a UI and OpenAPI documentation, all for the price of free!
![Example Swagger UI](docs/_static/images/code-to-ui.png?raw=true "Swagger UI")
Check out [open collective](https://opencollective.com/sanic-org) to learn more about helping to fund Sanic.
## Installation
```shell
pip install sanic-openapi
```Add Swagger UI with the OpenAPI spec:
```python
from sanic_openapi import swagger_blueprintapp.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:
```python
from sanic import Sanic
from sanic.response import json
from sanic_openapi import openapi2_blueprintapp = 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 like this:
![](docs/_static/images/hello_world_example.png)## OpenAPI 3
Here is an example to use Sanic-OpenAPI 3:
```python
from sanic import Sanic
from sanic.response import json
from sanic_openapi import openapi3_blueprintapp = 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 like this:
![](docs/_static/images3/hello_world_example.png)## Documentation
Please check the documentation on [Readthedocs](https://sanic-openapi.readthedocs.io)
## Contribution
Any contribution is welcome. If you don't know how to getting started, please check issues first and check our [Contributing Guide](CONTRIBUTING.md) to start you contribution.