Skip to main content

fsrest

fsrest extracts reusable single-resource REST CRUD orchestration from application code. It is framework-independent: request/response objects are Pydantic models, while persistence is supplied through a small DAO protocol.

Designed and developed by Codex.

Install

pip install fsrest

Python 3.9+ and Pydantic 1.10/2.x are supported.

Usage

Bind a DAO to RestCrudLogicBase. Request schemas provide the small conversion methods needed to turn HTTP-facing data into DAO fields.

from pydantic import BaseModel
from fsrest import RestCrudLogicBase, RestPageReqSchema, RestPageRespSchema

class Item(BaseModel):
    id: str
    name: str

class Filters(BaseModel):
    name: str | None = None

class Ordering(BaseModel):
    field: str = "id"

class PageData(BaseModel):
    items: list[Item]
    total: int

class ListQuery(RestPageReqSchema):
    name: str | None = None

    def build_filters(self) -> Filters:
        return Filters(name=self.name)

    def build_ordering(self) -> Ordering:
        return Ordering()

    def build_response(self, *, page_data: PageData) -> RestPageRespSchema[Item]:
        return RestPageRespSchema[Item](
            items=page_data.items,
            total=page_data.total,
            page=self.page,
            page_size=self.page_size,
        )

class ItemDao:
    @classmethod
    def list_schema_page(cls, *, filters, ordering, page, page_size) -> PageData:
        ...

    # Also implement get_schema_by_id, create_schema,
    # update_schema_by_id, and delete_by_id.

class ItemLogic(RestCrudLogicBase):
    dao_rest_crud = ItemDao

The library raises RestApiError for missing records and failed deletes. To integrate with an application's existing exception middleware, subclass it and bind error_class:

class ApplicationApiError(RestApiError):
    error_code = 400455

class ItemLogic(RestCrudLogicBase):
    dao_rest_crud = ItemDao
    error_class = ApplicationApiError

Development and publishing

From the pytools repository root, use the unified release script:

python make.py fsrest test
python make.py fsrest build
python make.py fsrest publish

publish uploads the artifacts under fsrest/dist/ using the PyPI credentials configured in ~/.pypirc. Before publishing a new release, update the version in pyproject.toml, run tests, and build fresh artifacts.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fsrest-0.1.1.tar.gz (30.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fsrest-0.1.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file fsrest-0.1.1.tar.gz.

File metadata

  • Download URL: fsrest-0.1.1.tar.gz
  • Upload date:
  • Size: 30.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.2

File hashes

Hashes for fsrest-0.1.1.tar.gz
Algorithm Hash digest
SHA256 438fc01ac50a8ffc96a33a66ae9df0f994bac0791cc1e7b42dd5e7e8b3534dc7
MD5 9c311f8d7ecbe662a35b9371da30e065
BLAKE2b-256 28cae66dc5a780c45ed12f82b6c65bbc60681db2e6aacee003b42a4b7049b9ad

See more details on using hashes here.

File details

Details for the file fsrest-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fsrest-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.2

File hashes

Hashes for fsrest-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 10774f61aee41f012dfd4a75d5fa65f06707a25d141713da8dcf690edc85bef9
MD5 31554694b5451c71cab395ed057babf0
BLAKE2b-256 e3ca38ccfefd1ebca9d30a9edbc2f89aa26d145b23f40234866068dbbed9a831

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

This release

0.1.1 This release

2 files

0.1.0

2 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