Skip to main content

Nested collections wrapper

Project description

ncw

Nested collections wrapper

Classes to access and/or modify data in nested collections (dict or list instances) of str, int, float, bool, or None.

Usage

Use the Structure class to access (deep) copies of substructures by either a string comprised of the segments of the keys or indexes in the "path" addressing the substructure or value in the nested collection, joined together by a separator character (usually an ASCII dot: .), or a tuple of these path segments.

>>> serialized = '{"herbs": {"common": ["basil", "oregano", "parsley", "thyme"], "disputed": ["anise", "coriander"]}}'
>>>
>>> import json
>>> original_data = json.loads(serialized)
>>>
>>> from ncw import Structure
>>>
>>> readonly = Structure(original_data)
>>> readonly["herbs"]
{'common': ['basil', 'oregano', 'parsley', 'thyme'], 'disputed': ['anise', 'coriander']}
>>> readonly["herbs.common"]
['basil', 'oregano', 'parsley', 'thyme']
>>> readonly["herbs", "common"]
['basil', 'oregano', 'parsley', 'thyme']
>>> readonly["herbs", "common", 1]
'oregano'
>>> readonly["herbs.common.1"]
'oregano'

The MutableStructure class allows changes to the underlying data structure, see the documentation for more details.


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

ncw-0.4.2.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ncw-0.4.2-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file ncw-0.4.2.tar.gz.

File metadata

  • Download URL: ncw-0.4.2.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.0

File hashes

Hashes for ncw-0.4.2.tar.gz
Algorithm Hash digest
SHA256 b80fb5e1ea070926a6451a109a43cfa5cfc8b8811af5626442775fca7b1d1e2c
MD5 79435512018b2c9c82fb17e23430238e
BLAKE2b-256 0c71b5ac2c9f0c2d14928dbd85f0a91c58d753b9f0c2e195cf1488062ab2ec36

See more details on using hashes here.

File details

Details for the file ncw-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: ncw-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.0

File hashes

Hashes for ncw-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9d8725c970ac3af950a210e190b012d5ae2ad7df3ded13683af143d4ef221c3e
MD5 c12848d789038435fec75ccb4f48c0e8
BLAKE2b-256 54a97c7087c90a31e52472165243991390e8acc605e0bfffbb3bf3f1808c8f22

See more details on using hashes here.

Supported by

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