Action0-Service
A lightweight service registry and dependency injection framework: register classes, factories, or ready-made instances — by type or by name — and request them back with their constructor dependencies resolved automatically. Scopes (singleton, transient, thread-local, context-local), YAML service definitions, and a test-friendly override mechanism included. The core has zero dependencies.
Requires Python 3.11 or newer.
Full documentation including the API reference: https://laughinjar.github.io/action0-service/
Installation
pip install action0-service # or: uv add action0-service
pip install "action0-service[yaml]" # with YAML support (PyYAML)
Usage
Register services and let the registry wire them together:
from action0.service import Registry, Scope
class Database:
def __init__(self, dsn: str = "sqlite://"):
self.dsn = dsn
class UserRepository:
def __init__(self, db: Database): # injected from the registry
self.db = db
registry = Registry()
registry.register(Database, params={"dsn": "postgres://db/app"})
registry.register(UserRepository)
repo = registry.get(UserRepository)
print(repo.db.dsn)
# postgres://db/app
print(registry.get(UserRepository) is repo) # singletons by default
# True
Services can be named (several implementations of one type), scoped, and looked up by type — subclass-aware — or by name:
registry.register(Database, name="replica", params={"dsn": "postgres://replica/app"})
registry.get("replica") # by name
registry.get(Database) # the unnamed default
registry.get(Database, name="replica") # typed + named
registry.register(UserRepository, name="fresh", scope=Scope.TRANSIENT, replace=True)
Or define whole registries in YAML (anchors and merges work as usual):
database:
factory: myapp.db.Database
dsn: !ENV ${DATABASE_DSN:-sqlite://}
user-repository:
factory: myapp.repo.UserRepository
db: !ref database
registry.load_yaml("conf/services.yaml")
registry.validate() # catch config mistakes at boot, not at first use
For tests, swap any service temporarily:
with registry.override(Database, FakeDatabase()):
...
See the documentation for
injection rules, scopes, custom scopes, the full YAML format, parent
registries, lifecycle management (warmup() / close()), and the
@registry.inject function decorator.
The action0 namespace is simply the one the author likes to use for
personal projects.
AI disclosure
This library is developed with heavy use of AI coding tools: the code, tests, and documentation are largely written by Claude Code, working from the author's design brief and reviewed by the author. If that changes how much you want to rely on this package, that's a fair call — read the source, it's small.
License
MIT — see LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file action0_service-0.1.1.tar.gz.
File metadata
- Download URL: action0_service-0.1.1.tar.gz
- Upload date:
- Size: 132.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
158ece2d1c99a2b14afab8cdf121788e05cfccb66585a3884e1177acfd2c21c0
|
|
| MD5 |
f870e2bbf985eabfc322f90a7def86d6
|
|
| BLAKE2b-256 |
25dba01c17523ec71c7d3329895f14ee3c3d14840673ceda94a250ad305c1d78
|
Provenance
The following attestation bundles were made for action0_service-0.1.1.tar.gz:
Publisher:
release.yml on LaughInJar/action0-service
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
action0_service-0.1.1.tar.gz -
Subject digest:
158ece2d1c99a2b14afab8cdf121788e05cfccb66585a3884e1177acfd2c21c0 - Sigstore transparency entry: 2381321428
- Sigstore integration time:
-
Permalink:
LaughInJar/action0-service@b2897ea0544ce5efc64446340cf27ac9ce829992 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/LaughInJar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b2897ea0544ce5efc64446340cf27ac9ce829992 -
Trigger Event:
push
-
Statement type:
File details
Details for the file action0_service-0.1.1-py3-none-any.whl.
File metadata
- Download URL: action0_service-0.1.1-py3-none-any.whl
- Upload date:
- Size: 38.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d36556d8a95fbfc24f8c2d8828243e2a599b2e574ef0b6fee199ca87af34074
|
|
| MD5 |
e997bfc6c6e47d631a88f08d5d4db7d4
|
|
| BLAKE2b-256 |
438c2eabc6adfc6d62a6ce75161ce54b97715fa61676c5c88519dd905381e7e2
|
Provenance
The following attestation bundles were made for action0_service-0.1.1-py3-none-any.whl:
Publisher:
release.yml on LaughInJar/action0-service
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
action0_service-0.1.1-py3-none-any.whl -
Subject digest:
1d36556d8a95fbfc24f8c2d8828243e2a599b2e574ef0b6fee199ca87af34074 - Sigstore transparency entry: 2381322179
- Sigstore integration time:
-
Permalink:
LaughInJar/action0-service@b2897ea0544ce5efc64446340cf27ac9ce829992 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/LaughInJar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b2897ea0544ce5efc64446340cf27ac9ce829992 -
Trigger Event:
push
-
Statement type: