Skip to main content

A dict implementation with support for easy and clean access of its values through attributes

Project description

attridict

Build Status GitHub

A Python package implementing atrribute dictionary.

This provides an easier and cleaner way to access dict values using their keys as attributes. It is typically a dict child, maintaining all the dict functionalities, but including some extra features.

Installation

To install the package from PyPI, use:

pip install attridict

Usage

Creating an attridict object

>>> import attridict
>>> att = attridict()
>>> att
{}
>>> att.foo = "bar"
>>> att.foo
'bar'
>>> att
{'foo': 'bar'}

A dict can be converted into an attridict object by passing it as an argument

>>> import attridict

>>> data = {'red': 'hot', 'blue': 'cold'}

>>> colors = attridict(data)
>>> colors
{'red': 'hot', 'blue': 'cold'}

>>> colors.red
'hot'

Modifying attridict object

>>> import attridict

>>> data = {'red': 'hot', 'blue': 'cold'}

>>> colors = attridict(data)
>>> colors
{'red': 'hot', 'blue': 'cold'}

>>> colors.blue
'cold'

>>> colors.blue = "sky"
>>> colors.red = "rose"
>>> colors.blue
'sky'
>>> colors.red
'rose'
>>> colors
{'red': 'rose', 'blue': 'sky'}

>>> colors.green = "grass"
>>> colors
{'red': 'rose', 'blue': 'sky', 'green': 'grass'}

Typical dict operations work on attridict objects

>>> import attridict

>>> data = {'red': 'rose', 'blue': 'sky'}

>>> colors = attridict(data)
>>> colors
{'red': 'rose', 'blue': 'sky'}

>>> colors.red
'rose'
>>> colors["red"]
'rose'

>>> colors["red"] = "tomato"
>>> colors["red"]
'tomato'
>>> colors.red
'tomato'

Nested attribute access

>>> import attridict

>>> data = {'foo': {}}
>>> att = attridict(data)

>>> att
{'foo': {}}

>>> att.foo.bar = 'baz'

>>> att.foo.bar
'baz'

>>> att
{'foo': {'bar': 'baz'}}

License

The project is MIT licensed

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

attridict-0.0.7.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

attridict-0.0.7-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file attridict-0.0.7.tar.gz.

File metadata

  • Download URL: attridict-0.0.7.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for attridict-0.0.7.tar.gz
Algorithm Hash digest
SHA256 4b9c2b7a693d2c34f9892fbd11686ef0bb7c23de0215c85fd2cf73c0f4d11b42
MD5 5d6aba0eb68b9294233ec47b8e83df83
BLAKE2b-256 3166d21d8a22639153b8d16c1fd84f3b455e41841bd43fc14b6eadd7ea7b965a

See more details on using hashes here.

File details

Details for the file attridict-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: attridict-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for attridict-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 a6b33fd8e1a2c11e4edd0161e8df2d108d699bce61e2f7787af89ef5c7ddae0c
MD5 58d68e0120fdb9929cc161b6e0ebe8ae
BLAKE2b-256 77721fa3cadf2c5f52764b4a33f6c16b7f744cab6380222f8aae7bc02e3ecc43

See more details on using hashes here.

Supported by

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