SAFRS
Expose SQLAlchemy models as JSON:API resources and generate API documentation with minimal boilerplate.
SAFRS is built around SQLAlchemy models and JSON:API-style resource handling. The repository includes FastAPI and Flask adapters.
Start here
Functionality
- JSON:API collection and instance endpoints for SQLAlchemy models
- relationship endpoints and
includesupport - filtering, sorting, pagination, sparse fieldsets, and bulk request support
- custom RPC methods with
@jsonapi_rpc - generated Swagger / OpenAPI documentation
- serialization hooks, computed attributes, and model-level customization
- stateless service-style endpoints through
JABase
Install
SAFRS currently requires Python >=3.10.
Install from PyPI:
pip install safrs
Editable install from a clone:
git clone https://github.com/thomaxxl/safrs
cd safrs
python -m venv venv
source venv/bin/activate
pip install -e .
For the broader example set, including auth and admin examples:
pip install -r examples/requirements.txt
More setup details: Installation wiki page
Quick start from this repository
SAFRS models inherit both SAFRSBase and the SQLAlchemy model base. You then expose them with:
SafrsApi(...).expose_object(Model)for FlaskSafrsFastAPI(...).expose_object(Model)for the FastAPI adapter
Run the smallest Flask example:
python examples/mini_app.py
Run the smallest FastAPI example:
python examples/mini_fastapi_app.py
Quickstarts and walkthroughs:
Example files worth opening first
examples/mini_app.py— smallest Flask exampleexamples/demo_relationship.py— relationships and includesexamples/mini_fastapi_app.py— smallest FastAPI exampleexamples/demo_fastapi.py— fuller FastAPI demoexamples/demo_pythonanywhere_com.py— broader Flask showcaseexamples/demo_stateless.py— stateless / non-SQLAlchemy-style resource example
The full examples index is in the wiki: Examples
Documentation map
Getting started:
Core JSON:API behavior:
- JSON:API basics
- Relationships and includes
- Filtering
- Sorting, pagination, and sparse fieldsets
- Content types and errors
- Bulk requests
Customization and extension:
- RPC / custom methods
- HTTP methods and hooks
- Endpoint decorators
- Serialization and
jsonapi_attr - Security and access control
- Configuration reference
Advanced topics:
Notes
- Flask is still the main documented SAFRS path.
- The FastAPI adapter exists in the repository and is documented, but it should still be treated as experimental.
- The older expose-existing-database workflow is no longer the main recommended entry point and is kept as legacy documentation.
SAFRS originally stood for SqlAlchemy Flask-Restful Swagger. The project has since grown beyond the original Flask-only framing, but the historical name remains.
Metadata
Release files for safrs 3.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| safrs-3.2.0.tar.gz | 139.8 kB | Without provenance | Details for safrs-3.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| safrs-3.2.0-py3-none-any.whl | Python 3 | none | any | Details for safrs-3.2.0-py3-none-any.whl |
Total release size: 277.3 kB
Release files / safrs-3.2.0.tar.gz
| Download URL | safrs-3.2.0.tar.gz |
|---|---|
| Size | 139.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
19cdce80fd0abc17320b313ba61721c0e3591b56aa16ff424efbb1f3bc43f73c
|
|
BLAKE2b-256 checksum How to use checksums |
240030427071b9041fdac187f10ede8b189d5b296feb17fe3a406c56fea8bd22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / safrs-3.2.0-py3-none-any.whl
| Download URL | safrs-3.2.0-py3-none-any.whl |
|---|---|
| Size | 137.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ab0b9e52534b40c6b4617d05a7a362695a536843c4b9f6597dd6547bbd25736e
|
|
BLAKE2b-256 checksum How to use checksums |
c311cd15c93da768cb45434e85f410e672543e8e18821e7b776269bebbc35786
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for safrs 3.2.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.