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]~=6.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]~=6.0 --upgrade

Install with selected dependencies

Box is no longer forcing install of external dependencies such as yaml and toml. Instead you can specify which you want, for example, [all] is shorthand for:

pip install python-box[ruamel.yaml,toml,msgpack]~=6.0 --upgrade

But you can also sub out ruamel.yaml for PyYAML.

Check out more details on installation details.

Box 6 is tested on python 3.6+, if you are upgrading from previous versions, please look through any breaking changes and new features.

Optimized Version

Box 6 is introducing 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]~=6.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-2022 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-6.0.2.tar.gz (40.6 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-6.0.2-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

python_box-6.0.2-cp310-cp310-win_amd64.whl (942.0 kB view details)

Uploaded CPython 3.10Windows x86-64

python_box-6.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

python_box-6.0.2-cp310-cp310-macosx_10_15_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10macOS 10.15+ x86-64

python_box-6.0.2-cp39-cp39-win_amd64.whl (941.8 kB view details)

Uploaded CPython 3.9Windows x86-64

python_box-6.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

python_box-6.0.2-cp39-cp39-macosx_10_15_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9macOS 10.15+ x86-64

python_box-6.0.2-cp38-cp38-win_amd64.whl (944.1 kB view details)

Uploaded CPython 3.8Windows x86-64

python_box-6.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

python_box-6.0.2-cp38-cp38-macosx_10_14_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.8macOS 10.14+ x86-64

python_box-6.0.2-cp37-cp37m-win_amd64.whl (927.7 kB view details)

Uploaded CPython 3.7mWindows x86-64

python_box-6.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

python_box-6.0.2-cp37-cp37m-macosx_10_14_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.7mmacOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: python-box-6.0.2.tar.gz
  • Upload date:
  • Size: 40.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.10

File hashes

Hashes for python-box-6.0.2.tar.gz
Algorithm Hash digest
SHA256 c15f09fa2a8730702115396b490ddc17dde3d4276a4f24eb754e35f102c41347
MD5 6dd4b6350731d23927009567515c147c
BLAKE2b-256 39c54091b5e7829144e91b5f4ecd4d5a457a63fb6b9be94de714d3fdae0a14ea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.2-py3-none-any.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.10

File hashes

Hashes for python_box-6.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2565dd56d5e9107e1499ab864f7a4dcd60f63dd5d68215a019308e36c0c98dbc
MD5 752b8b3db529573d020de4d6071e2efb
BLAKE2b-256 433bd99e539b4c5dc6c052db02f231bc624dba03ea961e224e1dacb16b1cc3b8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 942.0 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.2

File hashes

Hashes for python_box-6.0.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8b76359be83ea5d82c3d5ad20614acba522455f4f8c2aecf99847b72acd2db95
MD5 2591592232a3e33722e28a668bd9e2f2
BLAKE2b-256 4db2514347782a7b5a8a79f3641cba5da187dc3233cb4c7ca845115dfc71de1b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-6.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 113f4fb6aca9df22689e39f411b4b7cc74d3b284f2fa927666404a58d399f438
MD5 66b182c7a4626e13ac4ce6b79b7c399b
BLAKE2b-256 31a67f4b90293d208a34a3501c47612b4dc5162236c8cfa16c55c7f7cb726e2c

See more details on using hashes here.

File details

Details for the file python_box-6.0.2-cp310-cp310-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for python_box-6.0.2-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 41ae4ef7d8336b377b9caa1c1ef5b1efff3aaebe72f580eeb641c01a15288953
MD5 09714774ffbc85581ae34d5a74ac0f33
BLAKE2b-256 e762fadd6fc592d975e9bd664b727841376ef0ed5083c963ffe7b224aa71dc4b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 941.8 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.10

File hashes

Hashes for python_box-6.0.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 99e9f88069855e76cbc4846527d35bc9d1858f2272ab741f29a71c92b72b7b5b
MD5 3bbb8f4b37644d7d09463d7eef8248f1
BLAKE2b-256 9fa6e948104f3eb54fe106d4a28be9d0d13fcbee3158f5d9c83a44a36eab953e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-6.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8595d6916eb2ee6c097066886faa5a3fc9392abba8835faa63fd189d1b6ec11b
MD5 e437e807dfc3b338d36d8f77e10c367b
BLAKE2b-256 1f7c407db07bf1ec8950d58ba1a86af21a867e7fbbc39e561efe3312ca84e6a3

See more details on using hashes here.

File details

Details for the file python_box-6.0.2-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for python_box-6.0.2-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 a8f2c20c838d565b92e8733aaa24ea12c0d82f1e415b996e0ef664ac7d02938e
MD5 7ab898566fbfadb662d827614fd58fd3
BLAKE2b-256 15876a81ab42ad358570f0cfeb3df107858a2d1f20d514b73104f71b8e8d9222

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-6.0.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 944.1 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for python_box-6.0.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 b81a5398fdb97de5def918b6c206e3185c173e638d8ded9a3f0e5ef8f3e9da91
MD5 1ae1eed39af823d1a0b10c4dc5955628
BLAKE2b-256 2530ac1fa530a6da5334b1821e8bc663211131800426b06be27fff3ab6b43300

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-6.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ce824e4625bb121ef265f7eac54b29ff1c038b4c523bfea606582d8c6185737d
MD5 9ab15a138300dbc6da3640d01f6e4ad3
BLAKE2b-256 58f387f8b66a086223d5963cc029b63cada0d31493116b17bbe53a256b541610

See more details on using hashes here.

File details

Details for the file python_box-6.0.2-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_box-6.0.2-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 6cbf14b96afabaeaf6cd8c1da7c05704b0ab84cbd39188826d3fe6b2eed9bc1d
MD5 fd0767ab885e8290ca1d058c6f8c81f5
BLAKE2b-256 2c32db7daa0770a1167bb5a1dd7005e2e5c9e02637f2625da59dc95dfe35dbcd

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for python_box-6.0.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 449b190d5d8dae6b5ed67a71a0eff57bf9d9654bee2c3e21e54f0489ec0f8fd9
MD5 1727edf695f16ed8af0ab94def68ab0e
BLAKE2b-256 b4ab9bae8e21b8cb4144110ecdb8d3b7809e1dbb0473f8d256812b653eef2ac3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-6.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3a43baf2fdee399c7b3df425e2df163e9551f1d8b40ceb213f9cc0a952effa77
MD5 2fc2e59be96613f632e6188599a70288
BLAKE2b-256 bda014e95a9d67619adaf33fbbb34a3d1bdde67b266c29548bca90edc96ea5aa

See more details on using hashes here.

File details

Details for the file python_box-6.0.2-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for python_box-6.0.2-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 dbc85880cd01b1272509d660517d0fac94f104f902cc31647d1a27be070d37b3
MD5 148688baceb5c5a6f590809d059657e5
BLAKE2b-256 4e73afd0471244c1c6c59549b8d00388210edd413d011c9e15304b789aa83f2f

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