Plucking (deep) keys/paths safely from python collections has never been easier.
Project description
plucky.pluck enables you to safely extract several-levels deep values by using a concise selector comprised of dictionary-like keys and list-like indices. Wildcards over list items are also supported.
Usage
from plucky import pluck
pluck(obj, 'selector.*.path.2')
Examples
obj = {
'users': [{
'uid': 1234,
'name': {
'first': 'John',
'last': 'Smith',
}
}, {
'uid': 2345,
'name': {
'last': 'Bono'
}
}]
}
pluck(obj, 'users.1.name')
# -> {'last': 'Bono'}
pluck(obj, 'users.*.name.last')
# -> ['Smith', 'Bono']
pluck(obj, 'users.*.name.first')
# -> ['John']
More Examples! :)
pluck([1,2,3], '2')
# -> 3
pluck([1,2,3], '-1')
# -> 3
pluck([1,2,3], '*')
# -> [1,2,3]
pluck([1, {'val': 2}, 3], '*.val')
# -> [2]
pluck([1, {'val': [1,2,3]}, 3], '1.val.-1')
# -> 3
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
plucky-0.2.tar.gz
(3.4 kB
view hashes)