Flask Gun
Flask Gun is a web framework for building APIs with Flask and Python 3.9+ type hints.
Derived from Flask ninja 1.3.0 fork
Key features:
- Easy: Designed to be easy to use and intuitive.
- Fast to code: Type hints and automatic docs lets you focus only on business logic.
- Standards-based: Based on the open standards for APIs: OpenAPI (previously known as Swagger) and JSON Schema.
- Models based: Pydantic models support and automatic (de)serialization of requests/responses.
- Secure: Natively supports various authentication methods for the requests.
For mode details, see the Documentation
Installation
pip install flask-gun
Usage
In your flask project where you create flask app:
from flask import Flask
from flask_gun import GunAPI
from pydantic import BaseModel
app = Flask(__name__)
api = GunAPI(app)
class Response(BaseModel):
"""Response model containing results of various number operations."""
sum: int
difference: int
product: int
power: int
@api.get("/compute")
def compute(a: int, b: int) -> Response:
"""Computes results of various number operations.
This endpoint returns a result of the following operations:
- sum
- difference
- product
- power
:param int a: First number
:param int b: Second number number
"""
return Response(
sum=a + b,
difference=a - b,
product=a * b,
power=a ** b
)
if __name__ == "__main__":
app.run()
That's it !
Now you've just created an API that:
- receives an HTTP GET request at
/compute - takes, validates and type-casts GET parameters
aandb - validates the returned Response object and serializes it into JSON
- generates an OpenAPI schema for defined operation
Interactive API docs
Now go to http://127.0.0.1:5000/docs
You will see the automatic interactive API documentation (provided by Swagger UI):
Metadata
Release files for flask-gun 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flask_gun-1.0.0.tar.gz | 496.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flask_gun-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 998.7 kB
Release files / flask_gun-1.0.0.tar.gz
| Download URL | flask_gun-1.0.0.tar.gz |
|---|---|
| Size | 496.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
64f249ff6b53615aec1d80b29148f46575572904852604f8b101a811a44b3fe9
|
|
BLAKE2b-256 checksum How to use checksums |
29fbf4e8f0fdff6f93bf053c249db554d4ab2f8ebdee45569c0d8a23a58dfb82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.8 Windows/10
|
Release files / flask_gun-1.0.0-py3-none-any.whl
| Download URL | flask_gun-1.0.0-py3-none-any.whl |
|---|---|
| Size | 502.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8380d0dbdada2bbe2db900b1ab56dcd53430c363a5e5e8bc5875ddaf574b5413
|
|
BLAKE2b-256 checksum How to use checksums |
3e5ac1b654b6f795e3cef6ed8d504564be2ac724c941fc27e3b76f1de67f6ce8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.8 Windows/10
|