Skip to main content

Advanced Python dictionaries with dot notation access

Project description

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

Version Pin Your Box!

If you aren’t in the habit of version pinning your libraries, it will eventually bite you. Box has a list of breaking change between major versions you should always check out before updating.

requirements.txt

python-box[all]~=6.0

As Box adheres to semantic versioning (aka API changes will only occur on between major version), it is best to use Compatible release matching using the ~= clause.

Install from command line

pip install python-box[all]~=6.0 --upgrade

Install with selected dependencies

Box 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 python-box[ruamel.yaml,toml,msgpack]~=6.0 --upgrade

But you can also sub out ruamel.yaml for PyYAML.

Check out more details on installation details.

Box 6 is tested on python 3.6+, if you are upgrading from previous versions, please look through any breaking changes and new features.

Optimized Version

Box 6 is introducing Cython optimizations for major platforms by default. Loading large data sets can be up to 10x faster!

If you are not on a x86_64 supported system you will need to do some extra work to install the optimized version. There will be an warning of “WARNING: Cython not installed, could not optimize box” during install. You will need python development files, system compiler, and the python packages Cython and wheel.

Linux Example:

First make sure you have python development files installed (python3-dev or python3-devel in most repos). You will then need Cython and wheel installed and then install (or re-install with –force) python-box.

pip install Cython wheel
pip install python-box[all]~=6.0 --upgrade --force

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: {'data': 2, 'count': 5}>

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-2022 Chris Griffith. See LICENSE file.

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-box-6.0.0.tar.gz (38.8 kB view details)

Uploaded Source

Built Distributions

python_box-6.0.0-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

python_box-6.0.0-cp310-cp310-win_amd64.whl (936.6 kB view details)

Uploaded CPython 3.10 Windows x86-64

python_box-6.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

python_box-6.0.0-cp310-cp310-macosx_10_15_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

