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.1.tar.gz (45.7 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-7.3.1-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

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

Uploaded CPython 3.13Windows x86-64

python_box-7.3.1-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.1-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.1-cp312-cp312-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.12Windows x86-64

python_box-7.3.1-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.1-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.1-cp311-cp311-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.11Windows x86-64

python_box-7.3.1-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.1-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.1-cp310-cp310-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.10Windows x86-64

python_box-7.3.1-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.1-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.1-cp39-cp39-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.9Windows x86-64

python_box-7.3.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: python_box-7.3.1.tar.gz
  • Upload date:
  • Size: 45.7 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.1.tar.gz
Algorithm Hash digest
SHA256 a0bd9dbb4ddd2842f8d0143b8aa0c87d0e82e39093dd4698a5cbbb2d2ac71361
MD5 f77815d3ad12e408e5bb3a978a734cb1
BLAKE2b-256 bb35911965b97acf8f7813caa49487eb4c14c5de527d47d9b9ef0a5b16016834

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-7.3.1-py3-none-any.whl
  • Upload date:
  • Size: 29.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2d77100d0d5ad67e0d062fac4f77f973851db236f4a445c60b02d0415f83b0d6
MD5 8db4f9d38cb4242e6f78430c29cc9773
BLAKE2b-256 33b604e12fb310aa3d51af41ea33c432bbafe82d6ec84a420dc0b02ab588e649

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-7.3.1-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.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4fccc0b218937a6254219073f945117978f5222eff1bbae8a35b11c6e9651f5d
MD5 0e192d07c9d260f4c17098bfbeec5821
BLAKE2b-256 ce60a74487a0d926e159c708baad3bc7d94bb07485ed08a14cf14a1eef824b2b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2fe1e1c705535ec5ab9fa66172cf184a330fd41638aaf638a08e33a12c7c3f71
MD5 002ecdc07891b9c9ed3c592cdae53d0a
BLAKE2b-256 b0100f34ca5f05f501cf1dc804a4393c54b4b4a007190a2de50940fef17a246c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.3.1-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 e5e0c2bf73ab1020fc62f2a7161b8b0e12ee29872292ec33fb8124aa81adb48e
MD5 c03def17967616352687edd2335582b7
BLAKE2b-256 3b9a954f01c17adeda5bd32d9c943c9a2301977bba1cb8c4bbc5812e9096815c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-7.3.1-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.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 34d409137b41c15322491f353c331069a07d194573e95e56eae07fe101c04cbe
MD5 6fca78d8c18200803b876e5cfc8af5e0
BLAKE2b-256 2a1fe955b9ec9f80e4b2bc78d70c0ca2b3690ea6445cad597d44125dce3c9584

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f6277ef305fb1cc75e903416e0b4f59952675d55e8ae997924f4e2f6e5abf61b
MD5 615aef60a1f9a083ecbe2f1f7dca93a6
BLAKE2b-256 8a327f62656e0b15005e9e05f5b7a0c66fe8c4332ddc011ee9e9b04a8e9fe467

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.3.1-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 3320d3fa83f006ae44bda02f9ee08647ed709506baf5ae85be3eb045683dd12b
MD5 9d1eeb9d987fc29d6cdd37b04f91ec0d
BLAKE2b-256 0e93a958c0b9d8e45f9305cebf87a6345744cb723b88b6ea6ec4e4b541112206

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-7.3.1-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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6fd0463e20a4c990591094fbb0f4e3b39f8212d1faf69648df4ffac10912c49e
MD5 efe009ebe1daabfb7d8f4f2273962af5
BLAKE2b-256 4a03003033227213f03ce7270585e01fcdefb19fc48d5feff75df2f02f0c3d01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7aa85d0f1f0ea1ef4af33c0f3a133b8cec8f0ad3bfd6868370833efb8b9f86b3
MD5 bd41c1ebcef860d9cda92f2c9c706da1
BLAKE2b-256 3a4a9a5cc569ff42f3ca7e8a4a31345a40c34e89b3360a9436c4b01db1164e5b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.3.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 7cdcc0585d5840a04a74e64301d4ec5b0a05bc98a305d0f9516d3e59d265add1
MD5 87f68464f3804c616551e60853401afb
BLAKE2b-256 63ae9bf11924211ea0a3ca3aa1f492373ef6e335896ee738bb6126d325a410b2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-7.3.1-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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f7fef93deb2695716218f513cc43e665f447a85e41cf58219e42e026c570bd67
MD5 bddbadd03d5e542f5452f68389575b64
BLAKE2b-256 5f693657dcd152247e1a18bcd2dcf8816a7b8da64a3f06518eba1aa57bd3b3df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d375605b159c174b0d60b6acb3586bc47ba75f542b614e96fac2ef899c08add8
MD5 43610682e1b5b0d324b9fb9d37942d08
BLAKE2b-256 a1c25eced82d15dd1aaa8577b9e7fe5eb80e0483e3b6db55f9b666d07b6c427a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.3.1-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 fadf589c5d37d5bf40d25f6580d500168f2fc825d2f601c25e753ffc8d4bbec0
MD5 7216eceb1dbbada6d548e5436b92f4a9
BLAKE2b-256 248e62203632e636098ab42a9187ed9d923ff51d9fe6f1cb38bf83c82cd5fbcb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_box-7.3.1-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.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 0ed2024e27d67c5cf1ed1f88d8849aace9234d7a198fd4d5c791ed12e99e7345
MD5 faf952beda2c893fe4c59edd6f578fe4
BLAKE2b-256 17ea18a6f4094555c68d0119eca1738260d63c06339203c132d57792012c1a6a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.3.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4a5bf3264cd4ee9b742aefadb7ff549297dd7eef8826b3a4b922a4a44e9b0751
MD5 a771864ef486c8143ff4631cc765e94e
BLAKE2b-256 f0548fc090b9ce781741c91d24606c5e3b57e0d2cd68430f1099b020e6d947c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_box-7.3.1-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 a48050391cb4d8dcec4b0f8c860b778821ae013a293d49f0cbaeab5548c46829
MD5 ca0b7f5c5be4782f008ae10eff9cb8a3
BLAKE2b-256 668f9da2e28e764ba3a85653aaf866603444166699058718d452c300e2c2272e

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