SAFRS : SqlAlchemy Flask-Restful Swagger
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file safrs-3.2.0.tar.gz.
File metadata
- Download URL: safrs-3.2.0.tar.gz
- Upload date:
- Size: 139.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19cdce80fd0abc17320b313ba61721c0e3591b56aa16ff424efbb1f3bc43f73c
|
|
| MD5 |
99a277691279768bfbcb9c30b7ce7ca8
|
|
| BLAKE2b-256 |
240030427071b9041fdac187f10ede8b189d5b296feb17fe3a406c56fea8bd22
|
File details
Details for the file safrs-3.2.0-py3-none-any.whl.
File metadata
- Download URL: safrs-3.2.0-py3-none-any.whl
- Upload date:
- Size: 137.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab0b9e52534b40c6b4617d05a7a362695a536843c4b9f6597dd6547bbd25736e
|
|
| MD5 |
2ed95cdc47669d7701d9540815cca2e2
|
|
| BLAKE2b-256 |
c311cd15c93da768cb45434e85f410e672543e8e18821e7b776269bebbc35786
|