Awesome
Python Polylith Example
This is a repository with an example Python
setup of the Polylith Architecture.
Here you will find examples of code being shared between different kind of projects, and the developer tooling setup.
Developer experience
Mypy
Have a look at the mypy.ini
configuration file, to make Mypy
work really well with this type of architecture.
[mypy]
mypy_path = components, bases
namespace_packages = True
explicit_package_bases = True
The "loose" theme
This repository is setup with the loose
theme, a Python exclusive addition to the architecture.
The theme is about the folder structure of components:
components/<namespace>/<name>
, and a separate tests
top folder.
Currently, there is poor support in Mypy for the original Polylith component structure:
components/<name>/<src or test>/<namespace>/<name>/
With the original Polylith structure, you will have to explicitly add each component path to the mypy_path
.
There is a feature request in the mypy repo about adding regex support to the mypy_path
property.
Hopefully it will be implemented in the future. :pray:
.venv
It is recommended to create the virtual environment locally, for a great code editor experience.
By default, Poetry
will create a venv
outside of the repo. You can override that behaviour by adding a configuration in a poetry.toml
file:
[virtualenvs]
path = ".venv"
in-project = true
Tooling support
There's tooling support for using Polylith in Python. Have a look at this repository: Python tools for the Polylith Architecture
Tests
Run tests with:
poetry run pytest
Deployment
The projects contain examples for packaging and deploying APIs and handlers with docker, AWS Lambdas and GCP functions.
Kubernetes
The "My FastAPI project" includes an example setup for deploying into a Kubernetes cluser, by using kustomize to configure the deployments.
Have a look at the project-specific and the shared configurations.
The configuration is structured as:
- basic setup for all types of deployments
- with overlays for different environments (development, staging, production)
- service-specific setup, with overlays
- APIs
- handlers
- project-specific setup, with overlays