You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

dixi

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dixi

Wrapper around Python dicts that makes it easy to deal with nested tree structures.

0.0.1
pipPyPI
Maintainers
1

Dixi - Deep Dictionaries for Python

Installation

pip install dixi

Examples

from dixi import Dixi

data = Dixi({
    'Chris': {
        'age': 25,
        'address': {
            'city': 'Amsterdam',
            'country': 'Netherlands',
        },
    },
    'Anna': {
        'age': 19,
        'address': {
            'city': 'Zürich',
            'country': 'Switzerland',
        },
    },
    'John': {
        'age': 44,
        'address': {
            'city': 'London',
            'country': 'United Kingdom',
        },
    },
})

Deep indexing

data['John', 'age']
# >> 44

Partial indexing

data['Chris', 'address']
# >> {'city': 'Amsterdam', 'country': 'Netherlands'}

NumpPy style slicing

data[:, 'address', 'country']
# >> Dixi({'Chris': 'Netherlands', 'Anna': 'Switzerland', 'John': 'United Kingdom'})
data[['Chris', 'Anna'], 'age']
# >> {'Chris': 25, 'Anna': 19}

Setting

data['Derek', 'hobbies'] = ['Sewing', 'Archery']

Iteration

for key in data: # or key in data.leafkeys()
    print(key)
# >> ('Chris', 'age')
# >> ('Anna', 'age')
# >> ('Anna', 'address', 'city')
# >> ('Anna', 'address', 'country')
# >> ('John', 'age')
# >> ('John', 'address', 'city')
# >> ('John', 'address', 'country')
# >> ('Derek', 'hobbies')
for key in data.keys():
    print(key)
# >> Chris
# >> Anna
# >> John
# >> Derek
for key, value in data.items():
    print(key, value)
# >> Chris {'age': 25}
# >> Anna {'age': 19, 'address': {'city': 'Zürich', 'country': 'Switzerland'}}
# >> John {'age': 44, 'address': {'city': 'London', 'country': 'United Kingdom'}}
# >> Derek {'hobbies': ['Sewing', 'Archery']}
data = Dixi({
    0: {  0: 'a', 1: 'b' },
    1: { 0: 'c', 1: 'd' },
})
for keys, value in data.iterleaves():
    print(keys, value)
# >> (0, 0) a
# >> (0, 1) b
# >> (1, 0) c
# >> (1, 1) d

Deletion

del data['Chris', 'address']

Todo

  • Allow indexing for arrays

Keywords

dict

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts