typed-registry 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Denis Maciel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,208 @@
1
+ Metadata-Version: 2.4
2
+ Name: typed-registry
3
+ Version: 0.1.1
4
+ Summary: A tiny, fully typed service registry for Python application composition
5
+ Keywords: dependency-injection,service-locator,registry,typing,composition-root
6
+ Author: Denis Maciel
7
+ Author-email: Denis Maciel <denispmaciel@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Typing :: Typed
16
+ Requires-Python: >=3.14
17
+ Project-URL: Homepage, https://github.com/denismaciel/typed-registry
18
+ Project-URL: Repository, https://github.com/denismaciel/typed-registry
19
+ Project-URL: Issues, https://github.com/denismaciel/typed-registry/issues
20
+ Description-Content-Type: text/markdown
21
+
22
+ # typed-registry
23
+
24
+ [![CI](https://github.com/denismaciel/typed-registry/actions/workflows/ci.yml/badge.svg)](https://github.com/denismaciel/typed-registry/actions/workflows/ci.yml)
25
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
26
+
27
+ A tiny, fully typed service registry for Python. It has no dependencies, about
28
+ 35 lines of code, and needs no casts.
29
+
30
+ ```python
31
+ event_bus = registry.get(Services.event_bus) # your type checker knows: EventBus
32
+ ```
33
+
34
+ ## Why
35
+
36
+ Most service locators key services by string or by class and hand you back
37
+ `Any`, or make you write `cast(...)` at every call site. `typed-registry`
38
+ keys services by **typed tokens** instead. Each token carries the type of the
39
+ service it names, so:
40
+
41
+ - `registry.get(token)` returns the right type, inferred by MyPy, ty, and
42
+ Zuban.
43
+ - `token.register(registry, value)` rejects a value of the wrong type at type
44
+ check time.
45
+ - Two tokens with the same name never collide, because tokens compare by
46
+ identity, not by name.
47
+
48
+ ## Install
49
+
50
+ ```sh
51
+ uv add typed-registry==0.1.1
52
+ ```
53
+
54
+ Requires Python 3.14+.
55
+
56
+ ## Usage
57
+
58
+ Declare a catalogue of tokens that your application owns:
59
+
60
+ ```python
61
+ from typing import Final
62
+
63
+ from typed_registry import ServiceToken
64
+
65
+
66
+ class Services:
67
+ event_bus: Final = ServiceToken[EventBus]("platform.event_bus")
68
+ settings: Final = ServiceToken[Settings]("platform.settings")
69
+ ```
70
+
71
+ Wire concrete services in your composition root:
72
+
73
+ ```python
74
+ from typed_registry import ServiceRegistry
75
+
76
+ registry = ServiceRegistry()
77
+ Services.settings.register(registry, Settings.from_env())
78
+ Services.event_bus.register(registry, EventBus())
79
+ ```
80
+
81
+ Resolve them where you build the rest of the application:
82
+
83
+ ```python
84
+ event_bus = registry.get(Services.event_bus) # EventBus
85
+ settings = registry.get(Services.settings) # Settings
86
+ ```
87
+
88
+ Mismatches are caught before your code runs:
89
+
90
+ ```python
91
+ Services.event_bus.register(registry, Settings())
92
+ # error: Argument 2 to "register" of "ServiceToken" has incompatible type "Settings"; expected "EventBus"
93
+ ```
94
+
95
+ Asking for a token that was never registered raises `MissingServiceError`,
96
+ which is a `LookupError` and exposes the token's `service_name`:
97
+
98
+ ```python
99
+ from typed_registry import MissingServiceError
100
+
101
+ try:
102
+ registry.get(Services.event_bus)
103
+ except MissingServiceError as error:
104
+ print(error.service_name) # "platform.event_bus"
105
+ ```
106
+
107
+ ## Testing
108
+
109
+ Registering a token again replaces its value, so tests can build the real
110
+ wiring and then swap in a fake for a single service. The replacement is still
111
+ type checked against the token:
112
+
113
+ ```python
114
+ registry = build_registry()
115
+ Services.event_bus.register(registry, FakeEventBus())
116
+ ```
117
+
118
+ ## Design notes
119
+
120
+ `typed-registry` is meant for the **composition root**: the one place where an
121
+ application assembles its object graph. Keep the registry there. Domain code
122
+ should receive the narrow dependencies it needs as plain arguments, not reach
123
+ into the registry. That keeps the domain easy to test without any registry at
124
+ all, and avoids the usual downside of service locators, which is that
125
+ dependencies become hidden.
126
+
127
+ Some deliberate non-features:
128
+
129
+ - **No autowiring or reflection.** You construct services yourself, in order.
130
+ - **No scopes or lifecycles.** A registry holds values; create one per scope if
131
+ you need to.
132
+ - **No global registry.** You create and pass `ServiceRegistry` instances
133
+ explicitly.
134
+
135
+ ## API
136
+
137
+ | Name | Description |
138
+ | --- | --- |
139
+ | `ServiceToken[T](name)` | Typed, identity-compared key. `name` is used only in error messages. |
140
+ | `ServiceToken.register(registry, service)` | Store `service: T`, replacing any previous value. |
141
+ | `ServiceRegistry.get(token) -> T` | Resolve a service, or raise `MissingServiceError`. |
142
+ | `MissingServiceError` | `LookupError` subclass with a `service_name` attribute. |
143
+
144
+ ## Development
145
+
146
+ ```sh
147
+ make dev # uv sync --locked
148
+ make check # mypy and ty
149
+ make test # pytest
150
+ make build # uv build --no-sources
151
+ make release-check # build and test installed wheel + sdist
152
+ ```
153
+
154
+ Use uv 0.12.4. Development dependencies are pinned in `uv.lock`; packaging uses
155
+ `uv_build==0.12.4`. CI runs the same commands on Python 3.14 and 3.15.
156
+
157
+ ## Releases
158
+
159
+ Releases are published to PyPI and GitHub. To prepare a release, update `project.version` in
160
+ `pyproject.toml`, run `uv lock`, and run:
161
+
162
+ ```sh
163
+ make dev check test
164
+ RELEASE_TAG=v0.1.1 make release-check # use the new version
165
+ ```
166
+
167
+ `release-check` rejects a mismatched tag before building. It builds with
168
+ `uv build --no-sources`, installs the wheel and sdist separately in temporary
169
+ virtual environments outside the checkout, and checks package metadata,
170
+ `py.typed`, and registry behavior. Verified wheel/sdist files, `SHA256SUMS`, and
171
+ a hashed `index.html` are written to `dist/release/` (replacing its prior contents).
172
+ Without `RELEASE_TAG`, the check uses the version from `pyproject.toml`.
173
+
174
+ Commit the version and lockfile, then push a matching `vVERSION` tag. The release
175
+ workflow runs CI on that exact commit, repeats distribution verification, and
176
+ creates a draft GitHub release with the verified assets before publishing it.
177
+ Versions use `X.Y.Z` or `X.Y.ZaN`, `X.Y.ZbN`, or `X.Y.ZrcN`. Alpha, beta, and
178
+ release-candidate tags publish as prereleases without changing the latest release.
179
+ Existing releases are never overwritten. If publication fails after creating the
180
+ draft, inspect that draft and its assets before manually finishing or deleting it.
181
+ A manual workflow dispatch builds and uploads Actions artifacts only; it never
182
+ publishes a release.
183
+
184
+ After GitHub publication, a separate `pypi` environment job publishes only the
185
+ verified wheel and sdist to PyPI using Trusted Publishing and attestations. That
186
+ job never checks out or executes project code and has no repository write access.
187
+ Both publishers require a `v*` tag push in the canonical repository; the tagged
188
+ commit must be reachable from the default branch fetched from origin. Manual
189
+ workflow dispatch cannot publish. Checkout credentials are not persisted, and
190
+ release/CI dependency caching is disabled.
191
+
192
+ Configure the PyPI Trusted Publisher for owner `denismaciel`, repository
193
+ `typed-registry`, workflow `release.yml`, and environment `pypi`. Restrict that
194
+ GitHub environment to release tags and protect the default branch and release
195
+ tags. No PyPI API token is needed. If PyPI publication fails after GitHub
196
+ publication, rerun only the failed PyPI job; do not replace the GitHub release or
197
+ reuse a published PyPI version.
198
+
199
+ Once release assets are published, use that release's versioned wheel index
200
+ (replace the example version with the published version):
201
+
202
+ ```sh
203
+ uv add --no-index --find-links https://github.com/denismaciel/typed-registry/releases/download/v0.1.1/index.html typed-registry==0.1.1
204
+ ```
205
+
206
+ ## License
207
+
208
+ [MIT](LICENSE)
@@ -0,0 +1,187 @@
1
+ # typed-registry
2
+
3
+ [![CI](https://github.com/denismaciel/typed-registry/actions/workflows/ci.yml/badge.svg)](https://github.com/denismaciel/typed-registry/actions/workflows/ci.yml)
4
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
5
+
6
+ A tiny, fully typed service registry for Python. It has no dependencies, about
7
+ 35 lines of code, and needs no casts.
8
+
9
+ ```python
10
+ event_bus = registry.get(Services.event_bus) # your type checker knows: EventBus
11
+ ```
12
+
13
+ ## Why
14
+
15
+ Most service locators key services by string or by class and hand you back
16
+ `Any`, or make you write `cast(...)` at every call site. `typed-registry`
17
+ keys services by **typed tokens** instead. Each token carries the type of the
18
+ service it names, so:
19
+
20
+ - `registry.get(token)` returns the right type, inferred by MyPy, ty, and
21
+ Zuban.
22
+ - `token.register(registry, value)` rejects a value of the wrong type at type
23
+ check time.
24
+ - Two tokens with the same name never collide, because tokens compare by
25
+ identity, not by name.
26
+
27
+ ## Install
28
+
29
+ ```sh
30
+ uv add typed-registry==0.1.1
31
+ ```
32
+
33
+ Requires Python 3.14+.
34
+
35
+ ## Usage
36
+
37
+ Declare a catalogue of tokens that your application owns:
38
+
39
+ ```python
40
+ from typing import Final
41
+
42
+ from typed_registry import ServiceToken
43
+
44
+
45
+ class Services:
46
+ event_bus: Final = ServiceToken[EventBus]("platform.event_bus")
47
+ settings: Final = ServiceToken[Settings]("platform.settings")
48
+ ```
49
+
50
+ Wire concrete services in your composition root:
51
+
52
+ ```python
53
+ from typed_registry import ServiceRegistry
54
+
55
+ registry = ServiceRegistry()
56
+ Services.settings.register(registry, Settings.from_env())
57
+ Services.event_bus.register(registry, EventBus())
58
+ ```
59
+
60
+ Resolve them where you build the rest of the application:
61
+
62
+ ```python
63
+ event_bus = registry.get(Services.event_bus) # EventBus
64
+ settings = registry.get(Services.settings) # Settings
65
+ ```
66
+
67
+ Mismatches are caught before your code runs:
68
+
69
+ ```python
70
+ Services.event_bus.register(registry, Settings())
71
+ # error: Argument 2 to "register" of "ServiceToken" has incompatible type "Settings"; expected "EventBus"
72
+ ```
73
+
74
+ Asking for a token that was never registered raises `MissingServiceError`,
75
+ which is a `LookupError` and exposes the token's `service_name`:
76
+
77
+ ```python
78
+ from typed_registry import MissingServiceError
79
+
80
+ try:
81
+ registry.get(Services.event_bus)
82
+ except MissingServiceError as error:
83
+ print(error.service_name) # "platform.event_bus"
84
+ ```
85
+
86
+ ## Testing
87
+
88
+ Registering a token again replaces its value, so tests can build the real
89
+ wiring and then swap in a fake for a single service. The replacement is still
90
+ type checked against the token:
91
+
92
+ ```python
93
+ registry = build_registry()
94
+ Services.event_bus.register(registry, FakeEventBus())
95
+ ```
96
+
97
+ ## Design notes
98
+
99
+ `typed-registry` is meant for the **composition root**: the one place where an
100
+ application assembles its object graph. Keep the registry there. Domain code
101
+ should receive the narrow dependencies it needs as plain arguments, not reach
102
+ into the registry. That keeps the domain easy to test without any registry at
103
+ all, and avoids the usual downside of service locators, which is that
104
+ dependencies become hidden.
105
+
106
+ Some deliberate non-features:
107
+
108
+ - **No autowiring or reflection.** You construct services yourself, in order.
109
+ - **No scopes or lifecycles.** A registry holds values; create one per scope if
110
+ you need to.
111
+ - **No global registry.** You create and pass `ServiceRegistry` instances
112
+ explicitly.
113
+
114
+ ## API
115
+
116
+ | Name | Description |
117
+ | --- | --- |
118
+ | `ServiceToken[T](name)` | Typed, identity-compared key. `name` is used only in error messages. |
119
+ | `ServiceToken.register(registry, service)` | Store `service: T`, replacing any previous value. |
120
+ | `ServiceRegistry.get(token) -> T` | Resolve a service, or raise `MissingServiceError`. |
121
+ | `MissingServiceError` | `LookupError` subclass with a `service_name` attribute. |
122
+
123
+ ## Development
124
+
125
+ ```sh
126
+ make dev # uv sync --locked
127
+ make check # mypy and ty
128
+ make test # pytest
129
+ make build # uv build --no-sources
130
+ make release-check # build and test installed wheel + sdist
131
+ ```
132
+
133
+ Use uv 0.12.4. Development dependencies are pinned in `uv.lock`; packaging uses
134
+ `uv_build==0.12.4`. CI runs the same commands on Python 3.14 and 3.15.
135
+
136
+ ## Releases
137
+
138
+ Releases are published to PyPI and GitHub. To prepare a release, update `project.version` in
139
+ `pyproject.toml`, run `uv lock`, and run:
140
+
141
+ ```sh
142
+ make dev check test
143
+ RELEASE_TAG=v0.1.1 make release-check # use the new version
144
+ ```
145
+
146
+ `release-check` rejects a mismatched tag before building. It builds with
147
+ `uv build --no-sources`, installs the wheel and sdist separately in temporary
148
+ virtual environments outside the checkout, and checks package metadata,
149
+ `py.typed`, and registry behavior. Verified wheel/sdist files, `SHA256SUMS`, and
150
+ a hashed `index.html` are written to `dist/release/` (replacing its prior contents).
151
+ Without `RELEASE_TAG`, the check uses the version from `pyproject.toml`.
152
+
153
+ Commit the version and lockfile, then push a matching `vVERSION` tag. The release
154
+ workflow runs CI on that exact commit, repeats distribution verification, and
155
+ creates a draft GitHub release with the verified assets before publishing it.
156
+ Versions use `X.Y.Z` or `X.Y.ZaN`, `X.Y.ZbN`, or `X.Y.ZrcN`. Alpha, beta, and
157
+ release-candidate tags publish as prereleases without changing the latest release.
158
+ Existing releases are never overwritten. If publication fails after creating the
159
+ draft, inspect that draft and its assets before manually finishing or deleting it.
160
+ A manual workflow dispatch builds and uploads Actions artifacts only; it never
161
+ publishes a release.
162
+
163
+ After GitHub publication, a separate `pypi` environment job publishes only the
164
+ verified wheel and sdist to PyPI using Trusted Publishing and attestations. That
165
+ job never checks out or executes project code and has no repository write access.
166
+ Both publishers require a `v*` tag push in the canonical repository; the tagged
167
+ commit must be reachable from the default branch fetched from origin. Manual
168
+ workflow dispatch cannot publish. Checkout credentials are not persisted, and
169
+ release/CI dependency caching is disabled.
170
+
171
+ Configure the PyPI Trusted Publisher for owner `denismaciel`, repository
172
+ `typed-registry`, workflow `release.yml`, and environment `pypi`. Restrict that
173
+ GitHub environment to release tags and protect the default branch and release
174
+ tags. No PyPI API token is needed. If PyPI publication fails after GitHub
175
+ publication, rerun only the failed PyPI job; do not replace the GitHub release or
176
+ reuse a published PyPI version.
177
+
178
+ Once release assets are published, use that release's versioned wheel index
179
+ (replace the example version with the published version):
180
+
181
+ ```sh
182
+ uv add --no-index --find-links https://github.com/denismaciel/typed-registry/releases/download/v0.1.1/index.html typed-registry==0.1.1
183
+ ```
184
+
185
+ ## License
186
+
187
+ [MIT](LICENSE)
@@ -0,0 +1,55 @@
1
+ [project]
2
+ name = "typed-registry"
3
+ version = "0.1.1"
4
+ description = "A tiny, fully typed service registry for Python application composition"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.14"
9
+ dependencies = []
10
+ keywords = [
11
+ "dependency-injection",
12
+ "service-locator",
13
+ "registry",
14
+ "typing",
15
+ "composition-root",
16
+ ]
17
+ classifiers = [
18
+ "Development Status :: 4 - Beta",
19
+ "Intended Audience :: Developers",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Programming Language :: Python :: 3.14",
23
+ "Typing :: Typed",
24
+ ]
25
+
26
+ [[project.authors]]
27
+ name = "Denis Maciel"
28
+ email = "denispmaciel@gmail.com"
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/denismaciel/typed-registry"
32
+ Repository = "https://github.com/denismaciel/typed-registry"
33
+ Issues = "https://github.com/denismaciel/typed-registry/issues"
34
+
35
+ [dependency-groups]
36
+ dev = [
37
+ "pytest>=8",
38
+ "mypy>=1.15",
39
+ "ty>=0.0.1a1",
40
+ ]
41
+
42
+ [build-system]
43
+ requires = ["uv_build==0.12.4"]
44
+ build-backend = "uv_build"
45
+
46
+ [tool.pytest.ini_options]
47
+ testpaths = ["tests"]
48
+ python_files = ["*_test.py"]
49
+
50
+ [tool.mypy]
51
+ strict = true
52
+ files = [
53
+ "src",
54
+ "tests",
55
+ ]
@@ -0,0 +1,39 @@
1
+ [project]
2
+ name = "typed-registry"
3
+ version = "0.1.1"
4
+ description = "A tiny, fully typed service registry for Python application composition"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ authors = [{ name = "Denis Maciel", email = "denispmaciel@gmail.com" }]
9
+ requires-python = ">=3.14"
10
+ dependencies = []
11
+ keywords = ["dependency-injection", "service-locator", "registry", "typing", "composition-root"]
12
+ classifiers = [
13
+ "Development Status :: 4 - Beta",
14
+ "Intended Audience :: Developers",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3 :: Only",
17
+ "Programming Language :: Python :: 3.14",
18
+ "Typing :: Typed",
19
+ ]
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/denismaciel/typed-registry"
23
+ Repository = "https://github.com/denismaciel/typed-registry"
24
+ Issues = "https://github.com/denismaciel/typed-registry/issues"
25
+
26
+ [dependency-groups]
27
+ dev = ["pytest>=8", "mypy>=1.15", "ty>=0.0.1a1"]
28
+
29
+ [build-system]
30
+ requires = ["uv_build==0.12.4"]
31
+ build-backend = "uv_build"
32
+
33
+ [tool.pytest.ini_options]
34
+ testpaths = ["tests"]
35
+ python_files = ["*_test.py"]
36
+
37
+ [tool.mypy]
38
+ strict = true
39
+ files = ["src", "tests"]
@@ -0,0 +1,3 @@
1
+ from typed_registry.runtime import MissingServiceError, ServiceRegistry, ServiceToken
2
+
3
+ __all__ = ["MissingServiceError", "ServiceRegistry", "ServiceToken"]
File without changes
@@ -0,0 +1,35 @@
1
+ """Typed runtime service composition primitives."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ from typing import cast
7
+
8
+
9
+ class MissingServiceError(LookupError):
10
+ def __init__(self, service_name: str) -> None:
11
+ super().__init__(f"service is not registered: {service_name}")
12
+ self.service_name = service_name
13
+
14
+
15
+ @dataclass(frozen=True, slots=True, eq=False)
16
+ class ServiceToken[T]:
17
+ name: str
18
+
19
+ def register(self, registry: ServiceRegistry, service: T) -> None:
20
+ registry._store(self, service)
21
+
22
+
23
+ class ServiceRegistry:
24
+ def __init__(self) -> None:
25
+ self._services: dict[object, object] = {}
26
+
27
+ def _store(self, token: object, service: object) -> None:
28
+ self._services[token] = service
29
+
30
+ def get[T](self, token: ServiceToken[T]) -> T:
31
+ try:
32
+ service = self._services[token]
33
+ except KeyError:
34
+ raise MissingServiceError(token.name) from None
35
+ return cast(T, service)