A domain-driven design library for Python.
Project description
Note: This library is currently in alpha stage and is under active development. APIs and features may change before the final release.
py-domain-driven-design
A domain driven design library for Python.
Purpose
The purpose of py-domain-driven-design
is to provide a comprehensive toolkit for Python developers to implement domain-driven design (DDD) in their applications. This library focuses on enabling the development of rich domain models that accurately reflect complex business requirements, facilitating better communication between developers and domain experts, and promoting a more maintainable and scalable codebase.
Roadmap
Below is a list of planned features and enhancements for future releases of the py-domain-driven-design
library.
- Repository Pattern: Add support for the repository pattern to provide a standard way to access domain objects from a data source.
- Aggregates: Add support for defining and working with aggregates, including aggregate roots and associated objects.
- Value Objects: Implement support for defining value objects to represent immutable domain concepts.
- Entities: Add support for defining entities with distinct identities and lifecycles.
- Domain Events: Implement infrastructure for defining and handling domain events to capture important domain changes.
- Integration Events: Add support for defining and handling integration events for communication between different bounded contexts.
- Domain Services: Support for encapsulating domain logic in services outside of entities or value objects.
- Infrastructure Services: Support for services that provide technical capabilities like data persistence and messaging, supporting the application's infrastructure needs.
- Listeners: Implement listeners to react to domain and integration events, enabling reactive and decoupled systems.
- Documentation: Expand the documentation to cover new features and provide more comprehensive usage examples and best practices.
We welcome feedback and contributions to help shape the future of this library. If you have ideas or suggestions, please [create an issue](
Python Compatibility
This library is compatible and tested with the following Python versions:
- Python 3.7
- Python 3.8
- Python 3.9
- Python 3.10
- Python 3.11
- Python 3.12
Installation:
$ pip install py-domain-driven-design
Example:
Here's an example demonstrating the use of the repository pattern in the library:
from typing import List
from ddd.infrastructure.repository.in_memory.in_memory_repository_base import InMemoryRepositoryBase
from carbusiness.domain.model.vehicle.ivehicle_repository import IVehicleRepository
from carbusiness.domain.model.vehicle.vehicle import Vehicle
class InMemoryVehicleRepository(InMemoryRepositoryBase[Vehicle], IVehicleRepository):
def find_with_colors(self, colors: List[str]) -> List[Vehicle]:
with self._lock:
return [vehicle for vehicle in self._entities.values() if vehicle.color in colors]
# Creating a repository for Vehicle entities
vehicle_repository = InMemoryVehicleRepository()
# Adding some vehicles to the repository
vehicle_repository.save(Vehicle(id="1", color="red"))
vehicle_repository.save(Vehicle(id="2", color="blue"))
vehicle_repository.save(Vehicle(id="3", color="red"))
# Finding vehicles with the color red
red_vehicles = vehicle_repository.find_with_colors(["red"])
for vehicle in red_vehicles:
print(f"Red Vehicle: ID {vehicle.id}, Color {vehicle.color}")
# Output:
# Red Vehicle: ID 1, Color red
# Red Vehicle: ID 3, Color red
For more examples, please refer to the documentation.
Documentation:
You can find the latest documentation at readthedocs.
License
py-domain-driven-design
is released under the GPL 3 license. See LICENSE for more details.
Source Code
You can find the source code for py-domain-driven-design
on GitHub.
Release Notes
1.0.0-alpha.2 (2024-04-02)
- New Feature: Introduced the repository pattern, providing a base for data access.
- Basic Documentation: An initial set of documentation is provided, focusing on the repository pattern.
- License: Released under the GPL 3 license.
- Compatibility: Ensured compatibility with Python versions 3.7 to 3.12.
Project details
Release history Release notifications | RSS feed
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
Hashes for py-domain-driven-design-1.0.0a2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04f8f31e90b4ab52e053ccb2078b965a789ebed8d19a6994ae6006f63dca538d |
|
MD5 | 9ab1b7a2e43d900e2b8efa301b990a75 |
|
BLAKE2b-256 | a7d27a4b3b80d113fb4dcbf02bd1f0e67439c2db861800d6eefdce2ffa449f71 |
Hashes for py_domain_driven_design-1.0.0a2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4076793ff9e71daa1daf651ef9d8d2108063ed063dd59a8306173178e058651 |
|
MD5 | c7bf4d7813b40735a2736caf39d7b6e6 |
|
BLAKE2b-256 | 30da6e9f7317c29667471dda0d6e8f0b77f76acd499f647375125ba5301a710c |