Skip to main content

Bunch is a dictionary that supports attribute-style access, a la JavaScript.

>>> b = Bunch()
>>> b.hello = 'world'
>>> b.hello
'world'
>>> b['hello'] += "!"
>>> b.hello
'world!'
>>> b.foo = Bunch(lol=True)
>>> b.foo.lol
True
>>> b.foo is b['foo']
True

Dictionary Methods

A Bunch is a subclass of dict; it supports all the methods a dict does:

>>> b.keys()
['foo', 'hello']

Including update():

>>> b.update({ 'ponies': 'are pretty!' }, hello=42)
>>> print repr(b)
Bunch(foo=Bunch(lol=True), hello=42, ponies='are pretty!')

As well as iteration:

>>> [ (k,b[k]) for k in b ]
[('ponies', 'are pretty!'), ('foo', Bunch(lol=True)), ('hello', 42)]

And “splats”:

>>> "The {knights} who say {ni}!".format(**Bunch(knights='lolcats', ni='can haz'))
'The lolcats who say can haz!'

Miscellaneous

  • Bunch converts easily to (unbunchify, Bunch.toDict) and from (bunchify, Bunch.fromDict) a normal dict, making it easy to cleanly serialize them to JSON or YAML.

  • It is safe to import * from this module. You’ll get: Bunch, bunchify, and unbunchify.

  • Tests:

    $ python -m bunch.test -v

Feedback

Open a ticket at http://github.com/dsc/bunch or send me an email at dsc@less.ly .

Metadata

Release files for bunch 1.0.0

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

Source distributions (sdists)

Source distribution for bunch 1.0.0
File Size Uploaded Provenance Actions
bunch-1.0.0.zip 8.3 kB Without provenance Details for bunch-1.0.0.zip
bunch-1.0.0.tar.gz 5.2 kB Without provenance Details for bunch-1.0.0.tar.gz

Release files / bunch-1.0.0.zip

Download URL bunch-1.0.0.zip
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
64b0ae772518584256df8a6a583739787c683173c8e0a2b0e71d2e87245dbdfb
BLAKE2b-256 checksum
How to use checksums
d416789b94d9ea7e79538dfb155934d7cf6f12c9349f567ff6be6119238a8ca7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / bunch-1.0.0.tar.gz

Download URL bunch-1.0.0.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c3c0ee685431ae2a624e28107a2cf50ee84edfbd97297b1af207b938248eb54a
BLAKE2b-256 checksum
How to use checksums
d959139794ac055e37f90b6543143acb600b0da7c5859704daec35e0c7f59320
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for bunch 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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