Skip to main content

dddentity

PyPI PyPI - Python Version Code style: black license

DDD entity.

Usage

from dddentity import Entity, ref

UserId = str


class User(Entity[UserId]):
    def __init__(self, id: UserId, name: str) -> None:
        self.id = id
        self.name = name

    def _ref_(self) -> UserId:
        return self.id


assert User("0001", "Gilgamesh") == User("0001", "Bilgamesh")

assert ref(User("0002", "Enkidu")) == "0002"

Caveat

Currently eq=False must be set when using with dataclasses to prevent to generate __eq__() method by dataclass.

@dataclass(eq=False)
class User(Entity[UserId]):
    ...

API

Module dddentity

abstract class Entity[T]

Entity class. Classes implementing this class must implement abstract method _ref_().

This class is hashable, satisfying the following conditions:

  • entity1 == entity2 iff entity1._ref_() == entity2._ref_()
  • hash(entity) == hash(entity._ref_())

where entity, entity1, entity2 are entities.

type parameter T

Type of the identifier of the entity, which must be hashable.

abstract method _ref_() -> T

Shall return the identifier of the entity.

function ref(entity: Entity[T]) -> T

Return entity._ref_().

Release files for dddentity 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dddentity 0.1.0
File Size Uploaded
dddentity-0.1.0.tar.gz 3.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dddentity 0.1.0
File Interpreter ABI Platform
dddentity-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.5 kB

Release files / dddentity-0.1.0.tar.gz

Download URL dddentity-0.1.0.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1ac702a841b7b2c2747ad1059853c478bded70c6384921d9a43cead7856446b8
BLAKE2b-256 checksum
How to use checksums
7d5d8fe317dc03da8173645167f2819cf67adcddd5ba07c602a7a3df6fcee80a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/2.7.12 Darwin/20.2.0

Release files / dddentity-0.1.0-py3-none-any.whl

Download URL dddentity-0.1.0-py3-none-any.whl
Size 3.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4320953c4757428fbb4b9e7c4b030eadf67b2d252790755610bfd10a13e9e867
BLAKE2b-256 checksum
How to use checksums
8104516782a5ff46fac5e3eaf4490b32c8f91204d168d2d2d5b29d759fa5f308
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/2.7.12 Darwin/20.2.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page