Skip to main content

A library for accessing deep structures from simple text statements

Project description

The problem

Say you have a configuration file, or command line options, or whatever. And you want to have user-specified elements reference deep portions of a structure that you've defined, read in from yaml or json, or whatever. How?

This solution

(because there are likely others)

Users don't understand complex syntax, so this makes it easy to access deep dict or arrays with keys and numbers separated by a "." character.

A working demonstration

import dotnest

data = {
    'subdict': {
        'arrrr': ["there", "she", "blows",]
    },
    'list': [
        {'name': 'element1'}, {'name': 'element2'}
    ]
}

dn = dotnest.DotNest(data)
print(dn.get("subdict.arrrr.1"))       # she
print(dn.get("list.1.name"))           # element1

dn.set("subdict.newentry", "bar")
print(dn.get("subdict.newentry"))      # bar
print(dn.get("list.0"))                # {'name': 'element1'}

dn.get("does.not.exist")               # raises ValueError
dn.get("does.not.exist", 
       return_none=True)               # None

Used by

This class can be best married with tools that read in and need to referenc YAML or JSON as mentioned. As such, the original source of this effort comes from the package that converts from a netbox nestetd structure to ansible: nb2an.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dotnest-1.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

dotnest-1.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file dotnest-1.1.tar.gz.

File metadata

  • Download URL: dotnest-1.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.26.0

File hashes

Hashes for dotnest-1.1.tar.gz
Algorithm Hash digest
SHA256 212039d72d22352a0f0cc8cd782883592dc352c4a8adc9069b55e68a6ac83082
MD5 8979760e81469882d87c0575f147cc8f
BLAKE2b-256 32773b433e90c7b549527a8fb60a982f448d51649fb28ae3f83f5ff20a4d2fc7

See more details on using hashes here.

File details

Details for the file dotnest-1.1-py3-none-any.whl.

File metadata

  • Download URL: dotnest-1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.26.0

File hashes

Hashes for dotnest-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8296b828a6b44d276f5b9e6275844ee6db63259ddcbbb733093449607240c8f8
MD5 6dea89d0fb86ca5a33fbaa21f4ed0b94
BLAKE2b-256 06b25a8448d5d311df945b1c7ad4224394ac983148e0fad46d055448a4cd82e1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page