Search attributes easily using dot paths. Within structures of type dictionary, list and embedded substructures with simple format 'dict.users.0.name'.
pip install deepfinder
from deepfinder import deep_find
user: dict = {
'name': 'ash',
'links': {
'pokehub': '@ash'
},
}
print(deep_find(user, 'links.pokehub'))
# output: '@ash'
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'
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']
from deepfinder import deep_find
user: dict = {
'name': 'ash',
'pokemons': [
{
'name': 'pikachu',
},
{
'name': 'charmander',
'ball': 'superball'
}
]
}
print(deep_find(user, 'pokemons.?.ball'))
# output: 'superball'
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']
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'