![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
.. image:: https://app.travis-ci.com/dduraipandian/immutable.svg?token=HYyTsSU9ynxiqecjxoc5&branch=main :target: https://travis-ci.com/dduraipandian/immutable :alt: Travis CI
.. image:: https://codecov.io/gh/dduraipandian/immutable/branch/main/graph/badge.svg :target: https://codecov.io/gh/dduraipandian/immutable :alt: codecov test coverage
.. image:: https://img.shields.io/badge/License-MIT-blue.svg :target: https://opensource.org/licenses/MIT :alt: MIT License
.. inclusion-marker-do-not-remove-start
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
When "global variables as configuration" should be shared across the project, library will help to make config immutable.
.. inclusion-marker-do-not-remove-end
.. topic:: How to install
.. code-block:: html
pip install immutable
.. topic:: Requirements
Python 3.6 and above
.. code-block:: python
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)
It will create namedtuple from all dictionary keys. When it is set to :code:True
,
it will only create namedtuple from :code:constants
(all caps variables).
Only first level of key-vales are immuted, when it is set to :code:False
. When it is set to :code:True
,
all the key-values are traversed and converted to immutable.
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 :code:False
will improve the performance, but it will mutate the data given to immutable function.
So use :code:False
, when you do not need to access the data after making it immutable.
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 :code:iterable
to filter from data.
This project is licensed under the MIT License - see the LICENSE <LICENSE>
_ file for details
FAQs
Create immutable namedtuple from dict
We found that immutable-config demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.