Dictionaries as objects, that can have different dictionary views!
$ pip install thingy
>>> class MyThingy(Thingy)
... @property
... def foobaz(self):
... return self.foo + self.baz
>>> thingy = MyThingy({"foo": "bar", "baz": "qux"})
>>> thingy.foo
"bar"
>>> thingy.foobaz
"barqux"
>>> thingy.foo = "BARRRR"
>>> thingy.view()
{"foo": "BARRRR", "baz": "qux"}
>>> MyThingy.add_view(name="fooz", include=["foo", "foobaz"])
>>> MyThingy.add_view(name="no_foo", defaults=True, exclude="foo")
>>> thingy = MyThingy({"foo": "bar", "baz": "qux"})
>>> thingy.view("fooz")
{"foo": "bar", "foobaz": "barqux"}
>>> thingy.view("no_foo")
{"baz": "qux"}
Because it's much more enjoyable to write foo.bar
than foo["bar"]
.
Thingy is mainly meant to be used inside other libraries to provide abstractions over dictionaries, which can be useful for writing ORMs or similar utilities.
Thingy's views system is also particularly useful as-is when you intensively manipulate dictionaries and often restrict those dictionaries to a few redundant items.
To run Thingy tests:
- install developers requirements with
pip install -r requirements.txt
; - run
pytest
.
MIT