Skip to main content

Dictionary as an object, that can have different views

Project description

https://img.shields.io/pypi/v/thingy.svg https://img.shields.io/github/license/Refty/thingy.svg https://img.shields.io/travis/Refty/thingy.svg https://img.shields.io/coveralls/Refty/thingy.svg https://readthedocs.org/projects/python-thingy/badge

Dictionaries as objects, that can have different dictionary views!

Install

$ pip install thingy

Examples

Dictionaries as objects…

>>> 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"}

…that can have different dictionary views!

>>> 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"}

Why Thingy?

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.

Tests

To run Thingy tests:

  • install developers requirements with pip install -r requirements.txt;

  • run pytest.

Sponsors

Numberly

Refty

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Thingy-0.10.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

Thingy-0.10.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file Thingy-0.10.0.tar.gz.

File metadata

  • Download URL: Thingy-0.10.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for Thingy-0.10.0.tar.gz
Algorithm Hash digest
SHA256 a372734da8e723ee5e2e6178dec5230b07195db8bf3121f23a44efb4d8aeac71
MD5 f14d1e3a342690d4179a837cc09c3e77
BLAKE2b-256 8ba817bd2539b6c8d0cc23c875e8af8691ed400dca178fc56946b37616a336c1

See more details on using hashes here.

File details

Details for the file Thingy-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: Thingy-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for Thingy-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 438394e6bd415962f7558442a47680d9e87b661cbf3fa8831904205143a0459e
MD5 80ae2a763eca954a57e254abb02cc5ad
BLAKE2b-256 76774c999ef19be1eab8b3ffdcf2cde77426030a0f4763061f54e92a97738912

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page