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.0.tar.gz (94.9 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.0-py3-none-any.whl (29.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flask_restalchemy-0.15.0.tar.gz
  • Upload date:
  • Size: 94.9 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.0.tar.gz
Algorithm Hash digest
SHA256 11bb8f37599c23467c5720e26af42cd7c69c86890a7d7eb3c7f4b2c11a2965dd
MD5 6642c29ab2038704e9b94ccd8ea5a4a9
BLAKE2b-256 7ac7663028242019a17087a5b4be55173ba10ea54922bf0d519c226f3aeb15ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flask_restalchemy-0.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 43388619914bdc6ab20099a22fc1aed4320f37d3ddf02a6ef03f0e270a46c703
MD5 9107d4f87045458a0f003bfdea6aa2ce
BLAKE2b-256 b4e92623403534240434894349c1e4662243b87a64cf8dcfa031b10eaac905dd

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