Registry / serialization / dictor

dictor

JSON →
library0.1.12pypypi✓ verified 87d ago

Dictor is a Python JSON and Dictionary (Hash, Map) handler. It takes a dictionary or JSON data and returns a value for a specific key, simplifying access to deeply nested structures. Its primary goal is to eliminate the need for repetitive `try/except` blocks when performing lookups and to provide flexible fallback values for missing keys. The current version is 0.1.12, with new releases typically driven by feature additions or bug fixes rather than a strict cadence.

pip install dictor
INSTALL
IMPORT
SIG · DICTOR
D
dictor
serializationpythonv0.1.12
Install
2.4s avg
Import
10ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.12 · 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.920 runs
installs and imports cleanly · install 0.0s · import 0.006s · 19.2MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.4s · import 0.006s · 20MB
17MB installed
● package 17MB
Code
Verified usage

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

dictor
from dictor import dictor

This example demonstrates basic usage of `dictor` to safely retrieve nested values from a dictionary using dot notation, providing a default value for non-existent keys, and accessing elements within lists.

import json from dictor import dictor data = { "characters": { "Lonestar": { "id": 55923, "role": "renegade", "items": ["space winnebago", "leather jacket"] }, "Barfolomew": { "id": 55924, "role": "mawg", "items": ["peanut butter jar", "waggy tail"] } } } # Accessing a nested value using dot notation lonestar_role = dictor(data, "characters.Lonestar.role") print(f"Lonestar's role: {lonestar_role}") # Accessing a non-existent key with a fallback default value dark_helmet_role = dictor(data, "characters.Dark Helmet.role", default="villain") print(f"Dark Helmet's role: {dark_helmet_role}") # Accessing an item from a list by index first_lonestar_item = dictor(data, "characters.Lonestar.items.0") print(f"First item for Lonestar: {first_lonestar_item}")
Debug
Known issues
breakingDictor versions 0.1.13 and up will drop support for Python 2. Users on Python 2 must remain on version 0.1.12 or earlier.
fix
If currently using Python 2, either upgrade your project to Python 3 or explicitly pin the `dictor` dependency to `dictor==0.1.12` in your `requirements.txt`.
affects: >=0.1.13
gotchaIf a dictionary key contains a literal dot ('.') character (e.g., `'my.key'`), `dictor` will by default interpret it as a path separator, potentially leading to `None` or an incorrect value. For example, `dictor({'my.key': 'value'}, 'my.key')` will return `None` because it tries to find a nested `key` within `my`.
fix
Use the `pathsep` argument to specify a different character for path separation (e.g., `dictor(data, 'my.key', pathsep='_')`) or ensure keys with dots are not used in dot-separated search paths.
affects: all
gotchaWhen `checknone=True` is passed to `dictor`, it will raise a `ValueError` if the value found at the specified path is `None`. This can lead to unexpected program termination if `None` is a valid intermediate value.
fix
Only use `checknone=True` when `None` is explicitly considered an invalid value for the path, and you intend for a `ValueError` to be raised. Otherwise, rely on the default behavior where `None` is returned, or provide a `default` fallback value.
affects: all
gotchaThe `rtype` argument, used to cast the return value to a specific type (e.g., `int`, `str`), only applies to scalar values. If the value found at the specified path is a complex data structure (like a dictionary, list, or tuple), it will be returned as is, regardless of the `rtype` specified.
fix
Be aware that `rtype` does not enforce type conversion for complex data structures; manual casting or further processing may be required if a specific type for these is desired.
affects: all
Errors
Common errors & fixes
ValueError
The `dictor` function was called with the `checknone=True` argument, and the value found at the specified path in the dictionary or JSON data was `None`.
fix
If `None` is an acceptable value for the path, remove `checknone=True` from the `dictor` call. Alternatively, ensure the data at the specified path is not `None` or provide a `default` fallback value to `dictor`.
AttributeError: 'list' object has no attribute 'get'
The `dictor` function returned a list because the specified path pointed to a list, but the user then attempted to use the `.get()` method, which is a dictionary-specific method, on the returned list object.
fix
If the `dictor` call is expected to return a list, access its elements using list indexing (e.g., `my_list[0]`) or iterate over it. If a dictionary *within* the list is intended, adjust the path in `dictor` or perform list indexing before making another `dictor` call or using dictionary methods.
AttributeError: 'NoneType' object has no attribute 'some_method'
This error typically occurs when a dictionary key contains a literal dot ('.'), which `dictor` by default interprets as a path separator. This leads `dictor` to search for a non-existent nested structure and return `None`, and a subsequent operation attempts to call a method or access an attribute on this `None` object.
fix
If your dictionary keys contain literal dots, use the `pathsep` argument in `dictor` to specify a different character for path separation (e.g., `dictor(data, 'my.key', pathsep='_')`) or ensure such keys are not used in dot-separated search paths.
Upgrade
Version history
0.1.12latest on PyPI · released Sep 15, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
dictor — pip install dictor · libregistry