django-domain-repositories
Automatic repository discovery and container binding for domain-driven Django applications.
This package eliminates manual wiring of repository contracts to their implementations. It scans your configured domains package on startup, applies a strict naming convention, and registers everything automatically — no decorators, no explicit registration calls.
Installation
pip install django-domain-repositories
Add to INSTALLED_APPS:
INSTALLED_APPS = [
# ...
"django_domain_repositories",
]
Naming Convention
| Role | Pattern |
|---|---|
| Contract module | <domains_pkg>.<domain>.contracts.<domain>_repository |
| Contract class | <Domain>Repository (abstract) |
| Concrete module | <domains_pkg>.<domain>.repositories.<domain>_<driver> |
| Concrete class | <Domain><Driver> |
Example with foo domain and default django_orm driver:
myproject/domains/foo/contracts/foo_repository.py → class FooRepository (ABC)
myproject/domains/foo/repositories/foo_django_orm.py → class FooDjangoOrm(FooRepository)
If a contract or concrete class does not exist for a domain, that domain is silently skipped.
Domain Structure
myproject/
domains/
__init__.py
foo/
__init__.py
contracts/
foo_repository.py
repositories/
foo_django_orm.py
models/
services/
bar/
__init__.py
contracts/
bar_repository.py
repositories/
bar_sqlalchemy.py
Configuration
# settings.py
DOMAIN_REPOSITORIES = {
"DEFAULT_DRIVER": "django_orm", # default driver suffix
"DEFAULT_BINDING": "transient", # new instance per resolve call
"BINDING_OPTIONS": ["transient", "singleton"],
"DOMAINS_PACKAGE": "myproject.domains",
# Per-domain overrides
"DOMAINS": {
"foo": {"driver": "django_orm", "binding": "transient"},
"bar": {"driver": "sqlalchemy", "binding": "singleton"},
},
}
transient returns a new instance on every resolve() call. singleton returns the same instance throughout the process lifetime.
Resolving a Repository
from django_domain_repositories import resolve
from myproject.domains.foo.contracts.foo_repository import FooRepository
repo = resolve(FooRepository)
Directory Scaffolding
from django_domain_repositories import ensure_domain_directories
ensure_domain_directories("/path/to/myproject/domains/foo")
Creates the conventional subdirectories: contracts, repositories, models, services, enums, events, exceptions, helpers, jobs, listeners, observers, views.
Testing
from django_domain_repositories.registry import clear_registry, _registry
def test_something():
clear_registry()
# register a fake manually, test, then clear again
Out of Scope
This package handles repository registration only. Signals, middleware, and other domain concerns are intentionally left out.
License
MIT
Metadata
Release files for django-domain-repositories 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_domain_repositories-0.1.0.tar.gz | 7.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_domain_repositories-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.0 kB
Release files / django_domain_repositories-0.1.0.tar.gz
| Download URL | django_domain_repositories-0.1.0.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
92547a9559f777312b7146417174c7595b05d195a61616c922748cd8038a2061
|
|
BLAKE2b-256 checksum How to use checksums |
507d66798e67cdf222572839efab210e19e7de75bf67a5e87beb4d669629c969
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.2
|
Release files / django_domain_repositories-0.1.0-py3-none-any.whl
| Download URL | django_domain_repositories-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
076676e1dadf792508820bf6a00e9227032fe785dbf46f3dfe79ab55ee7c4e05
|
|
BLAKE2b-256 checksum How to use checksums |
46ce8f59128cfa93f79768999e340940899557deae4124cd046e724d34136167
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.2
|