Lato is a Python microframework for building modular monoliths and loosely coupled applications. It implements CQRS patterns with Commands, Queries, and Events, dependency injection, and transaction contexts.
- Author: Przemyslaw Gorecki
- License: MIT
- Docs: https://lato.readthedocs.io
- PyPI: https://pypi.org/project/lato/
- Application (
lato/application.py): Top-level entry point, extendsApplicationModule - ApplicationModule (
lato/application_module.py): Registers handlers, supports nested submodules - TransactionContext (
lato/transaction_context.py): Scoped context for handler execution with middleware support - DependencyProvider (
lato/dependency_provider.py): Automatic dependency injection by name or type - Messages (
lato/message.py):Command,Query,Eventbase classes (all extendMessage) - Exceptions (
lato/exceptions.py): All custom exceptions in one place
- Command/Query: One handler per message type per module. Registering a second raises
DuplicateHandlerError. Multiple modules can each have one handler for the same Command/Query (results get composed). - Event: Multiple handlers allowed per module (pub/sub pattern).
app.call(func_or_alias)— invoke a single function or aliasapp.execute(command)— execute all handlers for a Command/Query, compose resultsapp.publish(event)— publish to all Event handlers, return dict of results- All three have
_asyncvariants
poetry install --without examplespoetry run python -m pytest -p no:sugar -q tests/poetry run mypy latopoetry run pytest --doctest-modules latopoetry run sphinx-build -b html docs docs/_buildThe project uses pre-commit hooks: isort, black, autoflake, and type hint upgrades. If a commit fails due to hooks, re-stage the auto-fixed files and commit again (new commit, not amend).
- Triggers on: push to
main, pull requests - Matrix: Ubuntu/MacOS/Windows x Python 3.9/3.10/3.11/3.12
- Python 3.9 jobs use Poetry 1.8.5 (Poetry 2.x requires Python 3.10+)
- Python 3.10+ jobs use latest Poetry 2.x
- Lock file check:
poetry lock --check(Poetry 1.x) orpoetry check --lock(Poetry 2.x)
- Triggers on: tag push matching
v*.*.* - Waits for Tests workflow to pass before publishing
- Uses Python 3.12 for build/publish
- Publishes to PyPI via
poetry publish
- Create a release branch (e.g.
release/0.13.0) - Bump version in
pyproject.toml,lato/__init__.py, andCHANGELOG.md - Update
poetry.lockif dependencies changed (poetry lock) - Push branch, open PR, wait for tests to pass
- Squash merge the PR
- Pull main, tag (
git tag v0.13.0), push tag - The tag push triggers the Release workflow
Version must be kept in sync in three places:
pyproject.toml(version = "...")lato/__init__.py(__version__ = "...")CHANGELOG.md(new entry at top)
- Imports sorted by
isort, formatted byblack - Type hints used throughout
- Custom exceptions inherit from the closest built-in (
TypeError,LookupError,KeyError) - All custom exceptions live in
lato/exceptions.pyand are exported fromlato/__init__ - Docstrings use Sphinx
:param:,:return:,:raises:format