Overview

Metadata

A configurable metadata container. Accepts only preconfigured keys and enforces type for key's value.

Example:

>>> from metadata import Metadata
>>> ALLOWED_KEYS = {
...     'id': int,
...     'name': str
... }
>>> m = Metadata(ALLOWED_KEYS)
>>> m.name = 'foo'
>>> m.id = '23'
Traceback (most recent call last):
  ...
TypeError: attribute "id" only allows type "int"
>>> m.id = 23
>>> m.name, m.id
('foo', 23)
>>> m.bar = 'baz'
Traceback (most recent call last):
  ...
AttributeError: attribute "bar" not allowed

You can also use a dictionary or a list of tuples to fill the Metadata instance during initialization:

>>> from metadata import Metadata
>>> ALLOWED_KEYS = {
...     'id': int,
...     'name': str
... }
>>> DATA = {
...     'id': 23,
...     'name': 'foo'
... }
>>> m = Metadata(ALLOWED_KEYS, DATA)
>>> m.id, m.name
(23, 'foo')

Contributions and Bugs

Feel free to improve metadata. Pull requests are welcome!

Please report problems to our issue tracker.

Run the Test Suite

To run the test suite just execute the included test runner:

$ ./runtests.py

Author

Markus Zapke-Gründemann

License

This is Open Source Software. See LICENSE for detailed information.