A flexible way to access dict data instead of built-in dict.
Project description
Flexible Dict
A flexible way to access dict data instead of built-in dict.
Installation
pip install flexible-dict
Usage
Define a dict class and access value
Use a decorator json_object
to make class to be a flexible dict.
from flexible_dict import json_object, MISSING
@json_object
class A:
i: int = 3
j: str = "init value"
s: float
g: int = MISSING
a = A()
print(a) # actual is a dict
print(a.i) # access value via x.y
print(a.j)
a.j = "update value" # set value
print(a['j']) # access value via native dict way
Build a json_object class from json data
Suppose there is a file named a.py
with content
{
"a": 1,
"b": "two",
"c": {
"d": 4,
"e": "li"
}
}
Run the script bellow
python -m flexible_dict build_class --name A --file a.json --output a.py
Then a file named a.py
will be generated
from flexible_dict import json_object
@json_object
class A:
a: int
b: str
c: dict
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
flexible_dict-2.1.1.tar.gz
(15.7 kB
view details)
Built Distribution
File details
Details for the file flexible_dict-2.1.1.tar.gz
.
File metadata
- Download URL: flexible_dict-2.1.1.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69a515ae7114679775e5355f99a5e866ad8fd91a1ea0e85b11b89ec5c22d2598 |
|
MD5 | a54dc37f0a62eaa94fc2772c2c304094 |
|
BLAKE2b-256 | cb40a328aba0ef99e000a3a71f2a16c7b1962d43bdafa3e8f5737ab742443213 |
File details
Details for the file flexible_dict-2.1.1-py3-none-any.whl
.
File metadata
- Download URL: flexible_dict-2.1.1-py3-none-any.whl
- Upload date:
- Size: 16.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cd73a8344f70d6e471542d23c22f2683707b1266cc60fbbe80dc01fa3e1dca5 |
|
MD5 | ca1e5ccf8209e0b29811bdc1df15fcd4 |
|
BLAKE2b-256 | 6054f7f4d8ee8c7763067d81501a0501402b52d8fbe00594eb299cbe4e2a2e28 |