Skip to main content

a dict with key attributes

Project description

a dict with key attributes

pip install punktdict

This module provides the PunktDict class, which is a subclass of dict with additional functionality for handling nested dictionaries. It also provides some configuration options through the dictconfig object.

import sys
from punktdict import PunktDict, dictconfig, convert_to_dict

# Configure PunktDict behavior
dictconfig.allow_nested_attribute_creation = True
dictconfig.allow_nested_key_creation = True
dictconfig.convert_all_dicts_recursively = True
PunktDict._check_forbidden_key = (
    lambda self, x: (x.startswith("_ipython") or x == "_repr_mimebundle_")
)

# Create a PunktDict object
d = PunktDict({'popeye': {'mole': {'bole': 'dolle'}}})

# Access and modify nested dictionary values
d['hallo']['baba'] = 11
d.lll.ddd.xxx = 333

# Update PunktDict with new data
d.update({'rrrx': {'xxxxx': 'bbbb'}})
d.rrrx.xxxxxxx = []
d.rrrx.xxxxxxx.append(3)

# Access nested dictionary values using attribute syntax
d['gggg']['xxxxx']['tttt'] = 12
print(d.gggg.xxxxx.tttt)

# Convert PunktDict to a regular dictionary
di = convert_to_dict(d)
---------------

Attributes:
-----------
- allow_nested_attribute_creation: A boolean flag indicating whether PunktDict allows creation of nested attributes. Default is True.
- allow_nested_key_creation: A boolean flag indicating whether PunktDict allows creation of nested keys. Default is True.
- convert_all_dicts_recursively: A boolean flag indicating whether PunktDict recursively converts all nested dictionaries to PunktDict objects. Default is True.

Classes:
--------
- PunktDict: A subclass of dict with additional functionality for handling nested dictionaries.

Functions:
----------
- check_if_compatible_dict: Checks if an object is a compatible dictionary based on its type and attributes.
- convert_to_dict: Recursively converts a PunktDict object or a compatible dictionary to a regular dictionary.

Note:
-----
The `PunktDict` class overrides several methods and provides additional methods to handle nested dictionaries. The configuration options can be modified through the `dictconfig` object. The `convert_to_dict` function can be used to convert a PunktDict object or a compatible dictionary to a regular dictionary.

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

punktdict-0.11.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

punktdict-0.11-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file punktdict-0.11.tar.gz.

File metadata

  • Download URL: punktdict-0.11.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for punktdict-0.11.tar.gz
Algorithm Hash digest
SHA256 e46317d633ab927165aa7e1df82a1ddfcf44068bd1cfb02687c1335248129a00
MD5 89415f50161d5abee349200000b604a0
BLAKE2b-256 f9cfc4cd7742e4f636714d4cf91e1d269df0f679161f325ada06dfdc6fc7d125

See more details on using hashes here.

File details

Details for the file punktdict-0.11-py3-none-any.whl.

File metadata

  • Download URL: punktdict-0.11-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for punktdict-0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 c7e73cdced9fe34d93f55443b9719c1fcf037d3124e64dfcfb4d112426fbe8f0
MD5 de91f49c8b67ac9e42ca2bc6f4b17732
BLAKE2b-256 8adb506414fd5207c9d680b590fe6fd2776e5ef4c577901227d95f83f72d29da

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