Skip to main content

Domain-service foundation for Petrarca Labs backend services

Project description

Sonnet Server

Domain-service foundation for Petrarca backend services. Provides the infrastructure layer that every backend service inherits: FastAPI app factory, extension-based lifecycle, database connectivity, messaging, caching, DI, readiness pipeline, guards, CLI framework, and system endpoints.

What it provides

  • Extension protocol -- opt-in subsystem lifecycle (database, messaging, cache, profiles). Infrastructure and profile extensions with conditional startup and router mounting.
  • Database -- engine management, ambient sessions, CRUD repository, Alembic utilities, advisory locks.
  • Messaging -- content-based router with pluggable channels (Postgres LISTEN/NOTIFY, NATS, in-process), CloudEvents envelope, @handles decorator.
  • Cache -- managed cache with pluggable backends (local, distributed, near-cache), cross-process invalidation via messaging.
  • Readiness pipeline -- composable health check stages with decorator-based auto-discovery.
  • Guards -- protocol-based authentication and tenant context validation.
  • DI -- type-keyed service registry with factory and singleton patterns.
  • CLI -- Typer-based framework with reusable db check / db upgrade commands.
  • System endpoints -- /ping, /version, /health-check, plus extension-contributed routes (/messaging, /cache).

Prerequisites

  • Python 3.14+
  • Task (task runner)
  • uv (Python package manager)

Setup

Situation Command
Fresh clone task install
After git pull (no dep changes) task sync
After editing pyproject.toml task install
Upgrade deps to latest task upgrade → commit uv.lock

This package is part of the sonnet-server workspace. See the workspace root for setup instructions.

Development

From the package directory (packages/sonnet-server/):

task fct            # format, check, test
task test           # tests only
task test:unit      # unit tests only

Or from the workspace root:

task fct            # all packages

Consumer usage

Dependency

Add to your project's pyproject.toml:

[project]
dependencies = [
    "sonnet-server[all]>=0.1.8",
]

For local co-development, add an editable source override:

[tool.uv.sources]
sonnet-server = { path = "../sonnet-server/packages/sonnet-server", editable = true }

Settings

Subclass Settings with your own env prefix. Call init_settings() at the bottom of your settings module to register with sonnet-server:

# my_app/settings.py
from functools import lru_cache
from pydantic_settings import SettingsConfigDict
from sonnet_server.settings import Settings as SonnetSettings, init_settings

class Settings(SonnetSettings):
    model_config = SettingsConfigDict(env_prefix="MY_APP_", ...)
    # project-specific fields here

@lru_cache
def get_settings() -> Settings:
    return Settings()

init_settings(get_settings())

All sonnet-server infrastructure (database, messaging, cache, checks) will then read from MY_APP_* env vars.

License

Apache License 2.0. See LICENSE.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sonnet_server-0.2.1.tar.gz (160.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sonnet_server-0.2.1-py3-none-any.whl (210.0 kB view details)

Uploaded Python 3

File details

Details for the file sonnet_server-0.2.1.tar.gz.

File metadata

  • Download URL: sonnet_server-0.2.1.tar.gz
  • Upload date:
  • Size: 160.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sonnet_server-0.2.1.tar.gz
Algorithm Hash digest
SHA256 fdc5f68c4cbbe40ae6c9ed4b8b7ed55f5eaadd2d45ca48e662642e3c96b9fc69
MD5 bf2b5f8fff6db93b7363686e40602826
BLAKE2b-256 c5b90dc448e2a870bb2f9bdc53b9aed3e3d3c937491ac32b81d0d7dad0a6d804

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonnet_server-0.2.1.tar.gz:

Publisher: publish.yml on petrarca/sonnet-server

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sonnet_server-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: sonnet_server-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 210.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sonnet_server-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fac8b44c24e28d5b297208fcba6ecbb8ce78ad567a45a83c24da47b3c9763603
MD5 56a963f3a7056f33ada364ad4e8670ce
BLAKE2b-256 d385ab0f51816e6bb526d2f98df7d5abc04758d83c984538d23c4716064d31ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonnet_server-0.2.1-py3-none-any.whl:

Publisher: publish.yml on petrarca/sonnet-server

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page