Skip to content

bnlucas/python-dthreads

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dThreads

dThreads is a small module for creating object-like dictionaries based on Bunch. Threads extends Bunch with the ability to both load and dump in JSON or YAML format.

Installation via pip:

pip install dthreads

Quick usage:

>>> from dthreads import Threads
>>> items = Threads(a=0, b=1, c=[0, 2], d=Threads(x=0, y=1, z=2))
>>> items
{'a': 0, 'c': [0, 2], 'b': 1, 'd': {'y': 1, 'x': 0, 'z': 2}}
>>> items.c(1)
2
>>> items.d
{'y': 1, 'x': 0, 'z': 2}

dThreads offers serialization to JSON:

>>> items = Threads(a=0, b=1, c=[0, 2], d=Threads(x=0, y=1, z=2))
>>> items.json_dumps()
{"a": 0, "c": [0, 2], "b": 1, "d": {"y": 1, "x": 0, "z": 2}}
>>> with open('data.json', 'w') as f:
...     items.json_dump(f)

JSON methods supported: load, loads, dump, dumps

dThreads offers serialization to YAML:

>>> items = Threads(a=0, b=1, c=[0, 2], d=Threads(x=0, y=1, z=2))
>>> items.yaml_dump()
!threads.Threads
a: 0
b: 1
c: !!python/object/new:__main__.Strands
    listitems:
    - 0
    - 2
d: !threads.Threads
    x: 0
    y: 1
    z: 2

YAML methods supported: load, load_all, safe_load, safe_load_all, dump, safe_dump

About

Object-like dictionaries

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages