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

Uploaded Source

Built Distributions

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

Uploaded Python 3

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

Uploaded CPython 3.11 Windows x86-64

python_box-7.0.0rc0-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.0rc0-cp311-cp311-macosx_10_9_universal2.whl (1.7 MB view details)

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

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

Uploaded CPython 3.10 Windows x86-64

python_box-7.0.0rc0-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.0rc0-cp310-cp310-macosx_11_0_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10 macOS 11.0+ x86-64

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

Uploaded CPython 3.9 Windows x86-64

python_box-7.0.0rc0-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.0rc0-cp39-cp39-macosx_11_0_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9 macOS 11.0+ x86-64

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

Uploaded CPython 3.8 Windows x86-64

python_box-7.0.0rc0-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.0rc0-cp38-cp38-macosx_10_15_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

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

Uploaded CPython 3.7m Windows x86-64

python_box-7.0.0rc0-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

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

Uploaded CPython 3.7m macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: python-box-7.0.0rc0.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.0rc0.tar.gz
Algorithm Hash digest
SHA256 497df49c658669aa48daab06ee22a85125215c4c64e19f6926b41d5ad5807a39
MD5 ccad06f49b68726796c74694e4011259
BLAKE2b-256 0d7d23077d819aa686a54b9b1b9b85d86110fd2c99c759d79031656535464e10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.0.0rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 389b36c24a70616c2bf8d71b62fbf45af11eed4783e24f1612419071d9f53106
MD5 2dac6490baacaed85086ce97146b7f02
BLAKE2b-256 f0790a7523f36e4ea99f3633a48343849286b929d7f58f5b94ba3db36c39c855

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.0.0rc0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 372e599fe1011878a76820ac0d1e2323e3c591e1487acabc4dc2421d83d2f6a0
MD5 2c85744ecf59ec07b5930aa48b25d67c
BLAKE2b-256 7b8c1f97c2afb65102ca5c2a5b4c900b3c44bb2e6603c03a0652775cb9b69176

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.0.0rc0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d4daea78260403e20f7bbfef506d4168d59f2688201f345afc7375af21b33e79
MD5 b1ff801f0418a49b5c6a37eaa8280f93
BLAKE2b-256 1c392149fac21f9611b1c357d0d03ceb76fa8d3da0eaffc29db9db39362a363d

See more details on using hashes here.

File details

Details for the file python_box-7.0.0rc0-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for python_box-7.0.0rc0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 0c5c64c89d17c9417739ef9eae826bcce8d73b3dc64e40b43da3773c9dae4b0f
MD5 0bd62f4170288b53614f434da27c8018
BLAKE2b-256 e7bb6598ee9eacdf25b02716fa22db631de1bc0e3fc8f311d6ba46b6774ea4da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.0.0rc0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 484a656c293268bc1dd1a4edb168ae727f918bc927942d5447d8ad9d8cdf36c6
MD5 ce9109fc1a26611cee81ee5c3d96fd31
BLAKE2b-256 e317386615350ea38908748967cc7bbc8f5951e2bfd07f16b9b42dc54a00e634

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.0.0rc0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 438706b0a717d3375ee58e1124623bcdb52fdc37650a04fda08f9ee82f4bf921
MD5 5241228a3072d7d458f4ec929a670e07
BLAKE2b-256 2e88e4119f7c9634e840a5746080504444ce98e10094d786fb3e7d4d55ac43cf

See more details on using hashes here.

File details

Details for the file python_box-7.0.0rc0-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.0.0rc0-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 c02b1ffd567c86b5b98b70e76ec52c4bbcf44c31e277c0090957b1606cb9ce88
MD5 378088d9abb1d4ec72d645594ad820df
BLAKE2b-256 c08cd4ffdfce5de705d803cb8b35c2eb01792d3735aaf8941a48494205baa9d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.0.0rc0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 849da0119212fa4daf7e0866fe1988e08d12c3ec0bb6dc6bb26ad8c7047133c4
MD5 2c0883d189030de7778b78f10f9ffda6
BLAKE2b-256 8706ebb37a29d5ce83299cf6c3b98a557e10080cd4417e0324577c4548a478ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.0.0rc0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c5d359476b6953c4dd28be7971da87109f3cd9dbe33e2ea241134b16f627dacf
MD5 c6493981daa4aa0b87fe25c95627a779
BLAKE2b-256 33a77be50fe671afdfbd047e31d9f58fd46c2f637b614e0f5f2cf1a26c4a050c

See more details on using hashes here.

File details

Details for the file python_box-7.0.0rc0-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.0.0rc0-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 5514a1deb79a1cc265c4e78405a02291934ec0ac98d5a1ff5088fe4dc89e629a
MD5 92f8e7ae892001c52fbeda810c379eda
BLAKE2b-256 4eeca00e3f3d04bd43a883a19b0beeb09035dee58f55c65e7a027b91cecd46bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.0.0rc0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 198add7894d87f448716be44c1677fac30448c45c52f02e6692b41dd3468f915
MD5 cbebae39c07ce59fbfa2c2fb48eec1ca
BLAKE2b-256 448c15ee8d628060e053230aac13cc87143a2830096fae752f44b01c52d57f43

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.0.0rc0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 92be017fb8ad0f11a23eb663c0e4a2a00508d8f65e2f5bb4be8b6ff357f9c1a9
MD5 9dbabad23167ddb1b401c7f17d608519
BLAKE2b-256 85d9f3b83123862c20e9fd7a05a392b2caf9cb5afa748b6e328cb68130a6aa27

See more details on using hashes here.

File details

Details for the file python_box-7.0.0rc0-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.0.0rc0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 c6ae21723727caabdde8dc8a916659d513a5c797691c55ce916aaf502f31a803
MD5 94a5294e9081dfa9b503e6199dcc2308
BLAKE2b-256 7563fe56534f3b7fcbdc44811efbe86d346e10e1d62387d600a1fd885dd0680a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.0.0rc0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ef6539f74faf6855e76f1fb840caa44ee3ce6fa53b62e308faf2e21816b469d0
MD5 5fb9d9cdae5491be9253f42d37deeb80
BLAKE2b-256 28889919b80387037191ff81ef12301c38b494a6ed002e23dc62bdd2233e0024

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.0.0rc0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0ccf0f14eab53650e680a828571cbf59e59c65a27df318aa5f7f663f9db7fbd5
MD5 79617fdb147e68b603dd56f3396ef610
BLAKE2b-256 64d3310f9f39060fb351642fef957d644c400710bdec1b42f6269c59a7cb527c

See more details on using hashes here.

File details

Details for the file python_box-7.0.0rc0-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.0.0rc0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 fcc1230fa297f1245d27d4879a409487bce9d3f5f3f8bba73867cf3b748f3641
MD5 c23a9a6e394b9f87956a127ab58140ae
BLAKE2b-256 3d993c8e9fbb3e69848354202fce21c9aec2825535ae1879908dfc78aaa843ce

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