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.3.1.tar.gz (17.0 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.3.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ncw-0.3.1.tar.gz
Algorithm Hash digest
SHA256 bc6e17159442b0397971665a87865a3492456d90c462cef1e706fce8e12db66f
MD5 dd77beb6e0fc4bdfa40a414ff91609e7
BLAKE2b-256 04f6d5965fd1073b74af19faa09fe7880703e7e14cbc3b07818c4f57b66da2ed

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ncw-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 348627088dc63d250fc0f7b6abf291a77084169c47085f20c9f4624dfc78188e
MD5 12fdbb03236f2bc79de07f28f02c1762
BLAKE2b-256 f42a1d9e3e8a6e3dcab4905c758fbf6ec7d72f5bb37d2e0736d66529e75f07f5

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