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.2.1.tar.gz (2.1 MB view details)

Uploaded Source

Built Distribution

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

ncw-0.2.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ncw-0.2.1.tar.gz
  • Upload date:
  • Size: 2.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.8

File hashes

Hashes for ncw-0.2.1.tar.gz
Algorithm Hash digest
SHA256 35614828fb6f065ad9bda161e03ed30650a7661a481c280152c8e919eb44e759
MD5 8267b56778cb845fdd6e2142749c9757
BLAKE2b-256 aad9b13bc697c54f7dc0827bbd97dcba35026bf686bba7da03345c182abcbc6b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ncw-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d6809bdcfc3aeadf2673242148e444d6e746e4c3f8526a32dff8219471f87e1e
MD5 c876b03945266a78f89d5fa5feac4b2b
BLAKE2b-256 c7c62b61127c95bd71dd771530e77aa5abd400bc68dbb0967ef71581d352d47f

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