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.4.2.tar.gz
(3.7 kB
view details)
Built Distribution
File details
Details for the file deepfinder-1.4.2.tar.gz
.
File metadata
- Download URL: deepfinder-1.4.2.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67582207b32cefc22ada02e4003daccc0f10cbfdfac2c3aad30f170e15106e91 |
|
MD5 | 4bad37e881013ce3acbef4785680a3ee |
|
BLAKE2b-256 | aaf460f8f5f59f87d18abcc23252b3d0c012191235931ef29f55ea2ba1888b22 |
File details
Details for the file deepfinder-1.4.2-py3-none-any.whl
.
File metadata
- Download URL: deepfinder-1.4.2-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75d0a6ee602de34fb05945012b4ada515330fa7ee46b39c7a45b2163e96f774d |
|
MD5 | d43500e919f96633ab3733673325b290 |
|
BLAKE2b-256 | 719da401858767e2a82d1f8a3243e3a4c75bc9402eb4530b5523d6a5e2339602 |