wield.bunch


Namewield.bunch JSON
Version 0.9.9 PyPI version JSON
download
home_pagehttps://github.com/wieldphysics/wield-bunch
Summarybunch container objects like Matlab structs
upload_time2023-04-14 23:54:41
maintainer
docs_urlNone
authorLee McCuller
requires_python
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            wield.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.

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

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

or 

```python
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

```python
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 

```python
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 wield.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.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/wieldphysics/wield-bunch",
    "name": "wield.bunch",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Lee McCuller",
    "author_email": "mcculler@caltech.edu",
    "download_url": "https://files.pythonhosted.org/packages/52/b7/c2f9fb205eb5008184d564b4f7654a87dbb366f76d2b0dd6e4ffd139a680/wield.bunch-0.9.9.tar.gz",
    "platform": null,
    "description": "wield.bunch\n=================\n\nUtility classes providing \"Bunch\" containers. These are dictionaries with\nattribute access of the elements. They wrap any lower level dictionaries they\noutput, so the interface mimics the \"struct\" container from Matlab.\n\nBunch\n------\n\nThe Bunch class is a lightweight wrapper for dictionaries to allow attribute\naccess as a means to access elements with less syntax. Bunch does not copy\nassigned dictionaries, it wraps them. This is unlike some other implementations\nsuch as gwinc.Struct.\n\n```python\nd = dict(A=1, B=2, d2=dict(C=1))\n\nb1 = Bunch(d)\nprint(b1.A)\nprint(b1.d2.C)\n```\n\nor \n\n```python\nb2 = dict(A=1, B=2, d2=dict(C=1))\nprint(b2.A)\nprint(b2.d2.C)\n```\n\nA useful pattern while developing and debugging code, particularly while refactoring large\nblocks of code into functions is\n\n```python\ndef code_block(arg1, arg2, arg3, ...):\n    ...\n    a = 1\n    b = 2\n    ...\n    return Bunch(locals())\n    \nret = code_block(...)\nret.a\n```\n\nwhich is a lightweight way to access elements from the code_block that is\npromoted into a function.\n\nDeepBunch\n-----------\nThere are a collection of more advanced containers\nDeepBunch allows speculative access of elements, such that if it is missing\nan attribute, a temporary is created such that \n\n```python\nA = DeepBunch()\nA.B.C.D = 1\n```\n\nis acceptable.\n\nand \n\n```\nif A.B.C.E:\n  raise Exception('The above test evaluates to False')\n```\n\nand in this case, no intermediate dictionaries are actually created until a value is assigned to a leaf.\n\n\nHDFDeepBunch\n---------------\n\nh5py is not a required dependency of wield.bunch, but if it is installed\nthen one can import the `HDFDeepBunch`, which provides a similar interface to\nthe DeepBunch, but uses HDF5 files as a back-end, with internal handling of\nnumpy arrays.\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "bunch container objects like Matlab structs",
    "version": "0.9.9",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a67588f405d339fb6c8e3123a099ec5e67300a97eaea521b706cfb29d45f52d0",
                "md5": "8c182845ccb3e850b9ada4aa722829b3",
                "sha256": "fa8b350ea8cf4ee4aadfa29ad196b73cae5ae9a18a25f1d960c60554577e2828"
            },
            "downloads": -1,
            "filename": "wield.bunch-0.9.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8c182845ccb3e850b9ada4aa722829b3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 28528,
            "upload_time": "2023-04-14T23:54:39",
            "upload_time_iso_8601": "2023-04-14T23:54:39.248687Z",
            "url": "https://files.pythonhosted.org/packages/a6/75/88f405d339fb6c8e3123a099ec5e67300a97eaea521b706cfb29d45f52d0/wield.bunch-0.9.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "52b7c2f9fb205eb5008184d564b4f7654a87dbb366f76d2b0dd6e4ffd139a680",
                "md5": "8bc7644e84c81ce738b8096a6ccdaa84",
                "sha256": "855fc2883c0eb14aebefe14c4374e52fdf419870499561cf5c37ad139a58778c"
            },
            "downloads": -1,
            "filename": "wield.bunch-0.9.9.tar.gz",
            "has_sig": false,
            "md5_digest": "8bc7644e84c81ce738b8096a6ccdaa84",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 23069,
            "upload_time": "2023-04-14T23:54:41",
            "upload_time_iso_8601": "2023-04-14T23:54:41.344851Z",
            "url": "https://files.pythonhosted.org/packages/52/b7/c2f9fb205eb5008184d564b4f7654a87dbb366f76d2b0dd6e4ffd139a680/wield.bunch-0.9.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-14 23:54:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "wieldphysics",
    "github_project": "wield-bunch",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "wield.bunch"
}
        
Elapsed time: 0.05234s