Registry / data / python-autoviv

python-autoviv

JSON →
library1.0.4pypypiunverified

python-autoviv provides autovivification for Python dictionaries, allowing the creation of deeply nested data structures on-the-fly simply by accessing keys. It mimics Perl's default behavior, eliminating the need for explicit intermediate dictionary initializations. The current version is 1.0.4, with releases focusing on stability and minor enhancements.

pip install python-autoviv
INSTALL
IMPORT
SIG · PYTHON-AUTOVIV
P
python-autoviv
datapythonv1.0.4
Install
2.7s avg
Import
Disk
28MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 31.7MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.7s · import 0.000s · 32MB
28MB installed
● package 28MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AutoVivification
from autoviv import AutoVivification
from autoviv import AutoVivification
dump
from autoviv import dump
load
from autoviv import load

Initialize an `AutoVivification` object and create nested dictionary structures by simply assigning values to deeply nested keys. Intermediate dictionaries are automatically created.

from autoviv import AutoVivification d = AutoVivification() d[1]['one'][2]['two'] = "Nested is as nested does." d[1]['one'][2]['three'] = "Or so they say." print(d) # Expected output: {1: {'one': {2: {'two': 'Nested is as nested does.', 'three': 'Or so they say.'}}}} # Accessing a non-existent path creates it if 'new_key' not in d[1]['one']: print("'new_key' does not exist in d[1]['one'] initially.") d[1]['one']['new_key']['sub_key'] = 42 print(f"Value at d[1]['one']['new_key']['sub_key']: {d[1]['one']['new_key']['sub_key']}") # Expected output: Value at d[1]['one']['new_key']['sub_key']: 42
Debug
Known issues
gotchaAutovivification can mask typos. If you misspell a key (e.g., `d['usrname']` instead of `d['username']`), it will silently create a new key instead of raising a `KeyError`, potentially leading to hard-to-debug data inconsistencies.
fix
Always double-check key names, especially when assigning. Consider using `dict.get()` with a default value or `if 'key' in d:` checks if you need to strictly verify key existence before modification.
affects: All versions
gotchaEvery intermediate key access implicitly creates a new `AutoVivification` instance if the path doesn't exist. For very sparse or deeply nested data structures, this could consume more memory than a carefully constructed regular dictionary, as many empty intermediate objects might be instantiated.
fix
Be mindful of performance for extremely large or sparse datasets. If memory is a critical concern, consider alternative strategies or ensure all vivified paths are eventually populated with meaningful data.
affects: All versions
gotchaConverting an `AutoVivification` instance to a standard Python `dict` using `dict(autoviv_instance)` will only convert the top level. Nested `AutoVivification` objects within the structure will remain `AutoVivification` instances, not standard `dict`s.
fix
To recursively convert the entire structure to standard Python dictionaries, you'll need a helper function that iterates through the `AutoVivification` instance and converts all nested instances as well.
affects: All versions
Upgrade
Version history
1.0.4latest on PyPI · released Jan 27, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
8
Resources
python-autoviv — pip install python-autoviv · libregistry