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]~=7.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

python -m pip install --upgrade pip
pip install python-box[all]~=7.0 --upgrade

Install with selected dependencies

Box does not install external dependencies such as yaml and toml writers. Instead you can specify which you want, for example, [all] is shorthand for:

pip install python-box[ruamel.yaml,tomli_w,msgpack]~=7.0 --upgrade

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

Check out more details on installation details.

Box 7 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 has introduced 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]~=7.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-2023 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-7.1.1.tar.gz (44.7 kB view details)

Uploaded Source

Built Distributions

python_box-7.1.1-py3-none-any.whl (29.0 kB view details)

Uploaded Python 3

python_box-7.1.1-cp311-cp311-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.11 Windows x86-64

python_box-7.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

python_box-7.1.1-cp311-cp311-macosx_10_9_universal2.whl (1.8 MB view details)

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

python_box-7.1.1-cp310-cp310-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.10 Windows x86-64

python_box-7.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

python_box-7.1.1-cp310-cp310-macosx_11_0_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10 macOS 11.0+ x86-64

python_box-7.1.1-cp39-cp39-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.9 Windows x86-64

python_box-7.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

python_box-7.1.1-cp39-cp39-macosx_11_0_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9 macOS 11.0+ x86-64

python_box-7.1.1-cp38-cp38-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.8 Windows x86-64

python_box-7.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

python_box-7.1.1-cp38-cp38-macosx_11_0_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.8 macOS 11.0+ x86-64

File details

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

File metadata

  • Download URL: python-box-7.1.1.tar.gz
  • Upload date:
  • Size: 44.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for python-box-7.1.1.tar.gz
Algorithm Hash digest
SHA256 2a3df244a5a79ac8f8447b5d11b5be0f2747d7b141cb2866060081ae9b53cc50
MD5 756ef327607a2a07e5c9b8b690a0f5c7
BLAKE2b-256 690db463241f95bc0dc47dee176508fb0c1cf2d5ca100832ccf10b75401bfed4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-7.1.1-py3-none-any.whl
  • Upload date:
  • Size: 29.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for python_box-7.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 63b609555554d7a9d4b6e725f8e78ef1717c67e7d386200e03422ad612338df8
MD5 19967543f1823499087ca7b139446418
BLAKE2b-256 4779f3eae9a2e2a2bac63583bf335a1e13b037f4b2e9ceaf6f2c0942df0db705

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f9266795e9c233874fb5b34fa994054b4fb0371881678e6ec45aec17fc95feac
MD5 8d3c59dea3490a14d1e9b5d32b80fdc4
BLAKE2b-256 a80c5c4a9aa6216265059fa3b2551274bb0cf21089cab5057c3f43be994ff75c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c046608337e723ae4de3206db5d1e1202ed166da2dfdc70c1f9361e72ace5633
MD5 e4fa4b39a2c1aba331d316f7cbd7ef34
BLAKE2b-256 aa92c961a096d2d445c5c6a9c689a9a019c2735ff7c3fd22d7fddaf80bd7479e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.1.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 aabf8b9ae5dbc8ba431d8cbe0d4cfe737a25d52d68b0f5f2ff34915c21a2c1db
MD5 28b6317532bbceee603a73e165f5f335
BLAKE2b-256 8e4771b1cd3c04ba147781f68debcbb40a9aee4cb66700e523ee921655d69c26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.1.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0036fd47d388deaca8ebd65aea905f88ee6ef91d1d8ce34898b66f1824afbe80
MD5 ca3b3db623ac371e3cf7afe0541735d4
BLAKE2b-256 9aeb469234d6696310416a999399ec8e94b4904789cb15e0e01dd08a9348d87a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8891735b4148e84d348c6eadd2f127152f751c9603e35d43a1f496183a291ac4
MD5 d295624b24de685a8f4c924a0d989a09
BLAKE2b-256 6563c2df733c7e9549c1acc6919a3157f8f2fe833fa013052b169e228e1aeb75

See more details on using hashes here.

File details

Details for the file python_box-7.1.1-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.1.1-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 81ed1ec0f0ff2370227fc07277c5baca46d190a4747631bad7eb6ab1630fb7d9
MD5 fcea8367fc740dd88f6941174dadfe99
BLAKE2b-256 3c6f14015c479d4888d79901d78db9862cdf2bc9e215329f45ac180998b7b28b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.1.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a0f1333c42e81529b6f68c192050df9d4505b803be7ac47f114036b98707f7cf
MD5 ce6591d941ded9fe545558441477b779
BLAKE2b-256 6bbded4960ef50f5e43ef04f9b068ee5b42cde56b2a97aeb2dbfd4ec68322d0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d95e5eec4fc8f3fc5c9cc7347fc2eb4f9187c853d34c90b1658d1eff96cd4eac
MD5 d1748ff9ff8a833b86eb6d06cba5f3c6
BLAKE2b-256 0b65f8d876ebce5515574342b76b1b061657533b9d4adb2d5ef4624e642e4f09

See more details on using hashes here.

File details

Details for the file python_box-7.1.1-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.1.1-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 24c4ec0ee0278f66321100aaa9c615413da27a14ff43d376a2a3b4665e1d9494
MD5 79d8fa082e8cbe3b4f5a6925dfa6e14a
BLAKE2b-256 8467855a5c5b235b15ef892d195582c9da252c9d42c8364d2dc8d720d126f6bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.1.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 1b3f346e332dba16df0b0543d319d9e7ce07d93e5ae152175302894352aa2d28
MD5 7ea5c0de84848374387aa6416a2f1352
BLAKE2b-256 b80e2aea4a9180e3cf58efe4119ce8c9f75ef97f2666bd1fe2b1b5cd8e36170c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4ea13c98e05a3ec0ff26f254986a17290b69b5ade209fad081fd628f8fcfaa08
MD5 72418792f5e81f655788d1cde68e319c
BLAKE2b-256 88cfc75636ecfc9185630d6359fbb802b6a137a6cc763e0af6597a96b54bd343

See more details on using hashes here.

File details

Details for the file python_box-7.1.1-cp38-cp38-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.1.1-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 f76b5b7f0cdc07bfdd4200dc24e6e33189bb2ae322137a2b7110fd41891a3157
MD5 1b7cb92ec458a7f9ab6daaa641eaf8d7
BLAKE2b-256 37f2dd135ca297aa7322e2451b3933046f8704bb03c0ecb28373d9d97abdde07

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