Code Monkey home page Code Monkey logo

deepfinder.py's Introduction

๐Ÿ” Deepfinder

GitHub Pypi Downloads GA

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'

deepfinder.py's People

Contributors

alberlc avatar jparadadev avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

alberlc

deepfinder.py's Issues

Dictionary with numeric keys not working

Dictionary with numeric keys not working
Dictionary access with numeric values not working. All dictionary access use strings as keys.

To Reproduce

a = { 1: 'potato' }
output = deep_find(a, '#1')
print(output) # None

Expected behavior
It should return the string.

Add frozen set support

Bug description
When exploring a Frozen set, null value is always returned.

To Reproduce
Just add a Frozen set at any level

from deepfinder import deep_find
data = { 'a-tuple': frozenset((1,2,3,4,5)) }
print(deep_find(data, 'a-tuple.2'))
# output: None

Add set support

Bug description
When exploring a set, null value is always returned.

To Reproduce
Just add a set at any level

from deepfinder import deep_find
data = { 'a-set': set([1,2,3,4,5]) }
print(deep_find(data, 'a-set.2'))
# output: None

Expected behavior
It should explore the set as if it were an array

Add tuple support

Bug description
When exploring a Tuple, null value is always returned.

To Reproduce
Just add a tuple at any level

from deepfinder import deep_find
data = { 'a-tuple':(1,2,3,4,5) }
print(deep_find(data, 'a-tuple.2'))
# output: None
# expected: 3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.