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.2.0.tar.gz
(16.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flexible_dict-2.2.0.tar.gz.
File metadata
- Download URL: flexible_dict-2.2.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f77e9ab7dbf3c5d309c1e46115383a96051b640227e1fdd6a9ff70490259199f
|
|
| MD5 |
9059b27fd2898611330a5b50b0300c5c
|
|
| BLAKE2b-256 |
ef1adcaa6423d440822ed72efc1aaf9ed03d6e5d43e19c7bcbc033dd0bccaba9
|
File details
Details for the file flexible_dict-2.2.0-py3-none-any.whl.
File metadata
- Download URL: flexible_dict-2.2.0-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd423cb4af4e3d5c8ab025cad71c9d6136a5e3f4523b53021af592099e4700e2
|
|
| MD5 |
bf5e67837b6f2d7bededabacbdc9631c
|
|
| BLAKE2b-256 |
a15974513717da2c09a0c4c4aff6db530716ea953cbf8f549adbe1a440a4cc4b
|