Value Object
- Info:
DDD Value Object implementation.
- Author:
Paweł Zadrożny @pawelzny <pawel.zny@gmail.com>
Features
Value Objects are immutable.
Two objects with the same values are considered equal
Access to values with dot notation: value.my_attr
Access to values by key: value['my_attr']
Installation
pipenv install vo # or pip install vo
Package: https://pypi.org/project/vo/
Documentation
Full documentation: http://vo.readthedocs.io
Public API: http://vo.readthedocs.io/en/latest/api.html
Examples and usage ideas: http://vo.readthedocs.io/en/latest/examples.html
Quick Example
Value accept any key=value pairs. These pairs will be attached to object as attributes. Once created values are immutable. Attributes can’t be changed or deleted.
>>> from vo import Value
>>> book = Value(title='Learning Python',
... authors=['Mark Lutz', 'David Ascher'],
... publisher="O'REILLY")
>>> book
Value(authors=['Mark Lutz', 'David Ascher'], publisher="O'REILLY", title='Learning Python')
>>> str(book)
'{"authors": ["Mark Lutz", "David Ascher"], "publisher": "O\'REILLY", "title": "Learning Python"}'
>>> from vo import Value
>>> book = Value(title='Learning Python',
... authors=['Mark Lutz', 'David Ascher'],
... publisher="O'REILLY")
>>> book.title = 'Spam'
Traceback (most recent call last):
File "<input>", line 1, in <module>
raise ImmutableInstanceError()
vo.value.ImmutableInstanceError: Modification of Value frozen instance is forbidden.
Values access
Values can be accessed like object attributes or like dict keys.
>>> from vo import Value
>>> book = Value(title='Learning Python',
... authors=['Mark Lutz', 'David Ascher'],
... publisher="O'REILLY")
>>> book.title == book['title']
True
>>> book.authors == book['authors']
True
Objects comparison
Let’s take the same book example.
>>> from vo import Value
>>> book1 = Value(title='Learning Python',
... authors=['Mark Lutz', 'David Ascher'],
... publisher="O'REILLY")
>>> book2 = Value(title='Learning Python',
... authors=['Mark Lutz', 'David Ascher'],
... publisher="O'REILLY")
>>> book1 == book2
True
>>> book1 is book2
False
Value lookup
Check if value exists.
>>> from vo import Value
>>> book = Value(title='Learning Python',
... authors=['Mark Lutz', 'David Ascher'],
... publisher="O'REILLY")
>>> 'title' in book
True
>>> 'price' in book
False
>>> book.title
'Learning Python'
>>> book.price
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'Value' object has no attribute 'price'
Metadata
Release files for vo 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vo-1.0.0.tar.gz | 32.4 kB | Without provenance | Details for vo-1.0.0.tar.gz |
Release files / vo-1.0.0.tar.gz
| Download URL | vo-1.0.0.tar.gz |
|---|---|
| Size | 32.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
41de934bf99f1517b5b583ca16500cdb899d6c7d0216eb0897a8e3e6dd217708
|
|
BLAKE2b-256 checksum How to use checksums |
5d94b2afbc4192c6a16568d4a3094531628baab9a3818485340f066213de924b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for vo 1.0.0
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.