Service Registrar
A small provider registry for Python libraries that depend on services through ports (interfaces) while allowing adapters to be supplied by independently installed packages.
Define a port and inject an adapter
Keep the port in the library that needs the service. Construct the library with the selected adapter rather than having it discover or instantiate providers:
from typing import Protocol
class ObjectStore(Protocol):
def read(self, key: str) -> bytes: ...
class Catalog:
def __init__(self, store: ObjectStore) -> None:
self._store = store
# The composition root chooses the implementation and injects it.
catalog = Catalog(store=registry.create(ObjectStore, provider="filesystem"))
Publish a provider plugin
A provider package exports a Provider registration whose service is the
consumer's port and whose factory creates the adapter:
from collections.abc import Mapping
from service_registrar import Provider, ProviderRegistry
from my_library.ports import ObjectStore
class FilesystemStore:
def __init__(
self,
*,
config: Mapping[str, object],
registry: ProviderRegistry,
) -> None:
self._root = str(config["root"])
self._registry = registry
def read(self, key: str) -> bytes:
...
FILESYSTEM_STORE = Provider(service=ObjectStore, factory=FilesystemStore)
Declare that registration in the provider package's pyproject.toml:
[project.entry-points."service_registrar.providers"]
filesystem = "my_store_plugin:FILESYSTEM_STORE"
The application discovers installed plugins and explicitly selects a provider when composing the library:
from service_registrar import get_registry
registry = get_registry()
catalog = Catalog(store=registry.create(ObjectStore, provider="filesystem"))
get_registry() returns a process-wide singleton. Plugin discovery is lazy:
the first create() or dump() call discovers installed entry points once.
Use ProviderRegistry(...) directly when an isolated registry or custom
in-memory configuration is needed.
By default, ProviderRegistry reads service-registrar.toml from the current
working directory. Each top-level TOML table is a provider's configuration
section, and create() passes the selected provider's section to its factory.
For example:
[filesystem]
root = "/var/lib/catalog"
When the file is absent or a provider has no section, the factory receives an
empty mapping. Pass config=... to ProviderRegistry to override file loading
with an in-memory mapping. For an individual construction, pass config=...
to create(); that override does not modify the registry's stored
configuration:
store = registry.create(
ObjectStore,
provider="filesystem",
config={"root": "/tmp/catalog"},
)
Factories are called with named config and registry arguments. The injected
registry can be used to recursively construct other services:
class Catalog:
def __init__(self, *, registry: ProviderRegistry) -> None:
self._store = registry.create(ObjectStore, provider="filesystem")
def create_catalog(
*,
config: Mapping[str, object],
registry: ProviderRegistry,
) -> Catalog:
return Catalog(registry=registry)
ProviderRegistry.create() may omit the provider name only when exactly one
provider is registered for the port. It raises a clear error for missing or
ambiguous providers. Factories are called when create() is called; lifecycle
and caching remain under the application's control.
The entry-point name is the provider's registration name, so it is only declared once for plugins. For manual registration, pass the name explicitly:
registry.register("filesystem", FILESYSTEM_STORE)
Run service-registrar to discover installed providers and print the available
services and their provider names.
Metadata
Release files for service-registrar 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| service_registrar-0.2.2.tar.gz | 8.0 kB | With provenance | Details for service_registrar-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| service_registrar-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for service_registrar-0.2.2-py3-none-any.whl |
Total release size: 13.8 kB
Release files / service_registrar-0.2.2.tar.gz
| Download URL | service_registrar-0.2.2.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d2b1323dd882fbed4c34e78f10b50e792b916089d81afd2e3d52fa0e0c30873f
|
|
BLAKE2b-256 checksum How to use checksums |
eaa4007b543f8e1521fc099153bbc7074a077c39845428e6788735ddc677636f
|
| 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 1, 2026.
Transparency logRelease files / service_registrar-0.2.2-py3-none-any.whl
| Download URL | service_registrar-0.2.2-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
12ca80c89720b5a8aa01c9694f198456155ec27cb3255a2406b23a09dd4a613c
|
|
BLAKE2b-256 checksum How to use checksums |
0924acd64a27cda2854b41fd9ef7a9a5e7462622502836a1f52e3e15eb55ffc5
|
| 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 1, 2026.
Transparency logSecurity for service-registrar 0.2.2
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
All 2 files in this release have been uploaded with provenance metadata.
Attestation for service_registrar-0.2.2.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 1, 2026.
Transparency logA 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.