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.7+, 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.1.0.tar.gz (41.4 kB view details)

Uploaded Source

Built Distributions

python_box-6.1.0-py3-none-any.whl (27.3 kB view details)

Uploaded Python 3

python_box-6.1.0-cp311-cp311-win_amd64.whl (957.4 kB view details)

Uploaded CPython 3.11 Windows x86-64

python_box-6.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

python_box-6.1.0-cp311-cp311-macosx_10_9_universal2.whl (1.6 MB view details)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

python_box-6.1.0-cp310-cp310-win_amd64.whl (962.3 kB view details)

Uploaded CPython 3.10 Windows x86-64

python_box-6.1.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.1.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.1.0-cp39-cp39-win_amd64.whl (972.8 kB view details)

Uploaded CPython 3.9 Windows x86-64

python_box-6.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

python_box-6.1.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.1.0-cp38-cp38-win_amd64.whl (975.2 kB view details)

Uploaded CPython 3.8 Windows x86-64

python_box-6.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

python_box-6.1.0-cp38-cp38-macosx_10_15_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

python_box-6.1.0-cp37-cp37m-win_amd64.whl (958.2 kB view details)

Uploaded CPython 3.7m Windows x86-64

python_box-6.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

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

python_box-6.1.0-cp37-cp37m-macosx_10_15_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.7m macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: python-box-6.1.0.tar.gz
  • Upload date:
  • Size: 41.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for python-box-6.1.0.tar.gz
Algorithm Hash digest
SHA256 6e7c243b356cb36e2c0f0e5ed7850969fede6aa812a7f501de7768996c7744d7
MD5 82af8e6a315f8191910977d23342f0b0
BLAKE2b-256 9a85b02b80d74bdb95bfe491d49ad1627e9833c73d331edbe6eed0bdfe170361

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.1.0-py3-none-any.whl
  • Upload date:
  • Size: 27.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for python_box-6.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bdec0a5f5a17b01fc538d292602a077aa8c641fb121e1900dff0591791af80e8
MD5 365b435b81c041e293cf1dc01d59693a
BLAKE2b-256 88c66d1e368710cb6c458ed692d179d7e101ebce80a3e640b2e74cc7ae886d6f

See more details on using hashes here.

File details

Details for the file python_box-6.1.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for python_box-6.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 af6bcee7e1abe9251e9a41ca9ab677e1f679f6059321cfbae7e78a3831e0b736
MD5 6fdbd6e7cf024a373aa82d0b69a43eb6
BLAKE2b-256 f37d5cc1f3145792b803ee6debc82d1faf791659baa15c2de7b1d9318adbcd68

See more details on using hashes here.

File details

Details for the file python_box-6.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_box-6.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3f0036f91e13958d2b37d2bc74c1197aa36ffd66755342eb64910f63d8a2990f
MD5 58d81a5536e09d92656474d19d596827
BLAKE2b-256 8bb4ae3736cfc3970fe6ee348620780811c016fe4c01d2d0ff4a3a19f4eff5f7

See more details on using hashes here.

File details

Details for the file python_box-6.1.0-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for python_box-6.1.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 ac44b3b85714a4575cc273b5dbd39ef739f938ef6c522d6757704a29e7797d16
MD5 d95e9978ab97b0d188f636e85a5ac5fd
BLAKE2b-256 d41648bcaacf750fa2cc78882a53eef953c28a42e4a84f5e0b27e05d7188a92a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-6.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d199cd289b4f4d053770eadd70217c76214aac30b92a23adfb9627fd8558d300
MD5 d3319f48bdc1d3caf900098a0bf0779b
BLAKE2b-256 6997e43a8ab4487f923356a0ab8b0e540448aa453a8ec9314d49dd2098952185

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-6.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ab13208b053525ef154a36a4a52873b98a12b18b946edd4c939a4d5080e9a218
MD5 f984529da6dffa291892534128ca8909
BLAKE2b-256 6f323c865e7d62e481c46abffef3303db0d27bf2ca72e4f497d05d66939bfd4a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-6.1.0-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 c14aa4e72bf30f4d573e62ff8030a86548603a100c3fb534561dbedf4a83f454
MD5 d9150825fbcc2c6e207c3cc955073ca4
BLAKE2b-256 a9c75d18ef4960a67b8d8dad9a6aa6c739da15a92b6f1e550ab7ebe040493957

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.1.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 972.8 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for python_box-6.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 7b73f26e40a7adc57b9e39f5687d026dfa8a336f48aefaf852a223b4e37392ad
MD5 299974be1211f1b109b05e81985544cb
BLAKE2b-256 d17261f1ebd3702fdec61aaba12fd01b8d2c0cf22d7da12ffa2bc54579f8a220

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-6.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ed6d7fe47d756dc2d9dea448702cea103716580a2efee7c859954929295fe28e
MD5 a889ceb7bbd327aee427993999db34ff
BLAKE2b-256 cc4b8e5a4c4812f489b61bac4062ce069db92d309fc523b82aaf23da3a139024

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-6.1.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 9dbd92b67c443a97326273c9239fce04d3b6958be815d293f96ab65bc4a9dae7
MD5 4505eb9b03152b580427c4869e5759e0
BLAKE2b-256 28e6f30023871200936bb39c8308540388999e241bdb455ed7f967d57c637cf3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.1.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 975.2 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for python_box-6.1.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 1d29eafaa287857751e27fbe9a08dd856480f0037fe988b221eba4dac33e5852
MD5 bab04a836f230cfe9dc5fa4c99f8bf15
BLAKE2b-256 a7a59720ae5c1e10dd73710d1069399368a4311a894f2ae342823405c8eb6864

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-6.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 594b0363b187df855ff8649488b1301dddbbeea769629b7caeb584efe779b841
MD5 ec1bbbfb7a2182200bf47d15ede98868
BLAKE2b-256 e196e15d9db05dc8ac244e5947cfd9c789ee989b7383ea8a61221a58802c6cde

See more details on using hashes here.

File details

Details for the file python_box-6.1.0-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for python_box-6.1.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 53998c3b95e31d1f31e46279ef1d27ac30b137746927260901ee61457f8468a0
MD5 794a389d1002a0d5966771e6423575a6
BLAKE2b-256 748f28f21756eedf381c6b6d04251d5b05f4429461da4e59e8388c9e105d4d72

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-6.1.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 3638d3559f19ece7fa29f6a6550bc64696cd3b65e3d4154df07a3d06982252ff
MD5 e6f8f9ff5cb5f4720ac4d1e2a78597b5
BLAKE2b-256 fa920460063689d9a10e5125876ea03dd5924e4596b009ef12359b764bba5700

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-6.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fa4696b5e09ccf695bf05c16bb5ca1fcc95a141a71a31eb262eee8e2ac07189a
MD5 4aa61e0ef2f7fc877722120d20d9fe5d
BLAKE2b-256 a4ec4721471ea768601105d8ba8524e61a45701dd017c6cac00eab3e78536af8

See more details on using hashes here.

File details

Details for the file python_box-6.1.0-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for python_box-6.1.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 11cbe62f0dace8a6e2a10d210a5e87b99ad1a1286865568862516794c923a988
MD5 d8d2ab88dea51d2665b846e8a40bdffc
BLAKE2b-256 9e2857741ebe5748ea5646318146c82e2ae49bfd6941f3354984cd127918bb80

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