Skip to main content

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


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.0.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flexible_dict-2.3.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file flexible_dict-2.3.0.tar.gz.

File metadata

  • Download URL: flexible_dict-2.3.0.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

Hashes for flexible_dict-2.3.0.tar.gz
Algorithm Hash digest
SHA256 aa607a723737f6e863dfe4fbbf2beeb31c36d8b15e4829b2143d0e7328f44485
MD5 69177f154c85638f7fb4752071ca20a0
BLAKE2b-256 f8bfcf00f1ef693cb40824ef273d23e99bba46e51f22d8e6ab384a651d31016a

See more details on using hashes here.

File details

Details for the file flexible_dict-2.3.0-py3-none-any.whl.

File metadata

  • Download URL: flexible_dict-2.3.0-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

Hashes for flexible_dict-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06baee570128b56569f73556a120f3353a48c0c291923c74b2f098870d7c4743
MD5 779fb90f88baf5eaf718b259c994bf88
BLAKE2b-256 c07d787613c68f698a2d77d70bcc47bfb0b03132aecd96ccc78d09625817f921

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page