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

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

Uploaded Source

Built Distributions

python_box-7.0.0rc1-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

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

Uploaded CPython 3.11 Windows x86-64

python_box-7.0.0rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.10 Windows x86-64

python_box-7.0.0rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.9 Windows x86-64

python_box-7.0.0rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.8 Windows x86-64

python_box-7.0.0rc1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.7m Windows x86-64

python_box-7.0.0rc1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

File details

Details for the file python-box-7.0.0rc1.tar.gz.

File metadata

  • Download URL: python-box-7.0.0rc1.tar.gz
  • Upload date:
  • Size: 43.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for python-box-7.0.0rc1.tar.gz
Algorithm Hash digest
SHA256 a224e6c810fbe92b758abe5634fc22c2556d3997b610dfb7682174b6ac1d4faf
MD5 a329af27fa13fd4c209e219dc7b620fe
BLAKE2b-256 34f7e926613b76ffedbe39545f5197a6da2efaebd5083e56e83abf40e60199a0

See more details on using hashes here.

File details

Details for the file python_box-7.0.0rc1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_box-7.0.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 f49d74b249984f25b92ab3aabb30e0c3a87e284afcfd05678ea20a6045740d6b
MD5 f7465f69f769d113cdca9171b2818203
BLAKE2b-256 7d91d8bb02b438b1e71d6090678d52107126a0d6a08296b930b4b6157bfae762

See more details on using hashes here.

File details

Details for the file python_box-7.0.0rc1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for python_box-7.0.0rc1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e133823f750335cf0f5819dd876d59897465d74af1a0b75503bb601480e3f88c
MD5 3189c9de254a5130596b1d789b21558c
BLAKE2b-256 39c3c935c9cff27e44264872a4c8f653ec8f5a2311f7e81acd33f28ee5283a39

See more details on using hashes here.

File details

Details for the file python_box-7.0.0rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.0.0rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4f2ba7ae8cc78f28784ccec91c9bbdbe1a3e84da9f3d77755cc6267a60bebc57
MD5 0cb5d281b98590ebbf464278c1bdf19f
BLAKE2b-256 672d98e3a0aac30ed2693d39b49db1472411de4b6315130d05bee5eb2b188131

See more details on using hashes here.

File details

Details for the file python_box-7.0.0rc1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for python_box-7.0.0rc1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 af9fb32d2621fe729fee2be341699d92be7d75ead2554c4c0a46cf0d55a9c42f
MD5 96f0ace1c0f5b3aa00fdad60c9468fcc
BLAKE2b-256 fd880b1fbb3e8a941fbc515a965775b6c2a550016126eb27e27c7794187a98cb

See more details on using hashes here.

File details

Details for the file python_box-7.0.0rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.0.0rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 08893539c5514bfbb3d3dad2ba1928239f9140cbed093744f3d43240e1e7af21
MD5 9954d420469e19341123e92f7855dbe2
BLAKE2b-256 979ba44a1180593c3f7f0e24501a5d479aeff34c09665c0cf24da20e1525847a

See more details on using hashes here.

File details

Details for the file python_box-7.0.0rc1-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for python_box-7.0.0rc1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 753fb9f868cc0b4c86c86c754d939bbbd0937f34f3314c4587dda5b0369b6911
MD5 31bb73423df3b8cb35b0cc81f88e7698
BLAKE2b-256 c21d58b7446a0d37dd791bd75ca903edc1ac84b7a82757f703ee2730f13c0cc0

See more details on using hashes here.

File details

Details for the file python_box-7.0.0rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.0.0rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5323e800615a3515a6f4e2f6de2594145f2faa66b36fed856fc02f1b0bc56195
MD5 2316ec3725498fd1ccd613252b18d108
BLAKE2b-256 8d1efcaedb391f3d632de19fa307aad58889ccaa199e5acfff2d64c41462bf14

See more details on using hashes here.

File details

Details for the file python_box-7.0.0rc1-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for python_box-7.0.0rc1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 5a28aa7afe5b2f68902ded673ea6504ac01826424f39304a3f5f511eb5d4f5e7
MD5 0f3ac4eccc6dbd50d72b1ca9e7ddb922
BLAKE2b-256 ff9c1bed6b251a079a609e8daff0eef2d8737c807ceb68735fca66919d2556c1

See more details on using hashes here.

File details

Details for the file python_box-7.0.0rc1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.0.0rc1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 375063a15c2676021b2fc694d03819724e4490bac98cdcabd51ad6540d45913b
MD5 6c2b14ab1f2117ce95db5f9eb3d93939
BLAKE2b-256 12ef56b85dde33f3d0ed6ae5d808d703b88af5993ce00633f5833ad9db63f7b2

See more details on using hashes here.

File details

Details for the file python_box-7.0.0rc1-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for python_box-7.0.0rc1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 d4a6fc5437d5743df989c4e833ba4fd156dbd72c1a84078eab34366ac6f25f14
MD5 f948ff786f88c70a4f841afc87243cfb
BLAKE2b-256 dbe47d9ab40777beec8626d32a2f123bc2b48da9e43c2730d7e839499a78f573

See more details on using hashes here.

File details

Details for the file python_box-7.0.0rc1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.0.0rc1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a4b7f09b70be110bc7153f439bff35e688b5cf08d36e04cf16a22853462808d2
MD5 d41731896f113a57aa58d82e977a74fd
BLAKE2b-256 35ab8a4f2442502a4829d8a6aaafe9c20a82b14be33d2b4451ff33b5f867f8e8

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