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
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-1.1.1.tar.gz
(6.0 kB
view hashes)
Built Distribution
Close
Hashes for flexible_dict-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32249e94bed93979918943716415619fabd97c6de962b63ae4350ec8a6f12a28 |
|
MD5 | 618a9296626faac0ee395f50e213812e |
|
BLAKE2b-256 | eb12562ac1003d8e4d2765363917eaebafc78dfbf8d2305f889641cd7fd2e9bb |