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.3.tar.gz (8.4 kB view hashes)

Uploaded Source

Built Distribution

flask_api_factory-0.2.3-py3-none-any.whl (11.4 kB view hashes)

Uploaded Python 3

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