autotypedict
Dictionary-like class that automatically typecasts string-like values to standard types.
Installation
Using pip
python -m pip install -U autotypedict
Usage
Importing the class
from autotypedict import AutoTypeDict
Examples
>>> d = {"foo": {"baz": "42"}, "bar": {"baz": "n/a", "qux": "true"}}
>>> AutoTypeDict(d) # typecast every value
{'foo': {'baz': 42}, 'bar': {'baz': None, 'qux': True}}
>>> AutoTypeDict(d, ignored_keys=("baz",)) # ignore "baz"
{'foo': {'baz': '42'}, 'bar': {'baz': 'n/a', 'qux': True}}
>>> AutoTypeDict(d, ignored_keys=("bar.baz",)) # ignore d["bar"]["baz"]
{'foo': {'baz': 42}, 'bar': {'baz': 'n/a', 'qux': True}}
>>> td = AutoTypeDict()
>>> td.data = d # updating data attribute to ignore typecasting
>>> td
{'foo': {'baz': '42'}, 'bar': {'baz': 'n/a', 'qux': 'true'}}
Caveats
Values are only typecasted when the AutoTypeDict instance is updated directly, so avoid using type-specific operations on mutable objects within the dictionary (e.g. list.append, dict.update).
If using these methods is unavoidable, call the .refresh() instance method to re-process the dictionary.
Alternatives to common type operations:
| Operation | Non-typecasted | Typecasted |
|---|---|---|
| Append to list | td["list"].append(v) |
td["list"] += [v] |
| Update dict | td["dict"].update({k: v}) |
td["dict"][k] = v |
| Merge dict | td["dict"].update(other_dict) |
td["dict"] |= merge_dict [1] |
[1]: Python 3.9 or later
Metadata
Release files for autotypedict 1.0.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 | |
|---|---|---|---|---|
| autotypedict-1.0.0.tar.gz | 4.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| autotypedict-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.0 kB
Release files / autotypedict-1.0.0.tar.gz
| Download URL | autotypedict-1.0.0.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
48b68230ba73ab8bfaaaf80ed429d2e521984eed8f01bf1d21e74db0becf2f06
|
|
BLAKE2b-256 checksum How to use checksums |
451bf319eac1a1536a561488adc377f686335a6b67d4af209d70ecce65c426a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / autotypedict-1.0.0-py3-none-any.whl
| Download URL | autotypedict-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
79a9d3c4326129488e4b54f8322def576f784a9703c151ca79c31ff5bba867ba
|
|
BLAKE2b-256 checksum How to use checksums |
0d8879c0fa3c4d7ea568d780e538c380f5dd9a504993ad270ad6b53929221d20
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for autotypedict 1.0.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.