You deserve a...
Project description
QuickRest
A schema-first CRUD-generation framework for FastAPI and SQLAlchemy so your team can put your feet up (or get back to the interesting stuff).
Full Documentation: lucaskruitwagen.github.io/quickrest
Issues and Feature Requests: github.com/Lkruitwagen/quickrest/issues
Features
- Mixins classes for SQLAlchemy declarative ORM classes that automatically build
create,read,update,delete, andsearch(CRUD+Search) FastAPI endpoints and Pydantic models. - Full exposure of joined tables, either via serialized related objects or additional
GET <resource>/<id>/<relationship>routes - Route-level protections via standard dependency injection
- Row-level fine-grained access control via developer-defineable user generation
- Many additional configuration options available via
<Method>Configclasses
See docs for more.
Installation
QuickRest is available from the python package index: pip install quickrest.
Quickstart
Simple mixin the Resource class with your ORM classes and you're good to go.
Define some environment variables to set the default sessionmaker and user generator for the Resource class ()or use the build_resource method.
Mixin the User, Private (via make_private), and Publishable (via make_publishabe) classes to add fine-grained access control.
Check the docs for the full range of customisation options.
from datetime import date
from typing import Optional
import uvicorn
from fastapi import FastAPI
from sqlalchemy import ForeignKey
from sqlalchemy.orm import Mapped, mapped_column, relationship
from quickrest import (
Base,
ReadConfig,
ResourceConfig,
RouterFactory,
SearchConfig,
Resource,
)
class Owner(
Base,
Resource,
):
__tablename__ = "owners"
first_name: Mapped[str] = mapped_column()
last_name: Mapped[str] = mapped_column()
pets: Mapped[list["Pet"]] = relationship(back_populates="owner")
certifications: Mapped[list["Certification"]] = relationship(
secondary="owner_certifications",
)
class resource_cfg(ResourceConfig):
serialize = ["certifications"]
class read_cfg(ReadConfig):
# choose which relationships should be accessible via URL /<resource>/<id>/<relationship>
routed_relationships = ["pets"]
class Specie(
Base,
Resource,
):
__tablename__ = "species"
common_name: Mapped[str] = mapped_column()
scientific_name: Mapped[str] = mapped_column()
class Pet(Base, Resource):
__tablename__ = "pets"
# note: all Resource classes have an id and slug column by default
name: Mapped[str] = mapped_column()
vaccination_date: Mapped[Optional[date]] = mapped_column(nullable=True)
species_id: Mapped[int] = mapped_column(ForeignKey("species.id"))
owner_id: Mapped[int] = mapped_column(ForeignKey("owners.id"))
owner: Mapped["Owner"] = relationship()
specie: Mapped["Specie"] = relationship()
notes: Mapped[list["Note"]] = relationship()
class resource_cfg(ResourceConfig):
# choose which relationships should be serialized on the reponse
serialize = ["specie"]
class search_cfg(SearchConfig):
search_gte = ["vaccination_date"] # greater than or equal to, list[str] | bool
search_lt = ["vaccination_date"] # less than, list[str] | bool
class Note(Base, Resource):
__tablename__ = "notes"
text: Mapped[str] = mapped_column()
pet_id: Mapped[int] = mapped_column(ForeignKey("pets.id"))
class Certification(
Base,
Resource,
):
__tablename__ = "certifications"
# note: all Resource classes have an id and slug column by default
name: Mapped[str] = mapped_column()
description: Mapped[str] = mapped_column()
class OwnerCertifications(Base):
__tablename__ = "owner_certifications"
owner_id: Mapped[int] = mapped_column(ForeignKey("owners.id"), primary_key=True)
certification_id: Mapped[int] = mapped_column(
ForeignKey("certifications.id"), primary_key=True
)
# instantiate a FastAPI app
app = FastAPI(title="QuickRest Quickstart", separate_input_output_schemas=False)
# build create, read, update, delete routers for each resource and add them to the app
RouterFactory.mount(app, [Owner, Pet, Specie, Note, Certification])
if __name__ == "__main__":
# Base.metadata.create_all(Resource._sessionmaker.kw.get("bind")) # uncomment this line to create the tables in db backend
uvicorn.run(app, host="0.0.0.0", port=8000)
Contributing
Contributions welcome!
To set up for development simply clone the repo and then:
pip install -e .[dev]
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 fastapi_quickrest-0.0.0.tar.gz.
File metadata
- Download URL: fastapi_quickrest-0.0.0.tar.gz
- Upload date:
- Size: 27.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50dedfd8ce90c7e18b0c279f7f26886824254af0fdf018cc76b678b076c980fe
|
|
| MD5 |
a8409ae22437439c896b6c91f270584e
|
|
| BLAKE2b-256 |
e15f2cd7aa4da9abf0eba38a2932e79dd897909bdeca91b5f30e6dded4c51926
|
Provenance
The following attestation bundles were made for fastapi_quickrest-0.0.0.tar.gz:
Publisher:
release-pypi.yaml on Lkruitwagen/quickrest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_quickrest-0.0.0.tar.gz -
Subject digest:
50dedfd8ce90c7e18b0c279f7f26886824254af0fdf018cc76b678b076c980fe - Sigstore transparency entry: 160118804
- Sigstore integration time:
-
Permalink:
Lkruitwagen/quickrest@65af2d3368fdb0e41b6778d89c8ba4ca95d3812d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Lkruitwagen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yaml@65af2d3368fdb0e41b6778d89c8ba4ca95d3812d -
Trigger Event:
release
-
Statement type:
File details
Details for the file fastapi_quickrest-0.0.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_quickrest-0.0.0-py3-none-any.whl
- Upload date:
- Size: 39.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6927d0eb69746b328f1038230a26953575d2503afc1d9333562f9669c4c003b
|
|
| MD5 |
f0d894baff927f6ebe9f91529461aa1e
|
|
| BLAKE2b-256 |
c70760b4450050629fd54c68049dd93be7895f79c942bdad3e92062ed1c4a3d2
|
Provenance
The following attestation bundles were made for fastapi_quickrest-0.0.0-py3-none-any.whl:
Publisher:
release-pypi.yaml on Lkruitwagen/quickrest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_quickrest-0.0.0-py3-none-any.whl -
Subject digest:
f6927d0eb69746b328f1038230a26953575d2503afc1d9333562f9669c4c003b - Sigstore transparency entry: 160118805
- Sigstore integration time:
-
Permalink:
Lkruitwagen/quickrest@65af2d3368fdb0e41b6778d89c8ba4ca95d3812d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Lkruitwagen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yaml@65af2d3368fdb0e41b6778d89c8ba4ca95d3812d -
Trigger Event:
release
-
Statement type: