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

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 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] --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.0rc3.tar.gz (38.2 kB view details)

Uploaded Source

Built Distributions

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

Uploaded Python 3

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

Uploaded CPython 3.10 Windows x86-64

python_box-6.0.0rc3-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.0rc3-cp39-cp39-win_amd64.whl (936.2 kB view details)

Uploaded CPython 3.9 Windows x86-64

python_box-6.0.0rc3-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.0rc3-cp38-cp38-win_amd64.whl (938.5 kB view details)

Uploaded CPython 3.8 Windows x86-64

python_box-6.0.0rc3-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.0rc3-cp37-cp37m-win_amd64.whl (921.1 kB view details)

Uploaded CPython 3.7m Windows x86-64

python_box-6.0.0rc3-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.0rc3.tar.gz.

File metadata

  • Download URL: python-box-6.0.0rc3.tar.gz
  • Upload date:
  • Size: 38.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for python-box-6.0.0rc3.tar.gz
Algorithm Hash digest
SHA256 3a7edb6ab04461488567def1c37420c74ce9998bcc84a92ad83385e256463913
MD5 a52882d1fc777eb0f1b808d0e65766fe
BLAKE2b-256 3d03547c98860c372cf5ac1a3b14d1f37152eb197c9a3f79b289a46d9002004a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc3-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for python_box-6.0.0rc3-py3-none-any.whl
Algorithm Hash digest
SHA256 b0ed110ed7826b96310c02fd320d46f6af298e453b3e16f5b6652dfc03c9cb56
MD5 1d0304fab4a77761ed067817fec6b4cc
BLAKE2b-256 492a8e78c54e922cd441a9af330c9d6b9dde913d21a6dd38c65aff1f6813c43f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 936.4 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for python_box-6.0.0rc3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3822b10d1e45e68c5d439fffb60f1f48b3bc544f6778595c217c4a928af25659
MD5 ead09332b096799e9017ef89938bf287
BLAKE2b-256 26d3ba322d178cd5583da19d6beff66c2d4f31b75392d5f0e4f40b8623bd1e42

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc3-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.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2

File hashes

Hashes for python_box-6.0.0rc3-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 b0447388941516af6a097e0a2f2e6fbac5c628ec8215a2f438306f0c1833755a
MD5 bc617c692375c20887ff75c843f47261
BLAKE2b-256 4b0446d8ecaae094291df997f61783685b804d9940defdca7fda792d0f51088d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 936.2 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for python_box-6.0.0rc3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 2e154eec68be78e76fdd04160897c4fe288baf47238061ece8c7c6ed4796f89a
MD5 387f08df81774a42a2d90b40896c3583
BLAKE2b-256 bc28dc176c902172576124acd51c7df3a390cf84aec50dcda165df40deb284ee

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc3-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.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for python_box-6.0.0rc3-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 db25e65f644e863be93c704959ccf3faf58477ff196123a41cd43d1feacd57b1
MD5 7d7dbd5d2a25ba927106afdb8cb1e80f
BLAKE2b-256 13b14615606e0ce0cecfa826bef70327236e8ee914223238a5720cd6abfe8a6e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc3-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 938.5 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for python_box-6.0.0rc3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a8df6665fc032bd5270edb555331df3b4c4a4232987949134c736102a31b02c8
MD5 4278eb9b78b33d015c06d54ab041247f
BLAKE2b-256 51959d0f1ea8388d9d66069ed08973de8c1389dd46aa837314325de2cb2674c7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc3-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.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for python_box-6.0.0rc3-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 be6bf4e9c8b4b8f30f37a4f5a5d25727cd8881845423cc73da012ab7c62b09c9
MD5 ced9226cb9482585fddc92e20a2e416a
BLAKE2b-256 1d5870cfc08ebf529e7b8b70badfae5f8dd85b0fe8582244b7e9ec9791c583ed

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc3-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 921.1 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9

File hashes

Hashes for python_box-6.0.0rc3-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 6778758fdc5d3ff28b08f9cae3d80e238e70b1aa647ae54490ee7473b5ff1ac1
MD5 133b6243eb6952afadac81905d9b4fcd
BLAKE2b-256 6af29733fe9d759f0715c765262058cf517f5ee40ba5aa875f6115cc134b979d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc3-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.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for python_box-6.0.0rc3-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 054c9df59d0367eb5f098e15d33d263f085763a5ed6a722143ebb95492140e8c
MD5 996a854fac633a649b91f7129e858c54
BLAKE2b-256 e045d14afb768bf708d453b307718f43eb469b63571456a6bcd18159c57bfe15

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