Skip to main content

wavestate.bunch

Utility classes providing "Bunch" containers. These are dictionaries with attribute access of the elements. They wrap any lower level dictionaries they output, so the interface mimics the "struct" container from Matlab.

Bunch

The Bunch class is a lightweight wrapper for dictionaries to allow attribute access as a means to access elements with less syntax. Bunch does not copy assigned dictionaries, it wraps them. This is unlike some other implementations such as gwinc.Struct.

d = dict(A=1, B=2, d2=dict(C=1))

b1 = Bunch(d)
print(b1.A)
print(b1.d2.C)

or

b2 = dict(A=1, B=2, d2=dict(C=1))
print(b2.A)
print(b2.d2.C)

A useful pattern while developing and debugging code, particularly while refactoring large blocks of code into functions is

def code_block(arg1, arg2, arg3, ...):
    ...
    a = 1
    b = 2
    ...
    return Bunch(locals())
    
ret = code_block(...)
ret.a

which is a lightweight way to access elements from the code_block that is promoted into a function.

DeepBunch

There are a collection of more advanced containers DeepBunch allows speculative access of elements, such that if it is missing an attribute, a temporary is created such that

A = DeepBunch()
A.B.C.D = 1

is acceptable.

and

if A.B.C.E:
  raise Exception('The above test evaluates to False')

and in this case, no intermediate dictionaries are actually created until a value is assigned to a leaf.

HDFDeepBunch

h5py is not a required dependency of wavestate.bunch, but if it is installed then one can import the HDFDeepBunch, which provides a similar interface to the DeepBunch, but uses HDF5 files as a back-end, with internal handling of numpy arrays.

Release files for wavestate.bunch 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wavestate.bunch 0.9.1
File Size Uploaded
wavestate.bunch-0.9.1.tar.gz 24.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wavestate.bunch 0.9.1
File Interpreter ABI Platform
wavestate.bunch-0.9.1-py3-none-any.whl Python 3 none any Details

Total release size: 46.0 kB

Release files / wavestate.bunch-0.9.1.tar.gz

Download URL wavestate.bunch-0.9.1.tar.gz
Size 24.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ba25b7b342ff55dfc011feedca320e96920d84b0f75b38f2a9af43f4506aed03
BLAKE2b-256 checksum
How to use checksums
1fb833b813337fd609c4e245fa923b28789155a72f76cd80bc015caf8535b2a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/0.0.0 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.12

Release files / wavestate.bunch-0.9.1-py3-none-any.whl

Download URL wavestate.bunch-0.9.1-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
35a23b709e915db6a16eeccc563fa04cde16ace595955c0ee72b72259397a8ac
BLAKE2b-256 checksum
How to use checksums
6290ed35e454c74be020ee26125e8922086ba2826d978d0a9fb6d31339e15d26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/0.0.0 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.12

Release history Release notifications | RSS feed

This release

0.9.1 This release

2 release files

0.9.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page