Skip to main content

Bunch

A simple Python class that allows dictionary-style and attribute-style access to data interchangeably. Think of it as a lightweight object wrapper for dictionaries — great for config objects, JSON responses, or anything else you'd normally throw in a dict.

Features

  • Access keys as attributes or like a dictionary
  • Convert from regular dictionaries
  • Pretty-printed JSON representation
  • Check if a value exists
  • Fully compatible with in, .keys(), .items(), etc.

Installation

You can install this package via PIP: pip install python-bunch

Usage

# - Mutable Bunch -
from bunch.bunch import Bunch

my_bunch = Bunch(name='Jane', age=30)

print(my_bunch.name)  # Output: Jane
print(my_bunch['age'])  # Output: 30

# From Dictionary
my_dict = {'name': 'Bob', 'age': 25}
my_bunch_from_dict = Bunch.from_dict(my_dict)
print(my_bunch_from_dict)  # Output: {'name': 'Bob', 'age': 25}

# - Immutable Bunch -
from bunch.immutable_bunch import ImmutableBunch

my_immutable_bunch = ImmutableBunch(name='John', age=35)
print(my_immutable_bunch.name)  # Output: John
print(my_immutable_bunch['age'])  # Output: 35

# Attempting to modify an ImmutableBunch will raise an Exception
my_immutable_bunch.name = 'Alice'  # Raises ImmutableBunchException

# From Dictionary
my_dict = {'name': 'Alice', 'age': 40}
my_bunch_from_dict = Bunch.from_dict(my_dict, recursive=True)
print(my_bunch_from_dict)  # Output: {'name': 'Alice', 'age': 40}

Metadata

Release files for python-bunch 0.1.9

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

Source distribution (sdist)

Source distribution for python-bunch 0.1.9
File Size Uploaded
python_bunch-0.1.9.tar.gz 4.9 kB Details

Built distribution (wheel)

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

Total release size: 9.6 kB

Release files / python_bunch-0.1.9.tar.gz

Download URL python_bunch-0.1.9.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
21876e0fb1f9111dff5a2b9148305080d378e657ab4c88fccea31bb08977d3be
BLAKE2b-256 checksum
How to use checksums
ba137a2affc88e34ef1a62bce6d9227344baf36f57ea82aa84f7fff1ca6b540e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.6

Release files / python_bunch-0.1.9-py3-none-any.whl

Download URL python_bunch-0.1.9-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e5ce9dba29b68727039d5063d31393973eba865e15d1ddc75aafa0ce04c2818
BLAKE2b-256 checksum
How to use checksums
ef5cf1d66614f7040394125331fcd44e79f33c61a9b803afa952ac18f70b42ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.6

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

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