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

Uploaded Source

Built Distributions

python_box-7.2.0-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

python_box-7.2.0-cp312-cp312-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.12 Windows x86-64

python_box-7.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

python_box-7.2.0-cp312-cp312-macosx_10_9_universal2.whl (1.8 MB view details)

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

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

Uploaded CPython 3.11 Windows x86-64

python_box-7.2.0-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.2.0-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.2.0-cp310-cp310-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.10 Windows x86-64

python_box-7.2.0-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.2.0-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.2.0-cp39-cp39-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.9 Windows x86-64

python_box-7.2.0-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.2.0-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.2.0-cp38-cp38-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.8 Windows x86-64

python_box-7.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

python_box-7.2.0-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.2.0.tar.gz.

File metadata

  • Download URL: python_box-7.2.0.tar.gz
  • Upload date:
  • Size: 45.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for python_box-7.2.0.tar.gz
Algorithm Hash digest
SHA256 551af20bdab3a60a2a21e3435120453c4ca32f7393787c3a5036e1d9fc6a0ede
MD5 a0175e2c3f4a1351fad60b46ce5a4808
BLAKE2b-256 d2e48de6f91bb2a3c07eab631a2d8fc100fa759529b8576ea01c1c5d83ef886c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-7.2.0-py3-none-any.whl
  • Upload date:
  • Size: 29.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for python_box-7.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3c90832dd772cb0197fdb5bc06123b6e1b846899a1b53d9c39450d27a584829
MD5 62f59c1dead1b93577377603dfdc5049
BLAKE2b-256 46461a162759b3b753c29c59979495586fddb125ff70597fca582691e17f11ab

See more details on using hashes here.

File details

Details for the file python_box-7.2.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for python_box-7.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 739f827056ea148cbea3122d4617c994e829b420b1331183d968b175304e3a4f
MD5 f07ee6addf618075e870efe0d748d824
BLAKE2b-256 910df5548978dd4cfc26c562a266bd2d077427eaf3577d8b88c4c3deac793332

See more details on using hashes here.

File details

Details for the file python_box-7.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e8a5a7365db1aaf600d3e8a2747fcf6833beb5d45439a54318548f02e302e3ec
MD5 1017eadeb2d139805eebdcd268f954f1
BLAKE2b-256 af06953f932c34fe117f0c1b016332055c64c7ed5b284851d402ea570d7dbea4

See more details on using hashes here.

File details

Details for the file python_box-7.2.0-cp312-cp312-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for python_box-7.2.0-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 2a2d664c6a27f7515469b6f1e461935a2038ee130b7d194b4b4db4e85d363618
MD5 11bd5de52df95da0e1c8e9cfe3ad22e7
BLAKE2b-256 dc1339a808760ce42eba8435577dd74abd15e43dc0149d14d96769febc99f172

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 32ed58ec4d9e5475efe69f9c7d773dfea90a6a01979e776da93fd2b0a5d04429
MD5 f473796514fae7b841ad2ceab019909c
BLAKE2b-256 b4a7a9cd90c90d6d9b361fa4a9c27d9ea55c61dee70e6a7681d757f218035e61

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e8a6c35ea356a386077935958a5debcd5b229b9a1b3b26287a52dfe1a7e65d99
MD5 8bc5ec6d76ebd870d9bf4a4c0d231cc5
BLAKE2b-256 045f1ed110a22b5ff5e430fbbd1655afff6f833f1af83333a8815f22f47fc0ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.2.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 e2d752de8c1204255bf7b0c814c59ef48293c187a7e9fdcd2fefa28024b72032
MD5 eac33390a2f9a5cdabd65c2b4338c7ac
BLAKE2b-256 f93566313d7f1b3370c184eafa9f61ba982968e339ba0bda696bf564fbc74b70

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6b0d61f182d394106d963232854e495b51edc178faa5316a797be1178212d7e0
MD5 629fc78244a797f8754daa270eef1774
BLAKE2b-256 bc693b9392f0707d0ae1dde1fe6003883421195f98d103f2083e87e9c014aeb7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c449f7b3756a71479fa9c61a86e344ac00ed782a66d7662590f0afa294249d18
MD5 8de1815801f70f4522b58ee0238f7974
BLAKE2b-256 353038a4165441a212f160076bafab81413d5192ba8507cb2c506dff7e194275

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.2.0-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 6bdeec791e25258351388b3029a3ec5da302bb9ed3be175493c43cdc6c47f5e3
MD5 18c3b3675c71cbb4975e96f15cc57fba
BLAKE2b-256 e6e4b74c722abb6c040ef5de6c2787cc788e414a946ebb1972e7240c55294f53

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.2.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 573b1abdcb7bd745fa404444f060ee62fc35a74f067181e55dcb43cfe92f2827
MD5 298032b8e7d3c5eab2d2c68376e7c5e5
BLAKE2b-256 d1abe5587298db92c08dd42895804161e7de64337923793e23932d29cd4a87e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e23fae825d809ae7520fdeac88bb52be55a3b63992120a00e381783669edf589
MD5 721e110137d6b6e05a35b81de7029ec4
BLAKE2b-256 7612fb2b7adcc9080f3e049390c5791ffce295eacbd1734c8f37de334c6cef5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.2.0-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 6b59b1e2741c9ceecdf5a5bd9b90502c24650e609cd824d434fed3b6f302b7bb
MD5 14dd06b132028b6d22d04c60f8f6a9e8
BLAKE2b-256 97391f0fc998a5bd1f23d855b8d7231580625e8970dcea37a4f55d94e9d292bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.2.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9681f059e7e92bdf20782cd9ea6e533d4711fc7b8c57a462922a025d46add4d0
MD5 6781ae96acb8dea0d311ebe26f5857ea
BLAKE2b-256 627c118a42a7c40e3b011b6b3c862fa11626d00ab732e70fe5aa0f5794dae5f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ffd866bed03087b1d8340014da8c3aaae19135767580641df1b4ae6fff6ac0aa
MD5 3f4c6da26be2bde24812379332732229
BLAKE2b-256 a5588b6b8ca51172a65d9b79cd843a738d46e757936e2eb4eca9f149ab2fe870

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.2.0-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 2617ef3c3d199f55f63c908f540a4dc14ced9b18533a879e6171c94a6a436f23
MD5 cfc53f83384efb739fd3f7fd490ecb5a
BLAKE2b-256 3ae50f2f8106a2496d598755620138811f034904b8c0a746cfdec1a8b1c80572

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