Readme File
Immutable
Immutable library helps to convert python dictionary to namedtuples and converting values to immutable datastructure recursively. Namedtuples, by default, are immutable. You can’t modify them. But If you have nested data structures, you can still modify them.
Immutable library tries to provides a function to convert them immutable and creates namedtuple from the converted dict.
Dict -> MappingProxyType
List -> Tuple
Set -> Frozenset
UseCase
When “global variables as configuration” should be shared across the project, library will help to make config immutable.
Code Example
from immutable.immutable import immutable
LOGGING = {
'formatters': {
'verbose': {
'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
'style': '{',
},
'simple': {
'format': '{levelname} {message}',
'style': '{',
},
},
'loggers': {
'django': {
'handlers': ['console'],
'propagate': True,
},
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': False,
},
'myproject.custom': {
'handlers': {'console', 'mail_admins'},
'level': 'INFO',
'filters': ['special']
}
}
}
config = immutable('LoggingConfig', LOGGING, only_const=False, recursive=True)
Options
only_const (default = False)
It will create namedtuple from all dictionary keys. When it is set to True,
it will only create namedtuple from constants (all caps variables).
recursive (default = False)
Only first level of key-vales are immuted, when it is set to False. When it is set to True,
all the key-values are traversed and converted to immutable.
clone (default = True)
Clone the given dictionary and mutates it. deepcopy is a costly operation when dictionary is to many levels of nested with basic python data structure (list, tuple, set, dict).
Setting it to False will improve the performance, but it will mutate the data given to immutable function.
So use False, when you do not need to access the data after making it immutable.
properties
Immutable function takes all the key from data given and creates namedtuple from that. If you want to create namedtuple
with selected keys, you can pass properties iterable to filter from data.
License
This project is licensed under the MIT License - see the LICENSE file for details
Metadata
Release files for immutable-config 1.0
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 |
|---|---|---|---|---|
| immutable-config-1.0.tar.gz | 4.7 kB | Without provenance | Details for immutable-config-1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| immutable_config-1.0-py3-none-any.whl | Python 3 | none | any | Details for immutable_config-1.0-py3-none-any.whl |
Total release size: 9.6 kB
Release files / immutable-config-1.0.tar.gz
| Download URL | immutable-config-1.0.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9ce4cdec94596f9433ebfdf20c43ecccd94dfe647d1c5e5f96cd3363363bff61
|
|
BLAKE2b-256 checksum How to use checksums |
a215d12b8460a51d076f63ac67bfad012bec4691a30c8e33d6ca9d828fc256b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
|
Release files / immutable_config-1.0-py3-none-any.whl
| Download URL | immutable_config-1.0-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9e5b609443d07a195fc8e38b2fa8d6e6ea88ec1ff04f0bdfd8e24f1a5c464c53
|
|
BLAKE2b-256 checksum How to use checksums |
9a692b734c339751990d13b8bd9fe43f7b8c5cbdbbfe16117137bde9065e23b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
|
Security for immutable-config 1.0
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.