An extension of the Tiferet Framework for the Fast API.
Project description
Tiferet Fast - A FastAPI Extension for the Tiferet Framework
Introduction
Tiferet Fast elevates the Tiferet Python framework by enabling developers to build high-performance, asynchronous APIs using FastAPI, grounded in Domain-Driven Design (DDD) principles. Starting with v0.3, Tiferet Fast uses tiferet-openapi as the shared domain backbone for route configuration, Swagger metadata, and error-to-status-code mappings — leaving only FastAPI-specific concerns (builder assembly and context error handling) in this package.
For a deeper understanding of Tiferet's core concepts, refer to the Tiferet documentation.
Getting Started
Requirements
- Python 3.10 or later
- Tiferet >= 2.0.0b1
- Tiferet OpenAPI >= 0.1.2
Installation
pip install tiferet-fast
Architecture (v0.3.0)
Tiferet Fast v0.3 is a thin adapter layer. Domain objects, service interfaces, domain events, mappers, and repositories all live in tiferet-openapi. This package provides only:
- Builders (
tiferet_fast.builders) —FastApiBuilderextendsAppBuilderto assemble FastAPI applications fromApiRouter/ApiRoutedomain objects, with Swagger model resolution viaresolve_model(). - Contexts (
tiferet_fast.contexts) —FastApiContextextendsOpenApiContextwith FastAPI-specific error handling (convertsTiferetAPIErrortoHTTPException).FastRequestContextis an alias forOpenApiRequestContext.
All domain-layer concerns (routes, routers, request/response models, events, repos) are imported directly from tiferet_openapi.
Usage
Configuration
Tiferet v2 beta supports a consolidated config.yml at the project root:
interfaces:
calc_fast_api:
name: Calculator FastAPI
description: Arithmetic operations via FastAPI with Swagger docs
module_path: tiferet_fast.contexts.fast
class_name: FastApiContext
attrs:
get_routers_evt:
module_path: tiferet_openapi.events.openapi
class_name: GetRouters
get_route_evt:
module_path: tiferet_openapi.events.openapi
class_name: GetRoute
get_status_code_evt:
module_path: tiferet_openapi.events.openapi
class_name: GetStatusCode
openapi_service:
module_path: tiferet_openapi.repos.openapi
class_name: OpenApiYamlRepository
params:
openapi_yaml_file: config.yml
openapi:
routers:
calc:
prefix: /calc
routes:
add:
path: /add
methods: [POST]
status_code: 200
summary: Add two numbers
description: Adds two numbers and returns the result.
request_model: app.domain.request.TwoOperandRequest
response_model: app.domain.request.CalculatorResponse
errors:
DIVISION_BY_ZERO: 400
INVALID_INPUT: 422
Routes support Swagger metadata fields (summary, description, tags, request_model, response_model). The response_model is dynamically resolved by FastApiBuilder.resolve_model() and passed to FastAPI's add_api_route() for native Swagger schema generation.
Building and Running the API
from fastapi import Request
from tiferet_fast import FastApiBuilder
async def view_func(request: Request):
data = await request.json() if request.headers.get('content-type') == 'application/json' else {}
data.update(dict(request.query_params))
headers = dict(request.headers)
response, status_code = context.run(
feature_id=request.scope['route'].name,
headers=headers,
data=data,
)
return {'result': response}
# Create the builder and load configuration.
builder = FastApiBuilder()
builder.load_app_service(app_yaml_file='config.yml')
# Build the FastAPI application.
fast_app = builder.run('calc_fast_api', view_func)
# Access the context for the view function closure.
context = builder.load_interface('calc_fast_api')
Serve with uvicorn:
uvicorn calc_fast_api:fast_app --reload
Swagger UI is available at http://127.0.0.1:8000/docs.
Example
See the example/ directory for a complete calculator application demonstrating all v0.3 features.
Migration from v0.2.x
v0.3.0 removes all domain/interface/event/mapper/repo layers from this package in favor of tiferet-openapi:
tiferet_fast.domain— Removed. Usetiferet_openapi.domain(ApiRoute,ApiRouter,ApiRequestModel,ApiResponseModel).tiferet_fast.interfaces— Removed. Usetiferet_openapi.interfaces(OpenApiService).tiferet_fast.events— Removed. Usetiferet_openapi.events(GetRouters,GetRoute,GetStatusCode).tiferet_fast.mappers— Removed. Usetiferet_openapi.mappers.tiferet_fast.repos— Removed. Usetiferet_openapi.repos(OpenApiYamlRepository).fast.ymlconfig withfast:root key — Replaced byopenapi.ymlor consolidatedconfig.ymlwithopenapi:root key.FastApiContext— Now extendsOpenApiContext(fromtiferet_openapi) withhandle_error()convertingTiferetAPIErrortoHTTPException.FastRequestContext— Now an alias forOpenApiRequestContext.
License
MIT
Project details
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 tiferet_fast-0.3.0.tar.gz.
File metadata
- Download URL: tiferet_fast-0.3.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c19f79e0bcc8237a2ef95638305a15a89999833f5a945028af9973c25120c736
|
|
| MD5 |
3c34511f4f8bb729f9835e03a66e0c45
|
|
| BLAKE2b-256 |
e6c4d5012b1ec08b2e3603c9761465690ee2c397648ebab4da4d4e1238e7f83a
|
Provenance
The following attestation bundles were made for tiferet_fast-0.3.0.tar.gz:
Publisher:
python-publish.yml on greatstrength/tiferet-fast
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tiferet_fast-0.3.0.tar.gz -
Subject digest:
c19f79e0bcc8237a2ef95638305a15a89999833f5a945028af9973c25120c736 - Sigstore transparency entry: 1511264053
- Sigstore integration time:
-
Permalink:
greatstrength/tiferet-fast@41bbd4c56d445d87ff5b864f42baf83a13b722c7 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/greatstrength
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@41bbd4c56d445d87ff5b864f42baf83a13b722c7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file tiferet_fast-0.3.0-py3-none-any.whl.
File metadata
- Download URL: tiferet_fast-0.3.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfdcd805f5d31a4e3c0e0d4925310af5547fe0a1160d8c799583876ce1a42f9f
|
|
| MD5 |
16540463de681e031ffe8b3c815b4e57
|
|
| BLAKE2b-256 |
375fc4b5a74e7a1829208c0645ce3a41692a0f883332b7dbf075e2ce194668cc
|
Provenance
The following attestation bundles were made for tiferet_fast-0.3.0-py3-none-any.whl:
Publisher:
python-publish.yml on greatstrength/tiferet-fast
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tiferet_fast-0.3.0-py3-none-any.whl -
Subject digest:
cfdcd805f5d31a4e3c0e0d4925310af5547fe0a1160d8c799583876ce1a42f9f - Sigstore transparency entry: 1511264283
- Sigstore integration time:
-
Permalink:
greatstrength/tiferet-fast@41bbd4c56d445d87ff5b864f42baf83a13b722c7 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/greatstrength
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@41bbd4c56d445d87ff5b864f42baf83a13b722c7 -
Trigger Event:
release
-
Statement type: