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.0.1.tar.gz (43.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

python_box-7.0.1-py3-none-any.whl (28.6 kB view details)

Uploaded Python 3

python_box-7.0.1-cp311-cp311-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.11Windows x86-64

python_box-7.0.1-cp311-cp311-macosx_10_9_universal2.whl (1.7 MB view details)

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

python_box-7.0.1-cp310-cp310-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.10Windows x86-64

python_box-7.0.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

python_box-7.0.1-cp310-cp310-macosx_11_0_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

python_box-7.0.1-cp39-cp39-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.9Windows x86-64

python_box-7.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

python_box-7.0.1-cp39-cp39-macosx_11_0_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

python_box-7.0.1-cp38-cp38-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.8Windows x86-64

python_box-7.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

python_box-7.0.1-cp38-cp38-macosx_10_15_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.8macOS 10.15+ x86-64

python_box-7.0.1-cp37-cp37m-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.7mWindows x86-64

python_box-7.0.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

python_box-7.0.1-cp37-cp37m-macosx_10_15_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.7mmacOS 10.15+ x86-64

File details

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

File metadata

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

File hashes

Hashes for python-box-7.0.1.tar.gz
Algorithm Hash digest
SHA256 dc6724f88255ccbc07092abd506281439cc2b75c6569c754ffc2b22580e7ae06
MD5 3a31dfac5d4df784323ac039c6481ce5
BLAKE2b-256 11b43db81c812236f252f833dcfd470a559a26d0a86a0371be70b84f4f283440

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for python_box-7.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f26f210b2257fd973413e75e8b91aaff9c95d7d61266426a7d3df473c4adcfd4
MD5 7a416fa82c2e21c68c48e3b78783af3e
BLAKE2b-256 355b3fbd992289ee2466c72ec47449f111e9f7e34682e8b7318c92a9cde50b7f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-7.0.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for python_box-7.0.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 33d61b81133d1ddf6d85d0658c4c9aca871208c28df74e660dbdfe68f9b470ce
MD5 cea081f97a87054a2a5846417fae98a5
BLAKE2b-256 420bcffb0f069e836a06a1d4d0b213d86bd547eaca145e946c3fd101bd3d1722

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.0.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 86182565c9ebe9ee4a3aece1a55d9d5451c6a44b5ec127a5e4d315909efe6d10
MD5 60973aef8655a7d0f64ad6067e93453f
BLAKE2b-256 763175a63a86597430403b5d14da12e70b753db54934a783156d8436f35c709b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-7.0.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for python_box-7.0.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f394cca98c777b25836faf25cb5afdc88c01dc753a5aab80055a038229091b7b
MD5 67f6de648b3c4f2fb02e70a020370de3
BLAKE2b-256 cef972a67302a5e849df632e85b94df79841c66e81a9ff7f3f8509982c015f04

See more details on using hashes here.

File details

Details for the file python_box-7.0.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.0.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 cccb85f9cbf64eda51c773f3db68aa60291ec1356b0774c37bcd4e13f26b90e7
MD5 24ad7277b377769dd23c2c27b9553333
BLAKE2b-256 e91cdf839763448ca15ea23a7918aa22321a942a0b251eb481ddc0bc59dd8176

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.0.1-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 92093bf5b1500004e3608b3f39e54230b21301ffb00ff5f4dbf775f2a409a7a9
MD5 710b62d8f5a682776d5cfc9f7478f30c
BLAKE2b-256 e143c372d0cf4d69367990bc50602810b1d786acd24912a076ef751bc7930c7d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-7.0.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for python_box-7.0.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f9254a1c7ec5e729e256f9a223773aa8a76d7a995f4d6be0015f74ab93a0f97c
MD5 b05c398964b4de802f3b1fe92e122329
BLAKE2b-256 40585a926301b8b3d3196f6940469586db4940a3e0114e745a0a7249562e8a64

See more details on using hashes here.

File details

Details for the file python_box-7.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 4e35521b9b96cf6a18ecfef7ebcf73fe326956a7b5d789c4ff0a01dc43edd6ce
MD5 dbef49544092bf1df9d0eba1f27dce22
BLAKE2b-256 176cfa8d96eb89d05a59f14a2537fc5115ac9351b1b8b4fdfc2b2b6727f012cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.0.1-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 84867f6527bbd1d17bc7534e1c64ccd1d173d973ae5eb202f04bdf8c0ca3a690
MD5 4b830dbabcca502376894f4411f1d819
BLAKE2b-256 6cd13f0500ec8ef36ccde68774ff419d762120e5edba898790b2ebc99de9c221

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-7.0.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for python_box-7.0.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 fbb14fac0ff0b2b42e47041b7b8b4f1f8d6f6ac086c8e68b7f0358602905653e
MD5 020f026d0960e948b73f86a1a71e3bbf
BLAKE2b-256 a9018a53ecc73c78ef0704ebc122f99165dd05f75f739a287b51f5ed3b6aa229

See more details on using hashes here.

File details

Details for the file python_box-7.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 6b8265e842eee33dd5d1b129b8da900ec0b6f80db70680b633f9086807f42fb9
MD5 84c716dc5c30ac9d9a7f0606f5d04432
BLAKE2b-256 4689734aab7d7114c607235547cdfb5ca7c89fc781da11184aa4004fa468ba18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.0.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 443ff7320c1b7e64384189f532c386600a6c31db9ddd9ded8ecc3ad4c43d0edb
MD5 922f0e74532031eff03e0ae0045e1363
BLAKE2b-256 dddae57f1fecce41155042d2f43efc01f112ecb6d60d3fc536a275e94cd809bd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-7.0.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.9

File hashes

Hashes for python_box-7.0.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 dc135cf06ef3dde501de9baab21d908088fb03e2de09e3fe80e8a4f1dcd1ab2b
MD5 934528746252257617aff5e7962b1b10
BLAKE2b-256 82231932f422ec8d46d5d8e1278f87850cfc06ddc0673ef8263d8bb532c1e8b9

See more details on using hashes here.

File details

Details for the file python_box-7.0.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.0.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 6a6d71c3c2ebed3f4c888edfa96bc5768f5e7641c4b0b6017d70f68a325811cf
MD5 6405636625849b962d538fbe25038b67
BLAKE2b-256 b5ca18af58ee413820ff3a44847348908f6139d9f63a29e447a0bf60b352ebb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.0.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 042d10f33e56a3b3432a94a23c90672a7f32f6de7116cdd9bc59d852ca08f5f7
MD5 5752d01002882ee139aef0ce1c8ee030
BLAKE2b-256 cd485a949021a7e59ad3f51449a5cd2088ff7c6ffcc02769d7805df42aeae885

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page