Skip to main content

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 UuidValueObject con validación integrada.
  • Clase base para Entity con 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:

  1. Instala uv si no lo tienes.
  2. Sincroniza las dependencias:
    uv sync
    
  3. Ejecuta los tests:
    uv run pytest
    

Licencia

Este proyecto está bajo la licencia MIT.

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

ddd_value_objects-0.1.2.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

ddd_value_objects-0.1.2-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

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

Hashes for ddd_value_objects-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9901c958d6b39ac52a71d8ff91ca0a43272aa1086aa15b772d2f93eb7dce7410
MD5 e4d1ec970c09f3933516d8d7380be937
BLAKE2b-256 c5f502798103fc56375b12b0a8f1b560cad1cd615f743c622f818f19717dfcf4

See more details on using hashes here.

Provenance

The following attestation bundles were made for ddd_value_objects-0.1.2.tar.gz:

Publisher: code.yml on josedejesuschavez/ddd-value-objects

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ddd_value_objects-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ddd_value_objects-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 23e676f101b270ec8bb6838b8b91a62b433b15972eaf76609aacb53a59eb9858
MD5 9dc2c431e7f1fd9b15400b1bd582645f
BLAKE2b-256 c2f8788488f44668f43feaf56f143589e4de19ac7c6d7292f3435f8a9e7a93cb

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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