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.1.tar.gz (23.9 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.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ncw-0.4.1.tar.gz
Algorithm Hash digest
SHA256 2f34700c0289ee72a9bfb52ef7f6a3f7e1a2ebd6dbf7c62d8761dc3520c7c171
MD5 b6f95caf0f2eb867e9064bca9b1063cd
BLAKE2b-256 afabd15e5f33a04e841e03b7496237c35e7def3faf55aca3d67ec6d265c989a4

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ncw-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 475b77a2c185e1361b6616a5b4a12dc14c17ff4f083e763072c5f6b3d934bf92
MD5 bc53e56dbf5703640b2a9b553a7ed4da
BLAKE2b-256 f93abe214ea806eb5eb5f2916755a26b2d13c7ad056c0c4eac1272a6dc3bdbf3

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