Helper library that provides common functionality for bootstrapping tomodachi services
Table of Contents
-
Service configuration from environment variables with Pydantic-Settings
-
structlog logging middleware
-
Correlation ID middleware
-
Tomodachi base service class
-
Create your tomodachi service by inheriting from the
TomodachiServiceBase
class
from tomodachi_bootstrap import TomodachiServiceBase
class TomodachiService(TomodachiServiceBase):
name = "service-example"
-
Extend base
Pydantic-Settings
configuration class with your own configuration class
from functools import lru_cache
from tomodachi_bootstrap import TomodachiBaseSettings
class Settings(TomodachiBaseSettings):
dynamodb_orders_table_name: str
dynamodb_inbox_table_name: str
dynamodb_outbox_table_name: str
@lru_cache
def get_settings() -> Settings:
return Settings() # type: ignore
-
TomodachiServiceBase
base configures structlog logger.
import structlog
logger: structlog.stdlib.BoundLogger = structlog.get_logger()
logger.info("Hello, World!", foo="bar")
-
Install dev dependencies with Poetry
poetry install
poetry shell
pre-commit install
-
Run tests
pytest
poetry run test-ci
-
Format and lint code
poetry run format
poetry run lint
-
Run all commit hooks at once
poetry run hooks
-
Build package release
poetry build