plucky
raw JSON → 0.4.3 verified Fri May 01 auth: no python maintenance
Plucking (deep) keys/paths safely from python collections has never been easier. Version 0.4.3. Low activity, last release Jul 2021.
pip install plucky Common errors
error AttributeError: module 'plucky' has no attribute 'pluck' ↓
cause Importing incorrectly (e.g., import plucky then plucky.pluck) but module exposes functions only via direct import.
fix
Use 'from plucky import pluck' instead of 'import plucky' and plucky.pluck.
error KeyError: 'missing' ↓
cause Using pluck without a default or safe mode when path doesn't exist.
fix
Add default parameter: pluck(data, 'missing.key', default=None).
error ValueError: invalid literal for int() with base 10: 'key' ↓
cause Path segment is not a valid integer index when accessing a list element.
fix
Ensure path segments for list indices are integers, e.g., 'items.0.name'.
Warnings
gotcha pluck raises KeyError by default if path does not exist; use default= or safe=True to avoid exceptions. ↓
fix Use pluck(data, 'missing.key', default=None) or pluck(data, 'missing.key', safe=True).
gotcha Path syntax uses dot-separated keys and integer indices for lists (e.g., 'a.0.b'), not bracket notation. ↓
fix Use 'items.0.name' instead of 'items[0].name'.
deprecated The function 'plucks' (plural) is deprecated in favor of 'pluck' with safe=True or default. ↓
fix Replace plucks(data, path) with pluck(data, path, default=...).
Imports
- pluck
from plucky import pluck - set_keys
from plucky import set_keys
Quickstart
from plucky import pluck, set_keys
data = {'a': {'b': [{'c': 1}, {'c': 2}]}}
# pluck deep key
result = pluck(data, 'a.b.0.c')
print(result) # 1
# set deep key
set_keys(data, 'a.b.0.c', 42)
print(pluck(data, 'a.b.0.c')) # 42