python_box-6.0.0-cp39-cp39-win_amd64.whl (936.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

python_box-6.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

python_box-6.0.0-cp39-cp39-macosx_10_15_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

python_box-6.0.0-cp38-cp38-win_amd64.whl (938.7 kB view details)

Uploaded CPython 3.8 Windows x86-64

python_box-6.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

python_box-6.0.0-cp38-cp38-macosx_10_14_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

python_box-6.0.0-cp37-cp37m-win_amd64.whl (922.7 kB view details)

Uploaded CPython 3.7m Windows x86-64

python_box-6.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

python_box-6.0.0-cp37-cp37m-macosx_10_14_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

File details

Details for the file python-box-6.0.0.tar.gz.

File metadata

  • Download URL: python-box-6.0.0.tar.gz
  • Upload date:
  • Size: 38.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for python-box-6.0.0.tar.gz
Algorithm Hash digest
SHA256 417a82e67eef760e2ae6278ee5124ff85183b20a8d0138343adadd002c32f253
MD5 be1b759f550df014a113568848645388
BLAKE2b-256 7fd7fe03663ecae5bbe6f0d43b7eec9d74608869cac937caa2a8654be3d8ac82

See more details on using hashes here.

File details

Details for the file python_box-6.0.0-py3-none-any.whl.

File metadata

  • Download URL: python_box-6.0.0-py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for python_box-6.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 070aae37f55301fcb5713ab9ae35850b80cb54db5ef484f92c05f409681e1930
MD5 d79bcbfdc584a980658708634f5160f6
BLAKE2b-256 7638870c4678ec2c5a13ced6a3edb8b58725ebb2a91733c104d13dadcb18063c

See more details on using hashes here.

File details

Details for the file python_box-6.0.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: python_box-6.0.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 936.6 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for python_box-6.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ef6e8b0c6c22dbca351a8f8b8b9794dbcef1387112e14ce3238868635588f3fb
MD5 edf7e35c67cc91aa8f5638190f1853e4
BLAKE2b-256 f5b0e1497de7ffb396fccb48389b45e5acd38006173ff3104b1cdde037700721

See more details on using hashes here.

File details

Details for the file python_box-6.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: python_box-6.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for python_box-6.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2b8545d41be526fc238bf926b68c7e4653643719cdaa75d0583010e73af128ae
MD5 8b0b56a6e8e1f32dc91ebe0b40e8466c
BLAKE2b-256 5a1d94530f79497888971dd7e0d7dcf6f5293e62f11055cf84fc50cba7c4de61

See more details on using hashes here.

File details

Details for the file python_box-6.0.0-cp310-cp310-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: python_box-6.0.0-cp310-cp310-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.10, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for python_box-6.0.0-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 642960121d9fd2d5f0c35860a0dcd67311982cba4f9c732f13d98c3fa9a4be7e
MD5 79c802ea9ead40666257a0c0abb6f166
BLAKE2b-256 68e3f565ce63ec0ee0e713b06c57a922cba7dd34a9f667ebe88004a532836347

See more details on using hashes here.

File details

Details for the file python_box-6.0.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: python_box-6.0.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 936.4 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for python_box-6.0.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 b1b205b20136d56f10aef122f8b2fee1e715cdeb139ffcd4f426ed304b8e3776
MD5 00f1eccc4eb70a4a6e30d39112acf1d0
BLAKE2b-256 bbcf305b009f2b14a752f2b131dd5a794b70747e091f2848c035e999bf800195

See more details on using hashes here.

File details

Details for the file python_box-6.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: python_box-6.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for python_box-6.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4a59e3cb19cce26c8254ccfa63b85bb9cf3f276c4431f9c5e1034274ecd7290e
MD5 33c9dbba617f544cf20dd20d22ff3315
BLAKE2b-256 bf45c6e39b907d4a06e0e5e8b240be3e3c265805cac4448a6ba17691d950d3f6

See more details on using hashes here.

File details

Details for the file python_box-6.0.0-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: python_box-6.0.0-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for python_box-6.0.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 41ab483d6f2aa8829d18a76123ab5743eb8938b8013062f27c4b1de59ae567b0
MD5 1f54954d91df37af01f3165c2a13aadd
BLAKE2b-256 832f243e95b93971609ce60980ef66d7b373f46e508e177a393eb4c79c788167

See more details on using hashes here.

File details

Details for the file python_box-6.0.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: python_box-6.0.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 938.7 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for python_box-6.0.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 f4761be775a8601aa4cea8531d0024f93198d0807d5ec74df48706523ad6344f
MD5 484182f3a337bd1e525864cb11499468
BLAKE2b-256 8f26fc52416968467b7c1af30918905ebfae75869f5a2a004856c4e6e127b3be

See more details on using hashes here.

File details

Details for the file python_box-6.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: python_box-6.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for python_box-6.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7e788d6d0dde6626bb0e74c3c14abd494b1c7af7f1796b0cd75f0bb0b09fc2c8
MD5 b5c7b80b21cce10dad6570fd690d2f61
BLAKE2b-256 9ed4f14b8f37e148b7ab7e1ae2179d461e0e447f6686ce3adf605705b4a5980c

See more details on using hashes here.

File details

Details for the file python_box-6.0.0-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: python_box-6.0.0-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for python_box-6.0.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 eaee31897c86eb2f69b3383dd984c54370e00b106a481aa38b2d00fb57d96a4e
MD5 77c6539cbefee4bc339fe888e698ecf3
BLAKE2b-256 c8a328a31d04e96edeb4aa3ac25cb9ea50aeca16c4051d9123d1f553a73020e7

See more details on using hashes here.

File details

Details for the file python_box-6.0.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: python_box-6.0.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 922.7 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.9

File hashes

Hashes for python_box-6.0.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 9269269583ccd50d3b89a15b798c9a2da84f3623412c6d3500b8fe3dc36a4c16
MD5 0bf0f2388da803dae1cf7d4f051e7656
BLAKE2b-256 32178e9427ac18586b7ae682c8f4217eb9b3a80ac082e66bc0551418ed1b4001

See more details on using hashes here.

File details

Details for the file python_box-6.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: python_box-6.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 2.9 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for python_box-6.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 204d51460be9cb0adf788833622a04c66bd21da530d2705643eacc115df4e43e
MD5 34228478a3fd60e916f0c0ea90a72ca8
BLAKE2b-256 f66c9744015f8ef29ce6772df35c67b0ef79cc0318385bb74b5af9b665690936

See more details on using hashes here.

File details

Details for the file python_box-6.0.0-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: python_box-6.0.0-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

File hashes

Hashes for python_box-6.0.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 1d796d418954c0a2fde5b56bf22cbe2e0e371506729a6fcb41fba6bdbafb545a
MD5 8a764453081ea77ab2300e0764193cc3
BLAKE2b-256 688ad89f658de029e40966e5417e32e2bb30262287ab95ea5984603c7388b918

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page