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 a near transparent drop in replacements for dictionaries that add dot notation access and other powerful feature.

There are a lot of types of boxes to customize it for your needs, as well as handy converters!

Keep in mind any sub dictionaries or ones set after initiation will be automatically converted to a Box object, and lists will be converted to BoxList, all other objects stay intact.

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 insertion 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.1.tar.gz (39.0 kB view details)

Uploaded Source

Built Distributions

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

Uploaded Python 3

python_box-6.0.1-cp310-cp310-win_amd64.whl (938.4 kB view details)

Uploaded CPython 3.10 Windows x86-64

python_box-6.0.1-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.1-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.1-cp39-cp39-win_amd64.whl (938.2 kB view details)

Uploaded CPython 3.9 Windows x86-64

python_box-6.0.1-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.1-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.1-cp38-cp38-win_amd64.whl (940.5 kB view details)

Uploaded CPython 3.8 Windows x86-64

python_box-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

python_box-6.0.1-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.1-cp37-cp37m-win_amd64.whl (924.4 kB view details)

Uploaded CPython 3.7m Windows x86-64

python_box-6.0.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: python-box-6.0.1.tar.gz
  • Upload date:
  • Size: 39.0 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.9 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.1.tar.gz
Algorithm Hash digest
SHA256 3f394c69e1c484eb18a1a1d6e969428ec9cc70b5f47b921da798c2e41b15d1f7
MD5 7b19dc28375619ff83ec162788e3f3fa
BLAKE2b-256 26fb5ab3045def9e454dc0b5e9bf696980ff7eb363f8de1cbf46014cfb33423a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.1-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.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2966c58b7c47770a06ce4bed240556ac2f3f76f68c2ecb6db46123676a8cc8a0
MD5 aca4cc5b775a0d01772c52639d095ae7
BLAKE2b-256 ac8e13b97048887a049169955818fa8efe2a19533f43590f3a817e7832a4ee89

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 938.4 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.9 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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 15419a9b1883f3360f8ad8dd767e8ce20f2006e156012126d208c00fcc7fc6db
MD5 a491476d1f8d254d149a30fac25d5e1a
BLAKE2b-256 e9e1e0dd4619f55f8b97634e2525dba6a0cb685eb643aca9da92ee5ea931bd65

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.1-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.9 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.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bcd881fedb11f55ce1ec59889e2dc3da98b3cd54126f12c4a3b2e0cb3e1dc1e5
MD5 e23bd59664eb0f34e7304c8776a02149
BLAKE2b-256 258f5b2b1fa9a4a78fa47b48bfa975131bffaffcc4f3062429201efe2f395d56

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.1-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.9 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.1-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 214bb6c1305ec937a8f30f01fe76eeff6307bb783c1ee38979ae433514eed9cf
MD5 7b9196c630fe1fccd4686aa493a7f67c
BLAKE2b-256 8c03a6792623e9450a576066f16b86e977eafc1cdb778bef4328b21513bc0c5e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 938.2 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.9 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.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 0e37f753bf7031bf25fcf22107a4faa64230dcb81de602f79d9bf5b599f9ef5c
MD5 d1cb6981c498118c22e04d9fc3b513aa
BLAKE2b-256 14b788c66aff4b07ab229564f482cb8ae333ef623fa9ec254de94cf8b767189e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.1-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.9 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.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 234e47576882ddc7df17d7fdbdacaa0e831738fb6619499ec84905f3504c6cdf
MD5 6e1652eaab020ad467050a4cd9a4fb3f
BLAKE2b-256 a3d5241975b17156ec7deb72a10172192e88e031610f09c75392c61062bf7286

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.1-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.9 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.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 4f4a7aa7d57ec7b4182d35e275e9d2ee097e3541030e7bcdd15713404713017d
MD5 0f348f0fcae736a44d5bf8458499883c
BLAKE2b-256 5ffbb88344b13e2b6902c9b11ef4475ee0f7593ecc7e2d47758725df4d0eb384

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 940.5 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.9 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.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a4be4ea156fa9167fef5218ecaa53270ee60aa933fc7e3cc0864675a39b3ae5d
MD5 64e5175632e6f45110a7521ac086240a
BLAKE2b-256 969497bcb2b78af139ae98d6eb2113225be77ea06ee449bcf4cd9ab7ef90c298

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 3.4 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.9 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.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5ed78335f808162798370949026494da4aeb1530d630a2d98801e107a3a791d3
MD5 44ef3be5fef5e603dbfd8a7da155e636
BLAKE2b-256 432f932b306217afb3d019b0a46e7e4c598f68df2d191c62bfe50f534ad5ac15

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.1-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.9 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.1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 681f0d05a5db3385ae1b949035a57dd4462aa58f1f7a21df2eb29227f265e002
MD5 36044dc2caf0e8aa3022ae47fd244a4d
BLAKE2b-256 7fb88bfabd1ac8976428f2229e8056256b20d7f70a813a373fc83ddfd17b84fb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 924.4 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.9 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.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 802d79fdec6bafc0936ca2a59a3478e9ae95f786e68cc23dcd98a4ad44933c00
MD5 2fef1891424c8833bd995a1c1eaab052
BLAKE2b-256 a61afec777092a41309f1cd5d081124ad0b7739c001be22510a4251b4d40aead

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.1-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.9 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.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3f26c67d1ca48b96097d73b42b66187e0b11e954f61234784f3619a969a8b2bb
MD5 0fc3daabe0ec193df79a2779f13fe6e9
BLAKE2b-256 5e1542ed30241c2f45a84b2aef45d51f680c79f1af6961e6c320a1caec71e66d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.1-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.9 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.1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 6793311354ba11c9bdc4a1d40752bcc23a5ba8687c8929dba150e11af592de5e
MD5 0da3e09af8e4addd1bf8253ac41d4504
BLAKE2b-256 07cd5d5b86cbd1ad467b4fce54913bf054f089f1668d3e197120c81b843adb20

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