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

Uploaded Source

Built Distributions

python_box-7.3.2-py3-none-any.whl (29.5 kB view details)

Uploaded Python 3

python_box-7.3.2-cp313-cp313-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.13Windows x86-64

python_box-7.3.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

python_box-7.3.2-cp313-cp313-macosx_10_13_universal2.whl (1.8 MB view details)

Uploaded CPython 3.13macOS 10.13+ universal2 (ARM64, x86-64)

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

Uploaded CPython 3.12Windows x86-64

python_box-7.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

python_box-7.3.2-cp312-cp312-macosx_10_13_universal2.whl (1.8 MB view details)

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

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

Uploaded CPython 3.11Windows x86-64

python_box-7.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

python_box-7.3.2-cp311-cp311-macosx_10_9_universal2.whl (1.8 MB view details)

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

python_box-7.3.2-cp310-cp310-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.10Windows x86-64

python_box-7.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

python_box-7.3.2-cp310-cp310-macosx_10_9_universal2.whl (1.8 MB view details)

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

python_box-7.3.2-cp39-cp39-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.9Windows x86-64

python_box-7.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

python_box-7.3.2-cp39-cp39-macosx_10_9_universal2.whl (1.8 MB view details)

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

File details

Details for the file python_box-7.3.2.tar.gz.

File metadata

  • Download URL: python_box-7.3.2.tar.gz
  • Upload date:
  • Size: 45.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for python_box-7.3.2.tar.gz
Algorithm Hash digest
SHA256 028b9917129e67f311932d93347b8a4f1b500d7a5a2870ee3c035f4e7b19403b
MD5 8a8530f1b46f3a2dc6702a730c4ca3c1
BLAKE2b-256 29f7635eed8c500adf26208e86e985bbffb6ff039cd8950e3a4749ceca904218

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-7.3.2-py3-none-any.whl
  • Upload date:
  • Size: 29.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for python_box-7.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fd7d74d5a848623f93b5221fd9fb00b8c00ff0e130fa87f396277aa188659c92
MD5 2890c90aa530e993dfffc70f3d413c65
BLAKE2b-256 37138a990c6e2b6cc12700dce16f3cb383324e6d9a30f604eca22a2fdf84c923

See more details on using hashes here.

File details

Details for the file python_box-7.3.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: python_box-7.3.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for python_box-7.3.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e143295f74d47a9ab24562ead2375c9be10629599b57f2e86717d3fff60f82a9
MD5 26266588ab4639b38c6abfde9ead92a1
BLAKE2b-256 439072367e03033c11a5e82676ee389b572bf136647ff4e3081557392b37e1ad

See more details on using hashes here.

File details

Details for the file python_box-7.3.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for python_box-7.3.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3ca4685a7f764b5a71b6e08535ce2a96b7964bb63d8cb4df10f6bb7147b6c54b
MD5 2d6c7c2773d0b87442fd381a3741c212
BLAKE2b-256 88aebaf3a8057d8129896a7e02619df43ea0d918fc5b2bb66eb6e2470595fbac

See more details on using hashes here.

File details

Details for the file python_box-7.3.2-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for python_box-7.3.2-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 1dfc3b9b073f3d7cad1fa90de98eaaa684a494d0574bbc0666f74fa8307fd6b6
MD5 a57efebf4bbb15430b150aba7cb3a5a1
BLAKE2b-256 2f398bec609e93dbc5e0d3ea26cfb5af3ca78915f7a55ef5414713462fedeb59

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-7.3.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for python_box-7.3.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9eead914b9fb7d98a1473f5027dcfe27d26b3a10ffa33b9ba22cf948a23cd280
MD5 668f9324f320e02be5c09914760d43e2
BLAKE2b-256 e46b32484b2a3cd2fb5e5f56bfb53a4537d93a4d2014ccf7fc0c0017fa6f65e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2e2a72e2f6fb97c7e472ff3272da207ecc615aa222e52e98352391428527c469
MD5 2c5523a99c6ce70395c06e914b0f0494
BLAKE2b-256 ce5d76b4d6d0e41edb676a229f032848a1ecea166890fa8d501513ea1a030f4d

See more details on using hashes here.

File details

Details for the file python_box-7.3.2-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for python_box-7.3.2-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 39009a2da5c20133718b24891a206592adbe09169856aedc450ad1600fc2e511
MD5 52b907343999911ca49000386b2648d4
BLAKE2b-256 45680c2f289d8055d3e1b156ff258847f0e8f1010063e284cf5a612f09435575

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-7.3.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for python_box-7.3.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 488f0fba9a6416c3334b602366dcd92825adb0811e07e03753dfcf0ed79cd6f7
MD5 7c862342a03a7e4721e5fb3affc3b7bc
BLAKE2b-256 d4e26cdc8649381ae14def88c3e2e93d5b8b17a622a95896e0d1c92861270b7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 064cb59b41e25aaf7dbd39efe53151a5f6797cc1cb3c68610f0f21a9d406d67e
MD5 5578478db5800c7ba5acd22444b5bbad
BLAKE2b-256 b75251b6081562daa864847692536260200b337ccb4176d1e5f626ae48a7d493

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.3.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 32163b1cb151883de0da62b0cd3572610dc72ccf0762f2447baf1d2562e25bea
MD5 34e69af66d553c6322cdf461605522fa
BLAKE2b-256 1e3f133619c00d8a9d4f86efd8626c0e4ec356c8b8dabac66da18dac5cfaf70c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-7.3.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.11

File hashes

Hashes for python_box-7.3.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3aa52e3b5cc50c80bb7ef4be3e41e81d095310f619454a7ffd61eef3209a6225
MD5 a421366e8ffdeee2a097434746647303
BLAKE2b-256 346b95d1f13ae2c2c72854f8e845385312693a67ba0b2c9499d57476d8394c61

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 47d72e96547d8e2c2c333909826e9fae338d9a7e4cde07d5c6058cdd468432c0
MD5 d07c6c2b7c43f2f7e8f6eac50e0e94c0
BLAKE2b-256 25be97c585206086f50175b72e31f092f0afb3de43013d040097c1febbc7a2ce

See more details on using hashes here.

File details

Details for the file python_box-7.3.2-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for python_box-7.3.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 d136163294fd61a1554db7dd203f2e3035064798d30c17d67d948f0de5c572de
MD5 e96bcd9526b2f3496e6009a49c5fa598
BLAKE2b-256 efee7d9a4bc3ac4e693018506fb21893f4ba253694fd31dd93f7195f57a6c8d0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for python_box-7.3.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ea436e7ff5f87bd728472f1e31a9e6e95572c81028c44a8e00097e0968955638
MD5 0232ab96958c05919e0c3f7f76e3eaa6
BLAKE2b-256 948f984677ef56e5a82c73a8a270a8388f4fa65750ab95bc9c171a465b8bd97e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 42a760074ba12ccc247796f43b6c61f686ada4b8349ab59e2a6303b27f3ae082
MD5 03b9d909449b8008c7ae3e61a9aedd20
BLAKE2b-256 b61ed1c02d64009e59aed7ecec893c68c12e8de5d983b5410d52c7c8a35433d9

See more details on using hashes here.

File details

Details for the file python_box-7.3.2-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for python_box-7.3.2-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 f3118ab3076b645c76133b8fac51deee30237cecdcafc3af664c4b9000f04db9
MD5 57da3559fd296ff17bc010bf52c87107
BLAKE2b-256 3b3d3e3d803b16cc3d49cc4ffe52af742f7bdb42c130b1bc937ad2c150bee012

See more details on using hashes here.

Supported by

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