- Python 96.4%
- Dockerfile 2.2%
- Mako 1.4%
| .devcontainer | ||
| .vscode | ||
| py3tier | ||
| table_definitions | ||
| .gitignore | ||
| alembic.ini | ||
| pyproject.toml | ||
| README.md | ||
| uv.lock | ||
py3tier
Generic toolkit for building 3-tier applications.
YAML table definitions
Tables can be generated from a small YAML definition containing a class name,
an optional table name, and fields aligned with sqlmodel.Field options:
name: User
table: users
fields:
display_name:
type: str
max_length: 100
nullable: false
An integer id primary key is added automatically and is generated when a
row is inserted. Each row also receives a generated UUID uid; the same value
is available in the corresponding history row.
from py3tier.application.data_models import load_table_class
User, UserHistory = load_table_class("user.yaml")
UserHistory contains nullable snapshots of all User columns, an automatic
hid primary key, event_on, operation, audit_uid, revision, and
sha256_all and sha256_data snapshot hashes. revision defaults to 0 for
the initial snapshot; the persistence layer should increment it for later
snapshots of the same row.
Supported field types are bool, date, datetime, decimal, float,
int, str, time, and uuid. Relations and foreign keys are not part of
this format yet.
Database migrations
Alembic loads application-owned YAML definitions from
py3tier/table_definitions/ and user-owned definitions from the top-level
table_definitions/ before generating migrations, including each table's
history table. The default database is
sqlite:///./py3tier.db; set PY3TIER_DATABASE_URL to override it.
The user definition folder can be changed with
USER_TCLASS_DEFINITIONS_DIR.
uv run alembic revision --autogenerate -m "create tables"
uv run alembic upgrade head