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

pip install --upgrade python-box[all]

Box 5 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 --upgrade python-box[ruamel.yaml,toml,msgpack]

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

Check out more details on installation details.

Box 6 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 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] --force

If you have any issues please open a github issue with the error you are experiencing!

Overview

Box is designed to be an easy drop in transparently replacements for dictionaries, thanks to Python’s duck typing capabilities, which adds dot notation access. Any sub dictionaries or ones set after initiation will be automatically converted to a Box object. You can always run .to_dict() on it to return the object and all sub objects back into a regular dictionary.

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 lookup 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.0rc2.tar.gz (38.0 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.0rc2-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

python_box-6.0.0rc2-cp310-cp310-win_amd64.whl (930.8 kB view details)

Uploaded CPython 3.10Windows x86-64

python_box-6.0.0rc2-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.0rc2-cp39-cp39-win_amd64.whl (930.6 kB view details)

Uploaded CPython 3.9Windows x86-64

python_box-6.0.0rc2-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.0rc2-cp38-cp38-win_amd64.whl (933.0 kB view details)

Uploaded CPython 3.8Windows x86-64

python_box-6.0.0rc2-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.0rc2-cp37-cp37m-win_amd64.whl (915.9 kB view details)

Uploaded CPython 3.7mWindows x86-64

python_box-6.0.0rc2-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.0rc2.tar.gz.

File metadata

  • Download URL: python-box-6.0.0rc2.tar.gz
  • Upload date:
  • Size: 38.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for python-box-6.0.0rc2.tar.gz
Algorithm Hash digest
SHA256 23bfb56e3330c8cba773c338a7f2d0a881859f18a6edd0b89d0f538670bf37e1
MD5 10410b09d5ae8519c29a498500ccf106
BLAKE2b-256 b2c430f956d9cd4281594a3952680fc6347eeea9f3bb85455d7f2f0a6f60de01

See more details on using hashes here.

File details

Details for the file python_box-6.0.0rc2-py3-none-any.whl.

File metadata

  • Download URL: python_box-6.0.0rc2-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for python_box-6.0.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 773ac822da2f8fff2d77cbf9f127945058f3a58d49521b98c6fbe2e455278a5b
MD5 57755a8fe5634bb4a37e8fbc915680dd
BLAKE2b-256 e39a3c5ea29478e6d8abc6d4f2a0400416019ab22c6f9aa91fb70b029e8b5c43

See more details on using hashes here.

File details

Details for the file python_box-6.0.0rc2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: python_box-6.0.0rc2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 930.8 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for python_box-6.0.0rc2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 72f6642507692a1d6f27f48147db15b6a6c03464be537974d1c2c4421e87d3fe
MD5 707cca893fc41a68e24041ea4b05d296
BLAKE2b-256 e014daebbb7295f1cb9ba965cc7bc7ef57ce5fb4aef0bad1dc3a4b41f6fe3b1b

See more details on using hashes here.

File details

Details for the file python_box-6.0.0rc2-cp310-cp310-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: python_box-6.0.0rc2-cp310-cp310-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.10, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2

File hashes

Hashes for python_box-6.0.0rc2-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 d2ed623994885d78a47b4214ac9aefd29a9d7b66007ea54b72097e159b64c7f7
MD5 7520dc4fd494c8f22ddcbd5d631a7a71
BLAKE2b-256 06174928af8942e1c0e34986fe22b7820bc70f164b9082510b1a8725eb25941e

See more details on using hashes here.

File details

Details for the file python_box-6.0.0rc2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: python_box-6.0.0rc2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 930.6 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for python_box-6.0.0rc2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 571c2e547d3fe75c9fdc937cf4e19ed8c81224816c5910143e10bb18816e6aa2
MD5 087e5d54443e6db6effd5915a6759d44
BLAKE2b-256 d9cd5076e7269f446fef2858fceca574c7e5af9f728278af40e17f6b781b8cda

See more details on using hashes here.

File details

Details for the file python_box-6.0.0rc2-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: python_box-6.0.0rc2-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for python_box-6.0.0rc2-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 16f57c3a065844d521bb7d8091bf6d91248dd41b62b61751630dd68ddf620407
MD5 343dea3067376bd0ab782fb8db3e1a1f
BLAKE2b-256 8b51b78b28c8c705fbb6628f2462ea13a27b2d070053be62255c3ae4f90267c7

See more details on using hashes here.

File details

Details for the file python_box-6.0.0rc2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: python_box-6.0.0rc2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 933.0 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for python_box-6.0.0rc2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 8cdb819476d6376a43a8ce786610f26d78f74afb52154401ec8fe24e14e50c52
MD5 78f7dedc2a5c659d554cd909110e20ed
BLAKE2b-256 a53c67ff17c4d0baa3903ed53df292957edd247764d834caca728f314010fdf4

See more details on using hashes here.

File details

Details for the file python_box-6.0.0rc2-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: python_box-6.0.0rc2-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for python_box-6.0.0rc2-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 129d9a08d1be7b8e64a0fdcd85c9ba91024ec73362449831a284a1e3dd9b1a6d
MD5 a399c61ef543ac775e87595541487287
BLAKE2b-256 2bd84c87bc0f09382cf0755293fde3d44a34864dc67ddb5be6ba190222e32367

See more details on using hashes here.

File details

Details for the file python_box-6.0.0rc2-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: python_box-6.0.0rc2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 915.9 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9

File hashes

Hashes for python_box-6.0.0rc2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 eaf23397a938d32adedda8ee5b604ee93cf30b1bac585db49898d71227f8a21a
MD5 5eff78444e75e430103af28dc81d988b
BLAKE2b-256 0681f65d2973aadb759b5cff935897de48662fc9692c409056c19c1ca6bae7a4

See more details on using hashes here.

File details

Details for the file python_box-6.0.0rc2-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: python_box-6.0.0rc2-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for python_box-6.0.0rc2-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 2339da17d76d7f1f92c3ef531ae5fac8a5987da55f7c907650c4cc42a241aa3b
MD5 b89e966dca8fbcf95bc76e8c25bfa342
BLAKE2b-256 8b62d8410d6ff233b449c240c1f6ed8628b05ef7868e17c6105ca30e4b6684be

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