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

Uploaded Source

Built Distributions

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

Uploaded Python 3

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

Uploaded CPython 3.10 Windows x86-64

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

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.8 Windows x86-64

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

Uploaded CPython 3.7m Windows x86-64

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

File metadata

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

File hashes

Hashes for python-box-6.0.0rc4.tar.gz
Algorithm Hash digest
SHA256 8188344b8179d9e2785d980670a2fe8cb19e5014b7bd6234c90bacbdfbc6b290
MD5 b4fe8f7a80df45cbfff506f53c71cbdf
BLAKE2b-256 510c570d4e2883f6520141eabbb1bb4cee03f19213a1e00c7a3f30922abcc5d6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for python_box-6.0.0rc4-py3-none-any.whl
Algorithm Hash digest
SHA256 338a59cc7d19f4e81a8295cf403371d36a7e23c2ba6530de4c7d5bf37474e249
MD5 384232fde239a40aa5f29023ae4f0d0d
BLAKE2b-256 7c75a8139b26d7a1df7bb63df4cd3c623863b82ea36044086b47010620193b67

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 936.5 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/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1

File hashes

Hashes for python_box-6.0.0rc4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c9e263ab9333d01a25d4ea7d7564ed37d2dba9b197fcd81f91ca08ca8f43c4d1
MD5 63a1c9321a6ace1105e549e984279c74
BLAKE2b-256 4bf96b790e13a88b2621176dc9dbce4b32e7d59944dfb6fa3a3a3084eaf95f1d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc4-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/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for python_box-6.0.0rc4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 30e443f327e7fb6a9737010b26460aca165d92877dec4bb929a8e013c2855364
MD5 e8d9ba0f278794308cf29182a162f825
BLAKE2b-256 50bfe11b0e8a54d0b191c3d0d5ed60020eddcd9d27298922b76dca21403f6e98

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc4-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/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for python_box-6.0.0rc4-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 35d9ad462a328973311570c46b9d78c2d44b3bc49f1b11d0fa0ad258a85f272f
MD5 270d999611b4353e01156a8013583427
BLAKE2b-256 4321541a7015f7ff526a37637dc276919ad95cf1f70977b7df48229a60062172

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc4-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 936.3 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/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9

File hashes

Hashes for python_box-6.0.0rc4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 bafd2b9c73cc938e101fa460d26bfe027d3a776efac2ed546f26db16ca80d762
MD5 69cd835bafd9700920c39e768742cb20
BLAKE2b-256 846832005bd407436b11b497de9cc698f79405bcd0ad7b58bca63024aa008eb7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc4-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/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for python_box-6.0.0rc4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f545fbe3901b7b52c47aad74540f8380ca67ca19e3714bb10533ee38efa8e8d4
MD5 a14ebf2123bfa587d8f15da6a28b9e5f
BLAKE2b-256 d5c61ebee93bebc256ef8f4b26dd46505e3f39aa3c27de87b8ead7322fada65f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc4-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/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for python_box-6.0.0rc4-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 de25b5ae10ec6e6d046c64bec2f7165c6be8a44229b92839ce06c7aa87177242
MD5 18666561f8f92dd173a3507525d4231e
BLAKE2b-256 4ebf52dd56f6210ffa99902adfd0837a4e7ff6f6580c5c3c1aed2f63697f0c5d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc4-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 938.6 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/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for python_box-6.0.0rc4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 b187a1f0a0da9b270ef287631f5b9d93da88e109a8b861978760446260cf5cd0
MD5 8791b970556657e2be77d1a0080f01e1
BLAKE2b-256 ed548d904adcee1319fdb4e13dd51ecb8c0757d958cd03fcaf84301392c615cb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc4-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/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for python_box-6.0.0rc4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5bb64830ddf627b15999caf841cbbde089eda3562a9af8fbf68c7dcebca8e009
MD5 e6983299b38c494ad9a061647ca10063
BLAKE2b-256 7011a4bb0d5eb3a5dcf18b4651089b57c3e0b3c96fb8d36b8c8e4ca2c06b22fa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc4-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/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for python_box-6.0.0rc4-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 2db71a4cd3c2de99ec9409ec198b57b7eb168d5eeae4a097a3a46c09292a81ff
MD5 f37bc21cd42b4eb1917c2207bb10a571
BLAKE2b-256 3f45ae5791cb0092cbf07403089cbebee4d97f50f1e0eee37a1b368b94cc28bb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc4-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 921.2 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/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.9

File hashes

Hashes for python_box-6.0.0rc4-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ad0f978cece0b34fcd4a2c57449ac51c14383869ac48b804291cdaa40bb0c737
MD5 15c19a016112f2a0d7dd857ecf19258d
BLAKE2b-256 a49fca823a2794505bb018274cef83465a2e6d8ddf74b22ab675ff4d3612bf59

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc4-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/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for python_box-6.0.0rc4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cd2de2d39a99749e3b20ac697cb2e36cf5445e9e35260a30864577e30862cddc
MD5 a129dfeed912114a4be12ad3c04381e1
BLAKE2b-256 d904572049fc75657cf38993c2df87189fbafdd8e97ad7542a3e7531379807e8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.0rc4-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/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

File hashes

Hashes for python_box-6.0.0rc4-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 d4b2f5b63a16d76c0763e3b3cf334b37420c917cf6c5d20a932829a64e6c1816
MD5 a6cd8a43b2f5e6b529ac4a146715a7da
BLAKE2b-256 f274554c4d322612220ece0f57fd58b157954a2300d177d44bb737c2f68958fd

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