Dict_Path_Immutable
Tiny Python library to modify deep dictionary properties without modifying the original dictionary (immutability).
Install
pip install Dict_Path_Immutable
Quick usage
The following, sets a property without modifying the original dictionary. It will minimize the number of clones down the line. The resulting dictionary is just a plain Python dictionary, so be warned that it will not be protected against property mutations
my_dict = {
a: {
b: 'c',
c: ['d', 'f']
}
}
new_dict = Dict_Path_Immutable.set(my_dict, 'a.b', 'f')
# {
# a: {
# b: 'f',
# c: ['d', 'f']
# }
# }
API
# Premises
my_dict = {
a: {
b: 'c',
c: ['d', 'f']
}
}
from Dict_Path_Immutable import Dict_Path_Immutable
get (initialDict, path)
Gets a property.
nested_list = Dict_Path_Immutable.get(my_dict, 'a.c')
# [
# 'c',
# 'f'
# ]
nested_list_item = Dict_Path_Immutable.get(my_dict, 'a.c.1')
# 'f'
set (initialDict, path, value)
Changes a dictionary property.
- Path can be either a string or an array.
new_dict1 = Dict_Path_Immutable.set(my_dict, 'a.b', 'f')
new_dict2 = Dict_Path_Immutable.set(my_dict, ['a', 'b'], 'f')
# {
# a: {
# b: 'f',
# c: ['d', 'f']
# }
# }
# Note that if the path is specified as a string, numbers are automatically interpreted as array indexes.
new_dict = Dict_Path_Immutable.set(my_dict, 'a.c.1', 'fooo')
# {
# a: {
# b: 'f',
# c: ['d', 'fooo']
# }
# }
delete (initialDict, path)
Deletes a property.
new_dict = Dict_Path_Immutable.delete(my_dict, 'a.c')
# {
# a: {
# b: 'f'
# }
# }
Can also delete a deep array item using splice
new_dict = Dict_Path_Immutable.delete(my_dict, 'a.c.0')
# {
# a: {
# b: 'f',
# c: ['f']
# }
# }
Metadata
Release files for Dict-Path-Immutable 0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Dict_Path_Immutable-0.3.tar.gz | 1.8 kB | Without provenance | Details for Dict_Path_Immutable-0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Dict_Path_Immutable-0.3-py3-none-any.whl | Python 3 | none | any | Details for Dict_Path_Immutable-0.3-py3-none-any.whl |
Total release size: 4.5 kB
Release files / Dict_Path_Immutable-0.3.tar.gz
| Download URL | Dict_Path_Immutable-0.3.tar.gz |
|---|---|
| Size | 1.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8d029ffb2c28ba733ea74cccb1886abdf498b6b71277923a438c2b300faa0bb8
|
|
BLAKE2b-256 checksum How to use checksums |
80358e2ce9f3a22b5d0698f9d889fa6ecf60b66be3d1fb1deb15ae25e7173791
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.4
|
Release files / Dict_Path_Immutable-0.3-py3-none-any.whl
| Download URL | Dict_Path_Immutable-0.3-py3-none-any.whl |
|---|---|
| Size | 2.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0792332021784ebc5876ea11164e343ab03d51a75f7c94b7e4207f597974d680
|
|
BLAKE2b-256 checksum How to use checksums |
268be5422dc0a7443a40bdba452fabe3aeb807b33a814134d8a96af84a9d95c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.4
|
Security for Dict-Path-Immutable 0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.