Skip to main content
https://github.com/infraguys/restalchemy/actions/workflows/tests.yml/badge.svg https://img.shields.io/pypi/pyversions/restalchemy https://img.shields.io/pypi/dm/restalchemy https://raw.githubusercontent.com/infraguys/restalchemy/python-coverage-comment-action-data/badge.svg

RESTAlchemy

RESTAlchemy is a Python toolkit for building HTTP REST APIs on top of a flexible data model and storage abstraction.

It combines:

  • A Data Model (DM) layer for defining domain models and validation.

  • A Storage layer for persisting models (for example, SQL databases).

  • An API layer for exposing models as RESTful HTTP resources.

  • Optional OpenAPI support for discoverable, documented APIs.

Features

  • Clear separation between domain models, storage implementation details, and HTTP API.

  • Strongly typed, validated data model with reusable properties.

  • Minimal boilerplate to expose models as REST resources.

  • Built-in migration tooling for evolving database schemas.

Performance

On all three request patterns, RESTAlchemy is the fastest framework measured here, and stands nearer to the floor of what such a request can cost at all than to any framework behind it. The benchmark in this repository asks six stacks the same three questions against the same PostgreSQL and the same rows: read a collection of 100, read one resource, create one. The first row of the table is not one of them: it is a hand-written query and orjson.dumps, which is what the database and the JSON cost before any framework has run.

15 rounds × best of 20 calls, 1000 rows in the table, 100 per page, Python 3.12, PostgreSQL 16, one AMD EPYC 7742. The full run, with confidence intervals and the machine it was measured on, is in bench/results/results.md; these are its numbers. In parentheses: the same number as a multiple of RESTAlchemy’s.

Stack

Collection of 100

One resource

POST one

Per row

raw psycopg + orjson †

1272 µs (0.7×)

174 µs (0.5×)

229 µs (0.6×)

11.1 µs (0.8×)

RESTAlchemy

1705 µs

317 µs

397 µs

14.0 µs

Flask + SQLAlchemy

2267 µs (1.3×)

636 µs (2.0×)

606 µs (1.5×)

16.5 µs (1.2×)

FastAPI + SQLAlchemy

2417 µs (1.4×)

894 µs (2.8×)

829 µs (2.1×)

15.4 µs (1.1×)

Litestar + SQLAlchemy

2524 µs (1.5×)

857 µs (2.7×)

811 µs (2.0×)

16.8 µs (1.2×)

Django + DRF

5276 µs (3.1×)

943 µs (3.0×)

895 µs (2.3×)

43.8 µs (3.1×)

† Not a framework, and faster than every framework under it, as it should be: it is the floor the rest are read against, not a stack anyone would build a service on.

RESTAlchemy adds 143 µs to that bare single-row query, 168 µs to the bare insert, and under three microseconds to each row of a collection — a REST service, routed, validated and packed, for a few microseconds over the floor.

Every stack is written the way its own documentation writes it, answers with the same rows — checked field by field before anything is timed — and is called at its own interface, so what is measured is the framework and its database work rather than a web server. The command that runs it, and what the numbers do not say, are in bench/README.md.

Documentation

The rendered documentation is published at https://infraguys.github.io/restalchemy/.

All documentation is available in four languages. The structure of files and sections is identical across languages:

If you are new to RESTAlchemy, start with:

Quick start

Install from PyPI:

pip install restalchemy

Define a simple DM model (simplified from the getting started guide):

from restalchemy.dm import models
from restalchemy.dm import properties
from restalchemy.dm import types


class FooModel(models.ModelWithUUID):
    value = properties.property(types.Integer(), required=True)

For a complete in-memory REST service example, including controllers, routes and a WSGI application, see docs/en/getting-started.md.

Examples

Real code examples live in the examples/ directory:

  • examples/restapi_foo_bar_service.py – a simple REST API service built with in-memory storage.

  • examples/dm_mysql_storage.py – data model with MySQL storage example.

  • examples/openapi_app.py – example API with OpenAPI specification generation.

Migration commands

RESTAlchemy provides command-line tools for managing database migrations.

<migration number>-<message>-<hash>.py
$ ra-rename-migrations -p <path-to-migrations>

Create migrations:

$ ra-new-migration --path examples/migrations/ --message "1st migration"
$ ra-new-migration --path examples/migrations/ --message "2st migration" --depend 1st
$ ra-new-migration --path examples/migrations/ --message "3st migration" --depend 2st
$ ra-new-migration --path examples/migrations/ --message "4st migration"
$ ra-new-migration --path examples/migrations/ --message "5st migration" --depend 3st --depend 4st

Apply migrations:

$ ra-apply-migration --path examples/migrations/ --db-connection mysql://test:test@localhost/test -m 5st
> upgrade 1st
> upgrade 2st
> upgrade 3st
> upgrade 4st
> upgrade 5st

Rolled back migrations:

