Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

Coverage Status PyPI - License PyPI PyPI Mypy

pyddd

pyddd - это DDD (Domain-Driven Design) фреймворк для Python, предоставляющий встроенный менеджер зависимостей и шину сообщений. Он упрощает построение сложных доменных моделей и событийное программирование.

Возможности

  • Разделение доменов через Module
  • Использование команд и событий (DomainCommand, DomainEvent)
  • Корневые сущности (RootEntity) и управление идентификаторами (EntityId)
  • Встроенный менеджер зависимостей
  • Событийно-ориентированная архитектура

Быстрый старт

Определение доменной модели

class PetCreated(DomainEvent, domain='pet'):
    pet_id: str
    name: str


class Pet(RootEntity):
    def __init__(self, name: str):
        self.name = name

    @classmethod
    def create(cls, name: str):
        pet = cls(name)
        pet.register_event(PetCreated(name=name, pet_id=pet.__reference__))
        return pet

Репозитории и модуль

class IPetRepository(abc.ABC):
    @abc.abstractmethod
    def save(self, entity: RootEntity):
        ...

    @abc.abstractmethod
    def get(self, name: str) -> Pet:
        ...


class CreatePet(DomainCommand, domain='pet'):
    name: str


pet_module = Module('pet')


@pet_module.register
def create_pet(cmd: CreatePet, repository: IPetRepository):
    pet = Pet.create(cmd.name)
    repository.save(pet)
    return pet.__reference__

Запуск приложения

class InMemoryPetRepo(IPetRepository):
    def __init__(self):
        self.memory = {}

    def get(self, name: str) -> Pet:
        return self.memory.get(name)

    def save(self, entity: Pet):
        self.memory[entity.name] = entity


# Настройка приложения
app = Application()
app.run()
app.include(pet_module)
app.set_defaults('pet', repository=InMemoryPetRepo())
set_application(app)

# Использование
fluff_id = app.handle(CreatePet(name='Fluff'))
print(f'Создан питомец с ID: {fluff_id}')

Запуск интеграционных тестов:

# Поднимаем внешние сервисы
docker-compose up -d

# Запуск тестов
pytest tests

Лицензия

Этот проект распространяется под лицензией MIT. Подробности см. в файле LICENSE.

Контрибьюция

Мы приветствуем ваш вклад! Создавайте issue, присылайте pull request'ы и помогайте развивать pyddd.

Контакты

Если у вас есть вопросы или предложения, свяжитесь с нами через GitHub Issues.

Metadata

Release files for ddd-python 0.7.7

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

Source distribution (sdist)

Source distribution for ddd-python 0.7.7
File Size Uploaded Provenance Actions
ddd_python-0.7.7.tar.gz 20.0 kB Without provenance Details for ddd_python-0.7.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ddd-python 0.7.7
File Interpreter ABI Platform Actions
ddd_python-0.7.7-py3-none-any.whl Python 3 none any Details for ddd_python-0.7.7-py3-none-any.whl

Total release size: 57.0 kB

Release files / ddd_python-0.7.7.tar.gz

Download URL ddd_python-0.7.7.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d778912b93d485b7f8d7772c5399b488ec327ca4f5d6131a940b33c365d692af
BLAKE2b-256 checksum
How to use checksums
0897c384f068c0eccf089c420b2c7a9f73025a0615947aac5a5ab6e090753e21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.11.4 Darwin/24.2.0

Release files / ddd_python-0.7.7-py3-none-any.whl

Download URL ddd_python-0.7.7-py3-none-any.whl
Size 37.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d74bbd92d534a4a7a0032ec6f3bf16f556fbd8443c175f89be29ac25e049531d
BLAKE2b-256 checksum
How to use checksums
cb91cafd25947b99cdce5d0ed109998792541584c23a3c086171b85f32c5bc4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.11.4 Darwin/24.2.0

Security for ddd-python 0.7.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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