Skip to main content

one small flask rest api factory

Project description

The initial idea is to be a Rest API factory, with the aim of making it easy to create from models defined using the SQLAlchemy ORM.

We still use pydantic to serialize objects and payloads.

Install

You can install using pip:

$ pip install flask-api-factory

You can install with the database driver you want to be supported by SQLAlchemy, but if you prefer, you can install the driver as an extra library, with the command:

$ pip install flask-api-factory[postgres]

This will install psycopg2 together with our library.

You can still install using poetry with the command:

$ poetry add flask-api-factory

A simple example

Having the Pet model already defined and the initialization of the Flask application already started, just use the following code:

from flask import Flask, Blueprint
from flask_api_factory import factory_api

from .models import Pet
from .serializers import PetSerializer


blueprint = Blueprint("pets", __name__, url_prefix="/pets")


def init_app(app: Flask) -> None:
    app.register_blueprint(blueprint)

factory_api(blueprint, Pet, PetSerializer)

This way we will have a /pets endpoint capable of responding to all HTTP verbs. Consulting the documentation you can check other options for configurations and functionalities.

Roadmap

  • Documentation;
  • openapi.json generation mechanism;
  • A way to provide Swagger and/or Redoc;
  • Write unit tests.

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_api_factory-0.2.2.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

flask_api_factory-0.2.2-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file flask_api_factory-0.2.2.tar.gz.

File metadata

  • Download URL: flask_api_factory-0.2.2.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.10.10 Linux/5.15.0-1033-azure

File hashes

Hashes for flask_api_factory-0.2.2.tar.gz
Algorithm Hash digest
SHA256 335419c611ebee0276c03fe5f39f203e09ed0d3f7ab8144b4b924fb3a4e443f8
MD5 776e61ee54c7c00ecf3815e363afd5db
BLAKE2b-256 38e3b35a4469771c21d33073656b5acea85e56e09850a072e1f07022cc303c14

See more details on using hashes here.

File details

Details for the file flask_api_factory-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: flask_api_factory-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.10.10 Linux/5.15.0-1033-azure

File hashes

Hashes for flask_api_factory-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d81b8b70b74e52d1d06bccda521a93b7a357d47e69d3e2134ca24b37a5c0b872
MD5 4f27ea1fb834a0ffd3f9bce8b88cec68
BLAKE2b-256 23a5717a3ef9af6b11726aa8571609ed4ff50860ab63fea31279528ecf27b1b1

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