Skip to main content

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.

Release files for punktdict 0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for punktdict 0.11
File Size Uploaded
punktdict-0.11.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for punktdict 0.11
File Interpreter ABI Platform
punktdict-0.11-py3-none-any.whl Python 3 none any Details

Total release size: 10.7 kB

Release files / punktdict-0.11.tar.gz

Download URL punktdict-0.11.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e46317d633ab927165aa7e1df82a1ddfcf44068bd1cfb02687c1335248129a00
BLAKE2b-256 checksum
How to use checksums
f9cfc4cd7742e4f636714d4cf91e1d269df0f679161f325ada06dfdc6fc7d125
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release files / punktdict-0.11-py3-none-any.whl

Download URL punktdict-0.11-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c7e73cdced9fe34d93f55443b9719c1fcf037d3124e64dfcfb4d112426fbe8f0
BLAKE2b-256 checksum
How to use checksums
8adb506414fd5207c9d680b590fe6fd2776e5ef4c577901227d95f83f72d29da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release history Release notifications | RSS feed

This release

0.11 This release

2 release files

0.10

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page