Skip to main content

sonnet-core

The framework-agnostic foundation beneath the sonnet packages. Data access, models and logic that behave identically in an HTTP handler, a CLI command, a worker or a test.

Version 0.2.0. No FastAPI, no Starlette, no uvicorn, no Typer -- that is the point of the package.

What it provides

  • Database -- pooled engines, the ambient session, transaction boundaries, Alembic helpers and advisory locks.
  • CRUD repository -- CrudRepository and CrudConfig: list, get, create, update and delete derived from a SQLModel table, including versioned entities.
  • Filtering -- a transport-neutral filter AST, declaration-driven validation, and compilation to SQLAlchemy.
  • Readiness pipeline -- the staged check engine and its registries, usable outside a server.
  • State machines -- declarative, serializable entity lifecycles with guards.
  • Resource layer -- ResourceSpec, one resource declaration that both REST and CLI adapters consume.
  • Service registry -- ServiceRegistry, type-keyed DI with singletons and factories.
  • Models and ids -- dynamic model building, record-to-response conversion, PageResult, time-sortable ids, JSON Schema validation, version ordering.
  • Exceptions -- the shared domain error vocabulary.

Install

uv add sonnet-core

Depends on pydantic, sqlmodel, sqlalchemy, alembic, tenacity, arrow, jsonschema and loguru. You supply the database driver; psycopg is the expected one. The only extra is dev.

Root re-export policy

Importing sonnet_core gives you the cheap things: ids, exceptions, model helpers, PageResult, ResourceSpec, ServiceRegistry. Three subpackages are deliberately not re-exported at the root, because importing them costs more than the always-on dependencies:

from sonnet_core.database import borrow_db_session
from sonnet_core.readiness_pipeline import readiness_check
from sonnet_core.utils.filtering import parse_query

A caller that wants only exceptions does not pay for engine setup.

Usage

A repository is a class with a configuration attribute; the query methods come from CrudRepository, and the session travels in a context variable rather than through every call.

from sonnet_core.database import borrow_db_session
from sonnet_core.database.crud import CrudConfig, CrudRepository


class WidgetService(CrudRepository[Widget, WidgetResponse]):
    crud_config = CrudConfig(
        db_model=Widget,
        response_model=WidgetResponse,
        lookup_field="slug",
        order_by="name",
    )


service = WidgetService()

with borrow_db_session():
    widget = service.get("sprocket")

The boundary owns the transaction -- nothing inside the block commits. See the usage guides for repositories, sessions, filtering, state machines and the readiness pipeline.

Documentation

The web layer that builds on this package is sonnet-server.

License

Apache 2.0 -- see LICENSE.md.

Metadata

Release files for sonnet-core 0.5.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sonnet-core 0.5.3
File Size Uploaded Provenance Actions
sonnet_core-0.5.3.tar.gz 105.1 kB With provenance Details for sonnet_core-0.5.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sonnet-core 0.5.3
File Interpreter ABI Platform Actions
sonnet_core-0.5.3-py3-none-any.whl Python 3 none any Details for sonnet_core-0.5.3-py3-none-any.whl

Total release size: 233.6 kB

Release files / sonnet_core-0.5.3.tar.gz

Download URL sonnet_core-0.5.3.tar.gz
Size 105.1 kB
Tags Source
SHA-256 checksum
How to use checksums
39770e95a3e4ab84961dbec4c8bb644b423d7e09cd3f20809c8fa2f60793721a
BLAKE2b-256 checksum
How to use checksums
5fd64f2282ab7a5e56f729931232d99c5e1fdba04bcbcc1390c7980d8da3b6e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / sonnet_core-0.5.3-py3-none-any.whl

Download URL sonnet_core-0.5.3-py3-none-any.whl
Size 128.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc748ca7b3efc926147c62af1c516e33a038cd8c4d35f43d3ccdf5e003a89959
BLAKE2b-256 checksum
How to use checksums
fe5ae63188b2baaeff02f49018648ca9d7b6117df775ea75d9b929ed42f79481
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Security for sonnet-core 0.5.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sonnet_core-0.5.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page