Tiferet Flask - A Flask Extension for the Tiferet Framework
Introduction
Tiferet Flask extends the Tiferet Python framework to build Flask-based APIs using Domain-Driven Design (DDD). It uses tiferet-openapi as its domain backbone, providing a thin Flask integration layer on top of the shared OpenAPI abstraction.
Key components:
build_flask_app/FlaskApp— assembles a Flask app fromApiRouter/ApiRoutedomain objects using blueprint functions.FlaskApiContext— extendsOpenApiContextwith Swagger UI support.FlaskRequestContext— alias forOpenApiRequestContextwith Pydantic serialization.
Getting Started
Prerequisites
- Python 3.10+
- A virtual environment (recommended)
Installation
pip install tiferet-flask
This installs tiferet-openapi (which transitively provides tiferet) along with Flask and Flask-CORS.
Project Structure
project_root/
├── calc_flask_api.py
└── app/
├── events/
│ ├── __init__.py
│ └── calc.py
└── configs/
├── app.yml
├── openapi.yml
├── container.yml
├── error.yml
└── feature.yml
Configuration
App Interface (app/configs/app.yml)
Define the Flask API interface using tiferet-openapi types:
interfaces:
calc_flask_api:
name: Calculator Flask API
description: Arithmetic operations via Flask API
module_path: tiferet_flask.contexts.flask
class_name: FlaskApiContext
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: app/configs/openapi.yml
OpenAPI Configuration (app/configs/openapi.yml)
Define routers, routes, and error status codes using the openapi: root key:
openapi:
routers:
calc:
prefix: /calc
routes:
add:
path: /add
methods: [POST, GET]
status_code: 200
subtract:
path: /subtract
methods: [POST, GET]
status_code: 200
divide:
path: /divide
methods: [POST, GET]
status_code: 200
sqrt:
path: /sqrt
methods: [POST, GET]
status_code: 200
errors:
DIVISION_BY_ZERO: 400
INVALID_INPUT: 422
Usage
Entry Point (calc_flask_api.py)
from tiferet_flask import FlaskApp
# Define the view function.
def view_func(**kwargs):
from flask import request, jsonify
data = dict(request.json) if request.is_json else {}
data.update(dict(request.args))
data.update(kwargs)
headers = dict(request.headers)
response, status_code = context.run(
feature_id=request.endpoint,
headers=headers,
data=data,
)
return jsonify(response), status_code
# Build the Flask app with Swagger UI enabled.
flask_app = FlaskApp('calc_flask_api', view_func, swagger=True)
if __name__ == '__main__':
flask_app.run(host='127.0.0.1', port=5000, debug=True)
Endpoints
# Add two numbers
curl -X POST http://127.0.0.1:5000/calc/add \
-H "Content-Type: application/json" -d '{"a": 1, "b": 2}'
# Output: 3
# Square root
curl -X POST http://127.0.0.1:5000/calc/sqrt \
-H "Content-Type: application/json" -d '{"a": 16}'
# Output: 4.0
# Division by zero
curl -X POST http://127.0.0.1:5000/calc/divide \
-H "Content-Type: application/json" -d '{"a": 5, "b": 0}'
# Output: {"error_code": "DIVISION_BY_ZERO", ...}
Swagger UI
When swagger=True is passed to FlaskApp(), Swagger UI is available at:
- Swagger UI:
http://127.0.0.1:5000/docs - OpenAPI spec:
http://127.0.0.1:5000/docs/openapi.json
Architecture
Tiferet Flask v1.0.0 delegates all domain, interface, event, mapper, and repository concerns to tiferet-openapi. Only two packages remain under tiferet_flask/:
blueprints/— Stateless blueprint functions (build_flask_app,build_blueprint,get_routers,run) that consumeApiRouter/ApiRoutefrom tiferet-openapi, map them to Flask Blueprints, and optionally register a Swagger UI blueprint. Exported asFlaskAppalias.contexts/—FlaskApiContextis a thin subclass ofOpenApiContextthat addscreate_swagger_blueprint().FlaskRequestContextis an alias forOpenApiRequestContext.
For domain-level documentation (domain objects, events, mappers, repositories), see tiferet-openapi.
Migration from v0.4.x
- Builders → Blueprints: The
FlaskAppBuilderclass has been replaced by stateless blueprint functions.FlaskAppBuilder()→build_flask_app()/FlaskApp(). No more class instantiation — call the function directly. - Imports:
from tiferet_flask import FlaskAppBuilder→from tiferet_flask import FlaskApp(orbuild_flask_app). - Usage:
builder = FlaskAppBuilder(); builder.run(...)→flask_app = FlaskApp(interface_id, view_func, swagger=True). - Dependencies: The direct
tiferet>=2.0.0b1dependency has been removed. Tiferet is now provided transitively throughtiferet-openapi>=0.1.3.
Example
See the example/ directory for a complete calculator Flask API demonstrating the v1.0.0 architecture with Swagger support.
License
MIT
Metadata
Release files for tiferet-flask 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tiferet_flask-1.0.0.tar.gz | 474.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tiferet_flask-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 951.4 kB
Release files / tiferet_flask-1.0.0.tar.gz
| Download URL | tiferet_flask-1.0.0.tar.gz |
|---|---|
| Size | 474.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
49e580eb396c1f397dcf52c6b08beb872392f7ef65b234d097ef2d3b88c59cb5
|
|
BLAKE2b-256 checksum How to use checksums |
a8ede9d5133bcf4570b472b59e0771b250e1c958e8eadf1b5b31226624f97f89
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.
Transparency logRelease files / tiferet_flask-1.0.0-py3-none-any.whl
| Download URL | tiferet_flask-1.0.0-py3-none-any.whl |
|---|---|
| Size | 476.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3eaa7ea84026b46856f9a4d8cf456cbcf343db96d5149d49b1a0f937f771817f
|
|
BLAKE2b-256 checksum How to use checksums |
8d105b854e4a4a76650c6a4b2686ca2654ae89d037e08ec7eaed0aa6828ee889
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.
Transparency log