GithubHelp home page GithubHelp logo

isabella232 / dotty_dict Goto Github PK

View Code? Open in Web Editor NEW

This project forked from qmk/dotty_dict

0.0 0.0 0.0 253 KB

Dictionary wrapper for quick access to deeply nested keys.

Home Page: http://dotty-dict.readthedocs.io

License: MIT License

Makefile 2.71% Python 97.29%

dotty_dict's Introduction

Dotty-Dict

Info

Dictionary wrapper for quick access to deeply nested keys.

Author

Pawel Zadrozny @pawelzny <[email protected]>

This is a package published by QMK (https://qmk.fm) since the current dotty-dict published to pypi has non-ASCII characters that breaks with some non-UTF8 locale settings.

Features

  • Simple wrapper around python dictionary and dict like objects
  • Two wrappers with the same dict are considered equal
  • Access to deeply nested keys with dot notation: dot['deeply.nested.key']
  • Create, read, update and delete nested keys of any length
  • Expose all dictionary methods like .get, .pop, .keys and other
  • Access dicts in lists by index dot['parents.0.first_name']
  • key=value caching to speed up lookups and low down memory consumption
  • support for setting value in multidimensional lists
  • support for accessing lists with slices

Installation

pip install dotty-dict

Documentation

TODO

Waiting for your feature requests ;)

Quick Example

Create new dotty using factory function.

>>> from dotty_dict import dotty
>>> dot = dotty({'plain': {'old': {'python': 'dictionary'}}})
>>> dot['plain.old']
{'python': 'dictionary'}

You can start with empty dotty

>>> from dotty_dict import dotty
>>> dot = dotty()
>>> dot['very.deeply.nested.thing'] = 'spam'
>>> dot
Dotty(dictionary={'very': {'deeply': {'nested': {'thing': 'spam'}}}}, separator='.', esc_char='\\')

>>> dot['very.deeply.spam'] = 'indeed'
>>> dot
Dotty(dictionary={'very': {'deeply': {'nested': {'thing': 'spam'}, 'spam': 'indeed'}}}, separator='.', esc_char='\\')

>>> del dot['very.deeply.nested']
>>> dot
Dotty(dictionary={'very': {'deeply': {'spam': 'indeed'}}}, separator='.', esc_char='\\')

>>> dot.get('very.not_existing.key')
None

NOTE: Using integer in dictionary keys will be treated as embedded list index.

Install for development

Install dev dependencies

$ make install

Testing

$ make test

Or full tests with TOX:

$ make test-all

Limitations

In some very rare cases dotty may not work properly.

  • When nested dictionary has two keys of different type, but with the same value. In that case dotty will return dict or list under random key with passed value.
  • Keys in dictionary may not contain dots. If you need to use dots, please specify dotty with custom separator.
  • Nested keys may not be bool type. Bool type keys are only supported when calling keys with type defined value (e.g. dot[True], dot[False]).

dotty_dict's People

Contributors

pawelzny avatar dysproz avatar pyup-bot avatar skullydazed avatar amotl avatar linusg avatar aneeshd16 avatar kalebdfischer avatar kingdarboja avatar

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.