python-bunch 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
bunch/__init__.py ADDED
File without changes
bunch/bunch.py ADDED
@@ -0,0 +1,44 @@
1
+ import json
2
+ from typing import Any
3
+
4
+
5
+ class Bunch:
6
+ def __init__(self, *args, **kwargs):
7
+ for arg in args:
8
+ if not isinstance(arg, dict):
9
+ kwargs[arg] = None
10
+ self.__dict__.update(kwargs)
11
+
12
+ def __getitem__(self, key):
13
+ return self.__dict__[key]
14
+
15
+ def __setitem__(self, key, value):
16
+ self.__dict__[key] = value
17
+
18
+ def __contains__(self, key):
19
+ return key in self.__dict__
20
+
21
+ def __str__(self):
22
+ return json.dumps(self.__dict__, indent=4, sort_keys=False)
23
+
24
+ def __repr__(self):
25
+ return self.__str__()
26
+
27
+ def __delitem__(self, key):
28
+ del self.__dict__[key]
29
+
30
+ def contains_value(self, value):
31
+ return value in self.__dict__.values()
32
+
33
+ def keys(self):
34
+ return self.__dict__.keys()
35
+
36
+ def values(self):
37
+ return self.__dict__.values()
38
+
39
+ def items(self):
40
+ return self.__dict__.items()
41
+
42
+ @staticmethod
43
+ def from_dict(dictionary: dict) -> Any:
44
+ return Bunch(**dictionary)
@@ -0,0 +1,41 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-bunch
3
+ Version: 0.1.0
4
+ Summary: A lightweight Python class that behaves like a dict but supports attribute-style access.
5
+ Author-email: Your Name <your.email@example.com>
6
+ License: MIT
7
+ Keywords: python-bunch,bunch,dict,attribute-access,json,utility
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.7
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: license-file
15
+
16
+ ## Bunch
17
+
18
+ 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.
19
+
20
+ ### <ins> Features </ins>
21
+
22
+ - Access keys as attributes or like a dictionary
23
+ - Convert from regular dictionaries
24
+ - Pretty-printed JSON representation
25
+ - Check if a value exists
26
+ - Fully compatible with `in`, `.keys()`, `.items()`, etc.
27
+
28
+ ### <ins> Installation </ins>
29
+
30
+ You can install this package via PIP: _pip install bunch_
31
+
32
+ ### <ins> Usage </ins>
33
+
34
+ ```python
35
+ from bunch import Bunch
36
+
37
+ my_bunch = Bunch({'name': 'Jane', 'age': 30})
38
+
39
+ print(my_bunch.name) # Output: Jane
40
+ print(my_bunch['age']) # Output: 30
41
+ ```
@@ -0,0 +1,7 @@
1
+ bunch/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ bunch/bunch.py,sha256=OwDbw6bmpO4VU5taMl6gaqL6WRijMGMG18sQ5CmK7H4,1013
3
+ python_bunch-0.1.0.dist-info/licenses/LICENSE,sha256=Hsoz6W43KBiNLAODKAcjo2witGQKjZ05gVU_mUD4eHs,1039
4
+ python_bunch-0.1.0.dist-info/METADATA,sha256=4yNAae668lzJVoffU57_vCCwpKSpWjS9DfYRx3_aBNU,1312
5
+ python_bunch-0.1.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
6
+ python_bunch-0.1.0.dist-info/top_level.txt,sha256=A1w3sDjR8t1mZ4GDuhD9afxgybqy6nHJHPA4CbrgFRA,6
7
+ python_bunch-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (78.1.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,18 @@
1
+ This applies only to the contents of this package and does not affect the licensing of any projects that depend on it.
2
+
3
+ This is free and unencumbered software released into the public domain.
4
+
5
+ Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
6
+ software, either in source code form or as a compiled binary, for any purpose,
7
+ commercial or non-commercial, and by any means.
8
+
9
+ In jurisdictions that recognize copyright laws, the author has dedicated any
10
+ copyright interest in the software to the public domain. This software is
11
+ provided "as is", without warranty of any kind, express or implied, including
12
+ but not limited to the warranties of merchantability, fitness for a particular
13
+ purpose and noninfringement. In no event shall the authors be liable for any
14
+ claim, damages or other liability, whether in an action of contract, tort or
15
+ otherwise, arising from, out of or in connection with the software or the use
16
+ or other dealings in the software.
17
+
18
+ For more information, please refer to <https://unlicense.org>
@@ -0,0 +1 @@
1
+ bunch