Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.
/ nesdict Public archive

Support for xpath-like lookups in nested Python dicts

License

Notifications You must be signed in to change notification settings

steersbob/nesdict

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NesDict

Build Status

Intended to add easy-to-use lookup syntax to Python's builtin dict(), removing the need to chain [] operators or .get() calls.

Example:

from nesdict import NesDict

xdata = NesDict({
    'path': {
        'to': {
            'nested': {
                'value': 'stuff',
                'thing': 'more stuff',
                'number': 42
            },
            'something': 'else'
        }
    }
})

xdata['/path/to/nested/value'] == 'stuff'

xdata.search('/path/to/nested/*') == [
    ('/path/to/nested/value', 'stuff'), 
    ('/path/to/nested/thing', 'more stuff'),
    ('/path/to/nested/number', 42)
]

xdata.values() == ['stuff', 'more stuff', 42, 'else']

It also supports setting new values using the same syntax:

xdata['/path/less/traveled/by'] = 'all the difference'

xdata['/path'] == {
    'to': {
            'nested': {
                'value': 'stuff',
                'thing': 'more stuff',
                'number': 42
            },
            'something': 'else'
    },
    'less': {
        'traveled': {
            'by': 'all the difference'
        }
    }
}

About

Support for xpath-like lookups in nested Python dicts

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages