Skip to main content

A lightweight Python class that behaves like a dict but supports attribute-style access.

Project description

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

# - Immutable Bunch -v
from bunch.immutable_bunch import ImmutableBunch

my_immutable_bunch = ImmutableBunch({'name': 'John', 'age': 25})
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

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

python_bunch-0.1.6.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

python_bunch-0.1.6-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file python_bunch-0.1.6.tar.gz.

File metadata

  • Download URL: python_bunch-0.1.6.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for python_bunch-0.1.6.tar.gz
Algorithm Hash digest
SHA256 97d5b0be4fb4053aeebca9b24c2bb9c3bbfd9e61ee254c35d2d6f0249fcb55c1
MD5 06b7d4ccb543557d0ddee75401cab4f0
BLAKE2b-256 c287370657bb293805f9e4ad6a5dda5e013d6173e2ce73413a607f1820ff0390

See more details on using hashes here.

File details

Details for the file python_bunch-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: python_bunch-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for python_bunch-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2447ce9d839dd5b23d10d68fd7749f5a1cfd2b382cd3e02b1d0068ef47a19daf
MD5 a49843715034928144dd2cceb97a1f3e
BLAKE2b-256 5680d343401e831765ea4ea476855d25584300db46fc5b0e37511641238099fd

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