Skip to main content

FlaskEase

Flask extension for creating REST APIs. You get autogenerated OpenAPI spec (with Redoc and Swagger Docs), Request parsing and validations (query, path, body, form and files) and Response validation.

Checkout example here

Documentation

Documentation is coming soon :)

Try Example

$ git clone git@github.com:zero-shubham/flask-ease.git
$ cd flask-ease
$ poetry install
$ source "$( poetry env list --full-path )/bin/activate"
$ python example/main.py

Now go to http://127.0.0.1:5000/docs to find SwaggerUI docs for your API.

Simple Usage

# * example/resources/pet.py
from application import (
    FlaskEaseAPI,
    Depends,
    HTTPException,
    status,
    File
)
from schemas.pet import (
    PetCreationForm,
    PetInResp,
    PetInDB,
    PetsInResp
)
from utils.dependencies import get_current_user
from crud.pet import (
    add_new_pet_to_db,
    find_pet_by_id,
    get_all_pets_count_in_db,
    get_all_pets_in_db
)
from uuid import uuid4, UUID
from flask import send_from_directory

pets_blp = FlaskEaseAPI(
    blueprint_name="Pets",
    url_prefix="/pets"
)


@pets_blp.post(
    route="/",
    response_model=PetInResp,
    tags=["pets"],
    auth_required=True
)
def create_new_pet(
    obj_in: PetCreationForm,
    current_user=Depends(get_current_user)
):
    """
    Add a new pet to DB
    """

    if obj_in.owner != current_user["id"]:
        raise HTTPException(
            status.HTTP_403_FORBIDDEN,
            "You are not authorised for this operation."
        )

    new_pet = add_new_pet_to_db(PetInDB(
        id=str(uuid4()),
        **obj_in.dict()
    ).dict())
    return new_pet


@pets_blp.get(
    route="/<uuid:id>",
    response_model=PetInResp,
    tags=["pets"],
    auth_required=True
)
def get_pet_by_id(
    id: UUID
):
    """
    Get pet by id
    """
    pet = find_pet_by_id(id)
    return pet


@pets_blp.get(
    route="/",
    response_model=PetsInResp,
    tags=["pets"],
    auth_required=True
)
def get_all_pets(
    offset: int = 0,
    limit: int = 10,
    current_user=Depends(get_current_user)
):
    """
    Get all pets in db
    """
    pets = get_all_pets_in_db(
        offset,
        limit
    )
    count = get_all_pets_count_in_db()
    return PetsInResp(
        pets=pets,
        total_count=count
    )


@pets_blp.post(
    route="/<uuid:id>/photo",
    tags=["pets"],
    auth_required=True,
    responses={
        '204': 'File accepted and saved.'
    }
)
def add_pet_photo(
    id: UUID,
    photo: File("image/png"),
    current_user=Depends(get_current_user)
):
    """
    Add pet photo.
    """
    with open(f"{id}.png", "wb") as photoFile:
        photoFile.write(photo)
    return "True", 204

For a complete understanding check the example here

File-uploads are not yet supported via FlaskEase - to be added soon Now with File-upload and Multipart-Form support.

Release files for FlaskEase 0.2.2

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

Source distribution (sdist)

Source distribution for FlaskEase 0.2.2
File Size Uploaded
FlaskEase-0.2.2.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for FlaskEase 0.2.2
File Interpreter ABI Platform
FlaskEase-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 24.4 kB

Release files / FlaskEase-0.2.2.tar.gz

Download URL FlaskEase-0.2.2.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f5bed040b46ce20173913524c64dc9ae3d772a555072c1eb42d2bb603f0a8624
BLAKE2b-256 checksum
How to use checksums
a99efa10d27068722aedf0ac80f64065d2aea28f592d4e71c53b7e0b3c322cd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.2

Release files / FlaskEase-0.2.2-py3-none-any.whl

Download URL FlaskEase-0.2.2-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
26f9137ff08e4cb25f02a6099ba3ef72c835cb8ba0046f505afcb6cc5912d2fb
BLAKE2b-256 checksum
How to use checksums
7fd61a5733613f590449092d7b6cdc96ea79bc6badff8b1f90aeab3748ab548a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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