Skip to main content

Flask Gun is a web framework for building APIs with Flask and Python 3.10+ type hints.

Project description

Flask Gun

build python

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 a and b
  • 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):

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

flask_gun-1.0.0.tar.gz (496.5 kB view details)

Uploaded Source

Built Distribution

flask_gun-1.0.0-py3-none-any.whl (502.2 kB view details)

Uploaded Python 3

File details

Details for the file flask_gun-1.0.0.tar.gz.

File metadata

  • Download URL: flask_gun-1.0.0.tar.gz
  • Upload date:
  • Size: 496.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.8 Windows/10

File hashes

Hashes for flask_gun-1.0.0.tar.gz
Algorithm Hash digest
SHA256 64f249ff6b53615aec1d80b29148f46575572904852604f8b101a811a44b3fe9
MD5 17e6bb1123841221dd83a4e93dd1c22e
BLAKE2b-256 29fbf4e8f0fdff6f93bf053c249db554d4ab2f8ebdee45569c0d8a23a58dfb82

See more details on using hashes here.

File details

Details for the file flask_gun-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: flask_gun-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 502.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.8 Windows/10

File hashes

Hashes for flask_gun-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8380d0dbdada2bbe2db900b1ab56dcd53430c363a5e5e8bc5875ddaf574b5413
MD5 2ee4b9f597de47c66ffb72cf11a86324
BLAKE2b-256 3e5ac1b654b6f795e3cef6ed8d504564be2ac724c941fc27e3b76f1de67f6ce8

See more details on using hashes here.

Supported by

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