Skip to main content

Domain-Driven Design base classes and contracts

Project description

Python‑DDD‑Infrastructure

A lightweight Python library offering building blocks for Domain‑Driven Design (DDD). Provides base classes and utility mixins to help structure your domain model cleanly in terms of entities, value objects, aggregates, and events.


✨ Features

  • Core DDD abstractions:

    • ValueObject — immutable objects compared by value.
    • Entity — objects with a unique identity.
    • AggregateRoot — consistency boundary for aggregates.
    • DomainEvent — support for domain events in an event‑driven or event‑sourced architecture.
  • Clean, minimal dependencies and a small surface area so you can integrate it with your existing projects without a heavy footprint.


📦 Installation

Install from source:

pip install git+https://github.com/ariana126/Python‑DDD‑Infrastructure.git

or PyPI

pip install dddx

🛠 Usage

Here’s a simple example of how you might use the components in your domain layer.

from ddd import ValueObject, Entity, AggregateRoot, DomainEvent

# Value Object Example
class Money(ValueObject):
    def __init__(self, amount: float, currency: str):
        self._amount = amount
        self._currency = currency

    @property
    def amount(self):
        return self._amount

    @property
    def currency(self):
        return self._currency

# Entity Example
class Product(Entity):
    def __init__(self, product_id: str, name: str, price: Money):
        super().__init__(entity_id=product_id)
        self._name = name
        self._price = price

    @property
    def name(self):
        return self._name

    @property
    def price(self):
        return self._price

# AggregateRoot + DomainEvent Example
class ProductCreated(DomainEvent):
    def __init__(self, product_id: str, name: str, price: Money):
        self.product_id = product_id
        self.name = name
        self.price = price

class Inventory(AggregateRoot):
    def __init__(self, inventory_id: str):
        super().__init__(aggregate_id=inventory_id)
        self._products = {}

    def add_product(self, product: Product):
        # Some business invariants could be checked here
        self._products[product.id] = product
        self.record_event(ProductCreated(product.id, product.name, product.price))

✅ Testing

This project uses pytest for unit tests.

To run tests:

pytest

🌐 Contribution

Contributions are very welcome! If you find bugs, have ideas for enhancements, or want to add features, please feel free to open an issue or a pull request. Some suggestions:

  • Add more domain values (e.g. price, currency)
  • Support serialization / deserialization of aggregates and events
  • Expand documentation, provide practical real‑world examples

📄 License

This project is released under the MIT License. See the LICENSE file for details.


🤝 Acknowledgments

Thanks to anyone who has contributed or will contribute. Built for folks who want to work cleanly with DDD in Python, without getting locked into large frameworks.


Built with care by the community, for domain experts and software designers.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dddx-0.1.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dddx-0.1.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file dddx-0.1.1.tar.gz.

File metadata

  • Download URL: dddx-0.1.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for dddx-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1b9a5d40e4c6e76cd4e517a74f80518469fd9241fa5153754881f896f9a13b19
MD5 a83d2a7e6c56ef609f4a823a24bd75d3
BLAKE2b-256 f775f2d1e8e8c8af6288b2bb196e2db7dd37d10ea51b760f6c0240355ba0b00b

See more details on using hashes here.

File details

Details for the file dddx-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: dddx-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for dddx-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 230446244f0884f21290e328e2175d7ed55e22c078fae218ff3fcc215debcfc8
MD5 a66ea7e3e04fe5fd5a2ecc29e8047638
BLAKE2b-256 404999042aea29591c9fde2eff4fbbdd3dd40e94cddee50228ac1fe38c5bff3b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page