Skip to main content

xtr-service-contracts

What a container drives, not what a service does.

python 3.11+ core dependencies: 0 typed license MIT

Why?

A service's own contract says what it is for — a logger logs, a lock locks, a bus dispatches. This package holds the other kind: what something built by a container must answer to so the container can manage it, whatever it is for.

Keeping the two apart matters. reset() is not a logging idea, so a logging contract that ships it makes every consumer of that contract inherit a concern belonging to the container. Here it is declared once, and any contract or library that needs it depends on a package with no dependencies at all.

That last part is the whole design: this is a leaf, and it should stay one. Every other contract package in the ecosystem is free to depend on it, which only remains true while nothing here can drag anything in.

Install

uv add xtr-service-contracts

Requires Python 3.11+.

ResettableInterface

@runtime_checkable
class ResettableInterface(Protocol):
    def reset(self) -> None: ...

A long-running process — a worker consuming messages, a server answering requests — builds its services once and uses them many times. Buffers, caches, accumulated state and generated ids belong to one unit of work rather than to the service holding them. reset() ends that unit, so the next starts clean while configuration survives:

from xtr_service_contracts import ResettableInterface


class Buffer:
    def __init__(self, capacity: int) -> None:
        self.capacity = capacity  # configuration — survives
        self.items: list[str] = []  # this unit of work — does not

    def reset(self) -> None:
        self.items.clear()


assert isinstance(Buffer(10), ResettableInterface)

The protocol is structural and @runtime_checkable, so nothing has to inherit from it — a class that already has a reset() satisfies it as it stands. A container is the usual caller: it knows what it built, so it can reset whatever asks for it between units of work, and neither side has to know anything else about the other.

for service in container.services:
    if isinstance(service, ResettableInterface):
        service.reset()

Who uses it

Package Uses it for
xtr-logging Buffered and fingers-crossed handlers, generated ids, and LoggerFactory.reset() between requests or messages

Development

Developed in the python-xtr monorepo, under packages/xtr-service-contracts; run the commands below from there. The python-xtr-service-contracts repository is a read-only copy, so send issues and pull requests to the monorepo.

uv sync
uv run ruff check . && uv run ruff format --check .
uv run basedpyright
uv run ty check
uv run pytest

License

MIT — see LICENSE.

Release files for xtr-service-contracts 1.0.1

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

Source distribution (sdist)

Source distribution for xtr-service-contracts 1.0.1
File Size Uploaded
xtr_service_contracts-1.0.1.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xtr-service-contracts 1.0.1
File Interpreter ABI Platform
xtr_service_contracts-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / xtr_service_contracts-1.0.1.tar.gz

Download URL xtr_service_contracts-1.0.1.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e18d103d46e3de1f1e0f71a5362baa2f570f702a3f10dcd944cb16c07ae732fd
BLAKE2b-256 checksum
How to use checksums
6b5f58087a6ab4fe6b5ad7c539bf0204051779502b19d71e5ff99e9e4ba96240
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 25, 2026.

Transparency log

Release files / xtr_service_contracts-1.0.1-py3-none-any.whl

Download URL xtr_service_contracts-1.0.1-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
899a26515a8d429db29a40e6dc1124b12f7f1d5673c1f6c22910917b94e36bc7
BLAKE2b-256 checksum
How to use checksums
3e4992999de165c7d743d79b8517e8d48ca575ae17a01cf59f27641de5de4acc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 25, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

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