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.3.1.tar.gz
(16.7 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.3.1.tar.gz.
File metadata
- Download URL: flexible_dict-2.3.1.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9460f3be922b4cf0cd6ab373038ec2f0558117973366baa04474ba6b2e638e93
|
|
| MD5 |
2db2d0ba392c8847f49d9722566f08df
|
|
| BLAKE2b-256 |
aabc168c5cb916213ddbeacbbff051de8e51742d3aec172429dc462c2bb95f1a
|
File details
Details for the file flexible_dict-2.3.1-py3-none-any.whl.
File metadata
- Download URL: flexible_dict-2.3.1-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4cb857208348c90a1cf0300db75d56eb172eeeda7613ccc8db3f1a906c2ac79
|
|
| MD5 |
475f4cefd3556c5f2d5c4d335adc9ff0
|
|
| BLAKE2b-256 |
42d430ed0e3786ece0d1df51435826e32b8044242b4dc27bc887b6c4f98c6f27
|