Skip to content

thomaxxl/safrs

Repository files navigation

Latest Version Supported Python versions License: GPL v3 Python application Codacy Badge Downloads

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, it includes FastAPI and Flask adapters.

Check out the Live Demo!

SAFRS demo

Start here

Functionality

  • JSON:API collection and instance endpoints for SQLAlchemy models
  • relationship endpoints and include support
  • 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 Flask
  • SafrsFastAPI(...).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

The full examples index is in the wiki: Examples

Documentation map

Getting started:

Core JSON:API behavior:

Customization and extension:

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.

Packages

 
 
 

Contributors

Languages