$ ra-rollback-migration --path examples/migrations/ --db-connection mysql://test:test@localhost/test -m 4st
> downgrade 5st
> downgrade 4st
$ ra-rollback-migration --path examples/migrations/ --db-connection mysql://test:test@localhost/test -m 1st
> downgrade 3st
> downgrade 2st
> downgrade 1st

Tests

Tests are managed via tox. The default environment list includes Python 3.8, 3.10, 3.11, 3.12, 3.13 and 3.14.

Run the full test suite:

tox

Run tests for a specific Python version (for example, Python 3.10):

tox -e py310

Run functional tests (require access to a MySQL database):

export DATABASE_URI="mysql://root:@localhost:3306/radatabase"
tox -e py310-functional

Run functional tests with PostgreSQL:

export DATABASE_URI="postgresql://postgres:password@localhost:5432/radatabase"
tox -e py310-functional

Coverage

The current coverage percentage is shown by the badge at the top of this file. It is measured on every push by python-coverage-comment-action, which combines the unit and the MySQL and PostgreSQL functional suites of every supported Python version into one figure, with branch coverage enabled. The badge and the full HTML report are stored on the python-coverage-comment-action-data branch, and pull requests receive a comment describing how they change coverage. For reference, the unit suite alone covers roughly 75% of the restalchemy package.

Coverage measurement is wired into the default tox run. The begin environment erases previous data, every py3* environment records its own data file (.coverage.<envname>), and the end environment combines them into a single report:

tox

Reports are written to the cover/ directory (cover/index.html for the browsable HTML report and cover/coverage.xml for CI tools), and a summary of the files that are not fully covered is printed to the console.

To combine and render reports without re-running the tests (for example after tox -e py310):

tox -e end

To measure coverage for a single run directly, without tox:

pytest --cov --cov-report=term restalchemy/tests/unit

Use pytest --cov rather than coverage run: the suite runs under pytest-xdist, and coverage run does not measure the xdist worker processes, so it reports 0% coverage.

Coverage settings live in the [tool.coverage.*] sections of pyproject.toml: branch coverage is enabled, parallel data files are on so that several environments can be combined, restalchemy is the measured source, and the test packages themselves are excluded.

License

RESTAlchemy is licensed under the Apache License, Version 2.0.

Copyright (c) Genesis Corporation, 2025.

See the LICENSE file in this repository or https://www.apache.org/licenses/LICENSE-2.0 for the full license text.

Metadata

Release files for restalchemy 16.1.1

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

Source distribution (sdist)

Source distribution for restalchemy 16.1.1
File Size Uploaded
restalchemy-16.1.1.tar.gz 643.2 kB Details

Built distribution (wheel)

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

Total release size: 1.3 MB

Release files / restalchemy-16.1.1.tar.gz

Download URL restalchemy-16.1.1.tar.gz
Size 643.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4626e0f48cf3ae209e4c5f042f2a917221cced17841843bcc72f0283700a2458
BLAKE2b-256 checksum
How to use checksums
155747cd01b1696ef645e862f1948266abc68f367d07b3d376f5fa3c5239b620
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

Release files / restalchemy-16.1.1-py3-none-any.whl

Download URL restalchemy-16.1.1-py3-none-any.whl
Size 682.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
659ba3cec4dea8e22481baf16c798218f5f5bb8a630a1656c0368b88d589f1ca
BLAKE2b-256 checksum
How to use checksums
b5506be94a33da88883a0860b38ce7e56b09eda16e0b95f305f8ecf7def93635
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

Release history Release notifications | RSS feed

16.1.2

2 release files

This release

16.1.1 This release

2 release files

16.1.0

2 release files

16.0.7

2 release files

16.0.6

2 release files

16.0.5

2 release files

16.0.1

2 release files

16.0.0

2 release files

15.2.8

2 release files

15.2.7

2 release files

15.2.6

2 release files

15.2.5

2 release files

15.2.4

2 release files

15.2.3

2 release files

15.2.1

2 release files

15.2.0

2 release files

15.1.2

2 release files

15.0.9

2 release files

15.0.8

2 release files

15.0.7

2 release files

15.0.6

2 release files

15.0.3

2 release files

15.0.2

2 release files

15.0.1

2 release files

15.0.0

2 release files

14.7.0

2 release files

14.6.0

2 release files

14.5.0

2 release files

14.4.1

2 release files

14.4.0

2 release files

14.2.0

2 release files

14.1.6

2 release files

14.1.5

2 release files

14.1.4

2 release files

14.1.3

2 release files

14.1.2

2 release files

14.1.1

2 release files

14.1.0

2 release files

14.0.0

2 release files

13.0.1

2 release files

13.0.0

2 release files

12.9.0

2 release files

12.8.0

2 release files

12.7.0

2 release files

12.6.0

2 release files

12.5.1

2 release files

12.4.0

2 release files

12.3.1

2 release files

12.3.0

2 release files

12.2.0

2 release files

12.1.0

2 release files

12.0.0

2 release files

1.2.1

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