This release is a pre-release and may not be stable for production use.
dddlib
dddlib is a Python library that provides foundational components for implementing Domain-Driven Design.
This library does not provide application-specific business logic itself. Instead, it aims to provide common concepts that repeatedly appear in DDD design in a type-safe and easy-to-use form.
Positioning
dddlib standardizes the following elements commonly required in the domain layer.
- Value objects
- Entities
- Aggregate roots
- Domain events
- Identifiers
- Domain errors
- Messages
When these are implemented separately for each application, similar constraints, validations, equality comparisons, and reconstruction logic can easily become scattered.
dddlib serves as a foundation for reducing that repetition and making it easier to focus on designing the domain model itself.
Design Policy
dddlib is designed based on the following policies.
- Make it easy to handle value storage and immutability based on
dataclass - Provide an implementation that works well with type checking by
mypy - Keep the code explicit and readable in line with strict
ruffrules - Avoid concrete business processing and limit the scope to common domain foundations
- Separate it from
dddlib_clito distinguish library usage from CLI usage
For this reason, dddlib is intended to be used not as a framework, but as a thin foundational layer for domain models.
Provided Features
Value Objects
A value object is an object whose identity is determined by its value rather than by an ID.
In dddlib, the following operations, which are often needed when creating value objects, are consolidated.
- Validation at creation time
- Conversion to dictionaries
- Conversion to display strings
- Storage as immutable values
By using FrozenBase, behavior equivalent to dataclass(frozen=True) can be handled naturally.
Entities
An entity is an object that has identity through an identifier.
The entity foundation in dddlib supports the following operations.
- Creating objects with identifiers
- Internal creation for reconstruction
- Comparison based on identity
- Retrieving identifiers
Unlike value objects, entities have a lifecycle. Therefore, it is important to clearly separate identity determination.
Aggregate Roots
An aggregate root is the entry point for protecting domain consistency.
The aggregate root in dddlib inherits the characteristics of an entity while allowing domain events to be accumulated and retrieved.
- Adding events
- Getting and extracting events
- Adding multiple events together
This makes it easier to safely handle events that occur as a result of domain operations.
Domain Events
A domain event represents an important event that occurred within the domain.
In dddlib, emphasis is placed on handling events not as simple dictionaries or strings, but as typed objects.
By representing event contents as explicit classes, it becomes easier to connect them to event-driven processing, auditing, and notification processing.
Identifiers
An identifier is a value used to uniquely handle an entity or aggregate.
dddlib provides bases mainly for UUID-based identifiers, consolidating value validation and conversion.
This makes it easier to handle IDs as meaningful types instead of scattering raw str or int values throughout the code.
Errors and Messages
dddlib also standardizes errors and messages handled in the domain layer.
DDDErroris the foundation for domain errors that have a code and messageMessagehandles message body generation and formattingDDDMessagerepresents predefined messages with codes
Using this mechanism makes it easier to handle errors consistently across the entire application, rather than confining them to simple exception messages.
Typical Usage Image
dddlib is intended to be used, for example, in the following kind of structure.
- Define domain IDs by deriving them from
UUIDIdentifier - Give validation logic to value objects
- Determine entity identity based on IDs
- Publish domain events from aggregate roots
- Explicitly represent business failures with domain errors
This design makes it easier to build models using domain language without pushing too much responsibility into the application layer or infrastructure layer.
Relationship with the CLI
The main body of dddlib is a library.
If you want to support project work using a CLI, refer to the separate package dddlib_cli.
Adoption Approach
When adopting dddlib, it is useful to think through the following order.
- First, decide how to represent domain identifiers
- Next, extract concepts that should be closed as value objects
- Then, define entities and aggregate roots
- Finally, align the representation of events and errors
dddlib should be used as a tool for aligning implementation, rather than as something that disrupts this flow.
Notes
dddlibis not a completed business application, but a common foundation- The domain cannot be established simply by using it as-is, so each project needs to define concrete models
- CLI details are separated into the dddlib_cli README
License
For this project, refer to LICENSE.md directly under the repository root.
Metadata
Release files for dddlib 0.1.0a2
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 |
|---|---|---|---|---|
| dddlib-0.1.0a2.tar.gz | 8.8 kB | With provenance | Details for dddlib-0.1.0a2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dddlib-0.1.0a2-py3-none-any.whl | Python 3 | none | any | Details for dddlib-0.1.0a2-py3-none-any.whl |
Total release size: 24.3 kB
Release files / dddlib-0.1.0a2.tar.gz
| Download URL | dddlib-0.1.0a2.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
62f455d059a06311260f1c365f98adee5be33c7057747ca187722a70a567f19a
|
|
BLAKE2b-256 checksum How to use checksums |
aff18313d23100ceb376e19d2cc7104b0174bf84938236910e42e82e616686ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 20, 2026.
Transparency logRelease files / dddlib-0.1.0a2-py3-none-any.whl
| Download URL | dddlib-0.1.0a2-py3-none-any.whl |
|---|---|
| Size | 15.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
60bf63ae711d6254cf45ececeade00980c5bafdc903e417fe7cfe1450c7e03e1
|
|
BLAKE2b-256 checksum How to use checksums |
8325a23a277153e81d32509ee5aaca306b1850d494023cf3d01ca3a58ee144fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 20, 2026.
Transparency logSecurity for dddlib 0.1.0a2
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
Both files in this release have been uploaded with provenance metadata.
Attestation for dddlib-0.1.0a2.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 May 20, 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.