A collection of base classes for Domain-Driven Design (DDD) value objects and entities in Python
Project description
DDD Value Objects
Una colección de clases base para implementar Objetos de Valor (Value Objects) y Entidades siguiendo los principios de Domain-Driven Design (DDD) en Python.
Características
- Clases base para Objetos de Valor de tipos primitivos (
String,Int,Float,Bool). - Soporte para
UuidValueObjectcon validación integrada. - Clase base para
Entitycon identificación basada en UUID. - Tipado fuerte y validación de nulidad por defecto.
- Comparación de igualdad estructural para Objetos de Valor e igualdad de identidad para Entidades.
Instalación
Puedes instalarlo usando pip:
pip install ddd-value-objects
O usando uv:
uv add ddd-value-objects
Uso
Objetos de Valor (Value Objects)
Los Objetos de Valor son inmutables y se definen por sus atributos, no por una identidad única.
from ddd_value_objects.string_value_object import StringValueObject
from ddd_value_objects.int_value_object import IntValueObject
class UserName(StringValueObject):
pass
class UserAge(IntValueObject):
def __init__(self, value: int):
super().__init__(value)
if value < 0:
raise ValueError("Age cannot be negative")
name1 = UserName("Alice")
name2 = UserName("Alice")
name3 = UserName("Bob")
print(name1.equals(name2)) # True
print(name1.equals(name3)) # False
UUID Value Object
Especialmente útil para identificadores:
from ddd_value_objects.uuid_value_object import UuidValueObject
user_id = UuidValueObject("550e8400-e29b-41d4-a716-446655440000")
Entidades (Entities)
Las Entidades tienen una identidad única que las distingue de otras entidades del mismo tipo.
from ddd_value_objects.entity import Entity
class User(Entity):
def __init__(self, id: str, name: str):
super().__init__(id)
self.name = name
user1 = User("550e8400-e29b-41d4-a716-446655440000", "Alice")
user2 = User("550e8400-e29b-41d4-a716-446655440000", "Alice Smith")
print(user1.equals(user2)) # True (misma identidad)
Desarrollo
Si deseas contribuir o ejecutar las pruebas localmente:
- Instala
uvsi no lo tienes. - Sincroniza las dependencias:
uv sync - Ejecuta los tests:
uv run pytest
Licencia
Este proyecto está bajo la licencia MIT.
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
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 ddd_value_objects-0.1.2.tar.gz.
File metadata
- Download URL: ddd_value_objects-0.1.2.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9901c958d6b39ac52a71d8ff91ca0a43272aa1086aa15b772d2f93eb7dce7410
|
|
| MD5 |
e4d1ec970c09f3933516d8d7380be937
|
|
| BLAKE2b-256 |
c5f502798103fc56375b12b0a8f1b560cad1cd615f743c622f818f19717dfcf4
|
Provenance
The following attestation bundles were made for ddd_value_objects-0.1.2.tar.gz:
Publisher:
code.yml on josedejesuschavez/ddd-value-objects
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ddd_value_objects-0.1.2.tar.gz -
Subject digest:
9901c958d6b39ac52a71d8ff91ca0a43272aa1086aa15b772d2f93eb7dce7410 - Sigstore transparency entry: 781975616
- Sigstore integration time:
-
Permalink:
josedejesuschavez/ddd-value-objects@f2bce15b95f85d5e45f36a4c312f158a8427826f -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/josedejesuschavez
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
code.yml@f2bce15b95f85d5e45f36a4c312f158a8427826f -
Trigger Event:
release
-
Statement type:
File details
Details for the file ddd_value_objects-0.1.2-py3-none-any.whl.
File metadata
- Download URL: ddd_value_objects-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23e676f101b270ec8bb6838b8b91a62b433b15972eaf76609aacb53a59eb9858
|
|
| MD5 |
9dc2c431e7f1fd9b15400b1bd582645f
|
|
| BLAKE2b-256 |
c2f8788488f44668f43feaf56f143589e4de19ac7c6d7292f3435f8a9e7a93cb
|
Provenance
The following attestation bundles were made for ddd_value_objects-0.1.2-py3-none-any.whl:
Publisher:
code.yml on josedejesuschavez/ddd-value-objects
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ddd_value_objects-0.1.2-py3-none-any.whl -
Subject digest:
23e676f101b270ec8bb6838b8b91a62b433b15972eaf76609aacb53a59eb9858 - Sigstore transparency entry: 781975620
- Sigstore integration time:
-
Permalink:
josedejesuschavez/ddd-value-objects@f2bce15b95f85d5e45f36a4c312f158a8427826f -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/josedejesuschavez
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
code.yml@f2bce15b95f85d5e45f36a4c312f158a8427826f -
Trigger Event:
release
-
Statement type: