Search attributes easily using dot paths. Within structures of type dictionary, list and embedded substructures with simple format 'dict.users.0.name'.
Project description
Deepfinder
Search attributes easily using dot paths. Within structures of type dictionary, list and embedded substructures with simple format 'dict.users.0.name'.
Getting Started
Installation
pip install deepfinder
Usage
Basic sample
from deepfinder import deep_find
user: dict = {
'name': 'ash',
'links': {
'pokehub': '@ash'
},
}
print(deep_find(user, 'links.pokehub'))
# output: '@ash'
List sample
from deepfinder import deep_find
user: dict = {
'name': 'ash',
'pokemons': [
{
'name': 'pikachu',
'type': 'electric'
},
{
'name': 'charmander',
'type': 'fire'
}
]
}
print(deep_find(user, 'pokemons.0.name'))
# output: 'pikachu'
List all result sample
from deepfinder import deep_find
user: dict = {
'name': 'ash',
'pokemons': [
{
'name': 'pikachu',
'type': 'electric'
},
{
'name': 'charmander',
'type': 'fire'
}
]
}
print(deep_find(user, 'pokemons.*.name'))
# output: ['pikachu', 'charmander']
Find the first non-null result
from deepfinder import deep_find
user: dict = {
'name': 'ash',
'pokemons': [
{
'name': 'pikachu',
},
{
'name': 'charmander',
'ball': 'superball'
}
]
}
print(deep_find(user, 'pokemons.?.ball'))
# output: 'superball'
Find all non-null results
from deepfinder import deep_find
user: dict = {
'name': 'ash',
'pokemons': [
{
'name': 'pikachu',
},
{
'name': 'charmander',
'ball': 'superball'
},
{
'name': 'lucario',
'ball': 'ultraball'
}
]
}
print(deep_find(user, 'pokemons.*?.ball'))
# output: ['superball', 'ultraball']
Use custom dict and list
from deepfinder.entity import DeepFinderDict
user: dict = DeepFinderDict({
'name': 'ash',
'pokemons': [
{
'name': 'pikachu'
},
{
'name': 'charmander',
'ball': 'superball'
}
]
})
print(user.deep_find('pokemons.?.ball'))
# output: 'superball'
from deepfinder.entity import DeepFinderList
users: list = DeepFinderList([{
'name': 'ash',
'pokemons': [
{
'name': 'pikachu'
},
{
'name': 'charmander',
'ball': 'superball'
}
]
}])
print(users.deep_find('0.pokemons.?.ball'))
# output: 'superball'
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
deepfinder-1.3.0.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for deepfinder-1.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a7b8633f571ecf28ae4a4504933841774b8196da241c11f09651467d74736df |
|
MD5 | 6e1dfa46419b4ce99f6073b91b30e08d |
|
BLAKE2b-256 | 1e80623dab19a24c57f96745a36813a08bd424044cbf5353f7e021ebc50f0ac5 |