Value Object

Info:DDD Value Object implementation.
Author:Paweł Zadrożny @pawelzny <pawel.zny@gmail.com>
CI Status Documentation Status PyPI Repository Status Release Status Project Status Supported python versions Supported interpreters License

Features

  • Value object can’t be changed once created
  • Two objects with the same values are considered equal
  • Access to values after dot: value.my_value
  • Access to values like dict: value[‘my_value’]

Installation

pip install vo

Package: https://pypi.org/project/vo/

Documentation

Read full documentation on: http://vo.readthedocs.io

Quick Example

>>> from vo import Value
...
>>> class Book(Value):
...     price = None
...     title = None
...     publisher = None
...
>>> book = Book(price=120, title='Python for masses', publisher='SPAM')
>>> book
Book(price=120, title='Python for masses', publisher='SPAM')

>>> book.title
'Python for masses'

>>> book['price']
120

>>> book.price = 230
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    raise ImmutableInstanceError
vo.value.ImmutableInstanceError: Modification of Value instance is forbidden.