Skip to main content

Flask extension to build REST APIs based on SQLAlchemy models

Project description

Flask-RESTAlchemy

build codecov black black

A Flask extension to build REST APIs. It dismiss the need of building Schema classes, since usually all the information needed to serialize an SQLAlchemy instance is in the model itself.

By adding a model to the API, all its properties will be exposed:

class User(Base):

    __tablename__ = "User"

    id = Column(Integer, primary_key=True)
    firstname = Column(String)
    lastname = Column(String)
    email = Column(String)
    password = Column(String)


api = Api(flask_app)
api.add_model(User, "/user")

To change the way properties are serialized, declare only the one that needs a non-default behaviour:

from serialchemy import ModelSerializer, Field


class UserSerializer(ModelSerializer):

    password = Field(load_only=True)


api = Api(flask_app)
api.add_model(User, "/user", serializer_class=UserSerializer)

Development Setup

Requires uv.

uv python pin 3.10
uv sync --group dev
source .venv/bin/activate

If serialchemy is checked out as a sibling repository, install it as an editable dependency:

uv pip install -e ../serialchemy

Run the tests:

pytest src/flask_restalchemy/tests/

Release

A reminder for the maintainers on how to make a new release.

Note that the VERSION should folow the semantic versioning as X.Y.Z Ex.: v1.0.5

  1. Create a release-VERSION branch from upstream/master.
  2. Update CHANGELOG.rst.
  3. Push a branch with the changes.
  4. Once all builds pass, push a VERSION tag to upstream.
  5. Merge the PR.

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_restalchemy-0.15.1.tar.gz (95.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_restalchemy-0.15.1-py3-none-any.whl (30.1 kB view details)

Uploaded Python 3

File details

Details for the file flask_restalchemy-0.15.1.tar.gz.

File metadata

  • Download URL: flask_restalchemy-0.15.1.tar.gz
  • Upload date:
  • Size: 95.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flask_restalchemy-0.15.1.tar.gz
Algorithm Hash digest
SHA256 83028a1f551850b02a338ff7426bfb3f218a44a6f1f01bc44aad12de72713ac2
MD5 31474d17bb38d251b6a97843ea4a850d
BLAKE2b-256 0e619c0f1f219a6473793f5924c9719fe511c080d04fa3cb8e7f1f2f818adfec

See more details on using hashes here.

File details

Details for the file flask_restalchemy-0.15.1-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_restalchemy-0.15.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6729a2e5900595826a7f27df4ebddbec7fa09a42c05131879293af465db55fb7
MD5 c25dca747d64cd495d0806f38aea13dc
BLAKE2b-256 18a36f0f7695077fb06d0ccbfd6f2da8774fc604767a5344530bc69181d33e3c

See more details on using hashes here.

Supported by

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