https://github.com/cdgriffith/Box Skip to content Sign up * Why GitHub? + Features + Mobile + Actions + Codespaces + Packages + Security + Code review + Issues + Integrations + GitHub Sponsors + Customer stories * Team * Enterprise * Explore + Explore GitHub + Learn and contribute + Topics + Collections + Trending + Learning Lab + Open source guides + Connect with others + The ReadME Project + Events + Community forum + GitHub Education + GitHub Stars program * Marketplace * Pricing + Plans + Compare plans + Contact Sales + Education [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} cdgriffith / Box Public * Notifications * Fork 80 * Star 1.8k * Python dictionaries with advanced dot notation access github.com/cdgriffith/box/wiki MIT License 1.8k stars 80 forks Star Notifications * Code * Issues 21 * Pull requests 0 * Actions * Projects 0 * Wiki * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Wiki * Security * Insights master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 11 branches 43 tags Code Latest commit @cdgriffith @ipspace cdgriffith and ipspace Version 5.4.1 (#206) ... 4f9b3a6 Aug 22, 2021 Version 5.4.1 (#206) * Fixing setdefault behavior with box_dots (thanks to Ivan Pepelnjak) Co-authored-by: Ivan Pepelnjak 4f9b3a6 Git stats * 43 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github/workflows Version 5.4.0 (#204) Aug 15, 2021 box Version 5.4.1 (#206) Aug 22, 2021 docs Version 5.0.0 (#145) Jul 12, 2020 test Version 5.4.1 (#206) Aug 22, 2021 .black.toml Version 5.0.0 (#145) Jul 12, 2020 .coveragerc Version 5.0.0 (#145) Jul 12, 2020 .gitignore Version 4.1.0 (#132) Feb 22, 2020 .pre-commit-config.yaml Version 5.4.0 (#204) Aug 15, 2021 AUTHORS.rst Version 5.4.1 (#206) Aug 22, 2021 CHANGES.rst Version 5.4.1 (#206) Aug 22, 2021 CONTRIBUTING.rst Version 3.0.1 (#27) May 7, 2017 LICENSE Version 4.1.0 (#132) Feb 22, 2020 MANIFEST.in Version 5.4.0 (#204) Aug 15, 2021 README.rst Version 5.4.0 (#204) Aug 15, 2021 box_logo.png Version 2.0 (#2) Mar 16, 2017 requirements-dev.txt Version 5.4.0 (#204) Aug 15, 2021 requirements-test.txt Version 5.4.0 (#204) Aug 15, 2021 requirements.txt Version 5.4.0 (#204) Aug 15, 2021 setup.py Version 5.4.0 (#204) Aug 15, 2021 View code Install Overview Thanks License README.rst BuildStatus License BoxImage from box import Box movie_box = Box({ "Robin Hood: Men in Tights": { "imdb stars": 6.7, "length": 104 } }) movie_box.Robin_Hood_Men_in_Tights.imdb_stars # 6.7 Box will automatically make otherwise inaccessible keys safe to access as an attribute. You can always pass conversion_box=False to Box to disable that behavior. Also, all new dict and lists added to a Box or BoxList object are converted automatically. There are over a half dozen ways to customize your Box and make it work for you. Check out the new Box github wiki for more details and examples! Install pip install --upgrade python-box[all] Box 5 is no longer forcing install of external dependencies such as yaml and toml. Instead you can specify which you want, for example, all is shorthand for: pip install --upgrade python-box[ruamel.yaml,toml,msgpack] But you can also sub out "ruamel.yaml" for "PyYAML". Check out more details on installation details. Box 5 is tested on python 3.6+ and pypy3, if you are upgrading from previous versions, please look through any breaking changes and new features. If you have any issues please open a github issue with the error you are experiencing! Overview Box is designed to be an easy drop in transparently replacements for dictionaries, thanks to Python's duck typing capabilities, which adds dot notation access. Any sub dictionaries or ones set after initiation will be automatically converted to a Box object. You can always run .to_dict() on it to return the object and all sub objects back into a regular dictionary. Check out the Quick Start for more in depth details. Box can be instantiated the same ways as dict. Box({'data': 2, 'count': 5}) Box(data=2, count=5) Box({'data': 2, 'count': 1}, count=5) Box([('data', 2), ('count', 5)]) # All will create # Box is a subclass of dict which overrides some base functionality to make sure everything stored in the dict can be accessed as an attribute or key value. small_box = Box({'data': 2, 'count': 5}) small_box.data == small_box['data'] == getattr(small_box, 'data') All dicts (and lists) added to a Box will be converted on lookup to a Box (or BoxList), allowing for recursive dot notation access. Box also includes helper functions to transform it back into a dict, as well as into JSON, YAML, TOML, or msgpack strings or files. Thanks A huge thank you to everyone that has given features and feedback over the years to Box! Check out everyone that has contributed. A big thanks to Python Software Foundation, and PSF-Trademarks Committee, for official approval to use the Python logo on the Box logo! Also special shout-out to PythonBytes, who featured Box on their podcast. License MIT License, Copyright (c) 2017-2020 Chris Griffith. See LICENSE file. About Python dictionaries with advanced dot notation access github.com/cdgriffith/box/wiki Topics python bunch helper dictionaries object python-library pypi box python3 addict python-types python-box Resources Readme License MIT License Stars 1.8k stars Watchers 33 watching Forks 80 forks Releases 41 Version 5.4.1 Latest Aug 22, 2021 + 40 releases Contributors 9 * @cdgriffith * @fabaff * @vamega * @rochacbruno * @pwwang * @JacobHayes * @ipspace * @Yobmod * @NoamGraetz2 Languages * Python 100.0% * (c) 2021 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.