diot.diot
diot module
Diot
— Dictionary with dot notation</>CamelDiot
— With camel case conversion</>SnakeDiot
— With snake case conversion</>FrozenDiot
— The frozen diot</>OrderedDiot
— With key order preserved</>
Dictionary with dot notation
~~~python
d = Diot(a=1, b=2) d.a = 2 d['a'] = 2 d.a # 2 d['a'] # 2 d.pop('a') # 2 d.pop('x', 1) # 1 d.popitem() # ('b', 2) d.update(a=3, b=4) # {'a': 3, 'b': 4} d | {'a': 1, 'b': 2} # {'a': 1, 'b': 2} (d unchanged) d |= {'a': 1, 'b': 2} # d == {'a': 1, 'b': 2} del d.a del d['b'] d.freeze() d.a = 1 # DiotFrozenError d.unfreeze() d.a = 1 # ok d.setdefault('b', 2) 'b' in d d.copy() d.deepcopy() ~~~
*args
— Anything that can be sent to dict construct**kwargs
— keyword argument that can be sent to dict constructSome diot configurations can also be passed, including: diot_nest: Types to nestly convert values diot_transform: The transforms for keys diot_frozen: Whether to generate a frozen diot. True: freeze the object recursively if there are Diot objects in descendants False: Don'f freeze 'shallow': Only freeze at depth = 1
__contains__
(
name
)
(bool) — True if the dictionary has the specified key, else False.</>__delitem__
(
name
)
— Delete self[key].</>__getitem__
(
name
)
(any) — x.getitem(y) <==> x[y]</>__ior__
(
other
)
(Diot) — Return self|=value.</>__or__
(
other
)
(Diot) — Return self|value.</>__setitem__
(
name
,value
)
— Set self[key] to value.</>accessible_keys
(
)
(iterable of str) — Get the converted keys</>clear
(
)
— Clear the object</>copy
(
)
(Diot) — Shallow copy the object</>freeze
(
frozen
)
— Freeze the diot object</>from_namespace
(
namespace
,recursive
,diot_nest
,diot_transform
,diot_frozen
)
(Diot) — Get a Diot object from an argparse namespace</>get
(
name
,value
)
(any) — Get the value of a key name</>pop
(
name
,*value
)
(any) — Pop a key from the object and return the value. If key does notexist, return the given default value </>popitem
(
)
(str, any) — Pop last item from the object</>setdefault
(
name
,value
)
(any) — Set a default value to a key</>thaw
(
recursive
)
— A context manager for temporarily change the diot</>to_dict
(
)
(dict(str: any)) — Turn the Box and sub Boxes back into a nativepython dictionary. </>to_json
(
filename
,encoding
,errors
,**json_kwargs
)
(str, optional) — Convert to a json string or save it to json file</>to_toml
(
filename
,encoding
,errors
)
(str, optional) — Convert to a toml string or save it to toml file</>to_yaml
(
filename
,default_flow_style
,encoding
,errors
,**yaml_kwargs
)
(str, optional) — Convert to a yaml string or save it to yaml file</>unfreeze
(
recursive
)
— Unfreeze the diot object</>update
(
*value
,**kwargs
)
— Update the object. Shortcut:|=
</>update_recursively
(
*value
,**kwargs
)
— Update the object. Shortcut:|=
</>
from_namespace
(
namespace
, recursive=True
, diot_nest=True
, diot_transform='safe'
, diot_frozen=False
)
Get a Diot object from an argparse namespace
~~~python
from argparse import Namespace Diot.from_namespace(Namespace(a=1, b=2)) ~~~
namespace
(Namespace) — The namespace objectrecursive
(bool, optional) — Do it recursively?diot_nest
(Union(bool, iterable of type), optional) — Types to nestly convert valuesdiot_transform
(Union(callable(str: str), str), optional) — The transforms for keysdiot_frozen
(bool or str, optional) — Whether to generate a frozen diot.- - True: freeze the object recursively if there are Diot objects
- - False: Don'f freeze
- -
shallow
: Only freeze at depth = 1
diot_missing
— How to deal with missing keys when accessing them- - An exception class or object to raise
- -
None
to returnNone
- - A custom function with first argument the key and second
the diot object.
The converted diot object.
__setitem__
(
name
, value
)
Set self[key] to value.
__getitem__
(
name
)
→ any
x.getitem(y) <==> x[y]
pop
(
name
, *value
)
Pop a key from the object and return the value. If key does notexist, return the given default value
name
(str) — The keyvalue
— The default value to return if the key does not exist
The value corresponding to the name or the default value
DiotFrozenError
— when try to pop from a frozen diot
popitem
(
)
Pop last item from the object
A tuple of key and value
DiotFrozenError
— when try to pop from a frozen diot
update
(
*value
, **kwargs
)
Update the object. Shortcut: |=
args
— args that can be sent to dict to update the objectkwargs
— kwargs that can be sent to dict to update the object
DiotFrozenError
— when try to update a frozen diot
update_recursively
(
*value
, **kwargs
)
Update the object. Shortcut: |=
args
— args that can be sent to dict to update the objectkwargs
— kwargs that can be sent to dict to update the object
DiotFrozenError
— when try to update a frozen diot
__delitem__
(
name
)
Delete self[key].
freeze
(
frozen='shallow'
)
Freeze the diot object
frozen
(str or bool, optional) — The frozen argument indicating how to freeze:shallow: only freeze at depth=1 True: freeze recursively if there are diot objects in children False: Disable freezing
unfreeze
(
recursive=False
)
Unfreeze the diot object
recursive
(bool, optional) — Whether unfreeze all diot objects recursively
thaw
(
recursive=False
)
A context manager for temporarily change the diot
recursive
(bool, optional) — Whether unfreeze all diot objects recursively
self, the reference to this diot.
setdefault
(
name
, value
)
Set a default value to a key
name
(str) — The key namevalue
(any) — The default value
The existing value or the value passed in
DiotFrozenError
— when try to set default to a frozen diot
accessible_keys
(
)
Get the converted keys
The accessible (transformed) keys
get
(
name
, value=None
)
Get the value of a key name
name
(str) — The key namevalue
(any, optional) — The value to return if the key does not exist
The corresponding value or the value passed in if the key doesnot exist
__contains__
(
name
)
→ bool
True if the dictionary has the specified key, else False.
clear
(
)
Clear the object
to_dict
(
)
Turn the Box and sub Boxes back into a nativepython dictionary.
The converted python dictionary
to_json
(
filename=None
, encoding='utf-8'
, errors='strict'
, **json_kwargs
)
Convert to a json string or save it to json file
filename
(str, PathLike, or NoneType, optional) — The filename to save the json to, if not given a jsonstring will be returnedencoding
(str, optional) — The encoding for saving to fileerrors
(str, optional) — The errors handling for saveing to fileSee python's open function**json_kwargs
— Other kwargs for json.dumps
The json string with filename is not given
to_yaml
(
filename=None
, default_flow_style=False
, encoding='utf-8'
, errors='strict'
, **yaml_kwargs
)
Convert to a yaml string or save it to yaml file
filename
(str, PathLike, or NoneType, optional) — The filename to save the yaml to, if not given a yamlstring will be returneddefault_flow_style
(bool, optional) — The default flow style for yaml dumpingSeeyaml.dump
encoding
(str, optional) — The encoding for saving to fileerrors
(str, optional) — The errors handling for saveing to fileSee python's open function**yaml_kwargs
— Other kwargs foryaml.dump
The yaml string with filename is not given
to_toml
(
filename=None
, encoding='utf-8'
, errors='strict'
)
Convert to a toml string or save it to toml file
filename
(str, PathLike, or NoneType, optional) — The filename to save the toml to, if not given a tomlstring will be returnedencoding
(str, optional) — The encoding for saving to fileerrors
(str, optional) — The errors handling for saveing to fileSee python's open function
The toml string with filename is not given
With camel case conversion
*args
— Anything that can be sent to dict construct**kwargs
— keyword argument that can be sent to dict constructSome diot configurations can also be passed, including: diot_nest: Types to nestly convert values diot_transform: The transforms for keys diot_frozen: Whether to generate a frozen diot. True: freeze the object recursively if there are Diot objects in descendants False: Don'f freeze 'shallow': Only freeze at depth = 1
__contains__
(
name
)
(bool) — True if the dictionary has the specified key, else False.</>__delitem__
(
name
)
— Delete self[key].</>__getitem__
(
name
)
(any) — x.getitem(y) <==> x[y]</>__ior__
(
other
)
(Diot) — Return self|=value.</>__or__
(
other
)
(Diot) — Return self|value.</>__setitem__
(
name
,value
)
— Set self[key] to value.</>accessible_keys
(
)
(iterable of str) — Get the converted keys</>clear
(
)
— Clear the object</>copy
(
)
(Diot) — Shallow copy the object</>freeze
(
frozen
)
— Freeze the diot object</>from_namespace
(
namespace
,recursive
,diot_nest
,diot_transform
,diot_frozen
)
(Diot) — Get a Diot object from an argparse namespace</>get
(
name
,value
)
(any) — Get the value of a key name</>pop
(
name
,*value
)
(any) — Pop a key from the object and return the value. If key does notexist, return the given default value </>popitem
(
)
(str, any) — Pop last item from the object</>setdefault
(
name
,value
)
(any) — Set a default value to a key</>thaw
(
recursive
)
— A context manager for temporarily change the diot</>to_dict
(
)
(dict(str: any)) — Turn the Box and sub Boxes back into a nativepython dictionary. </>to_json
(
filename
,encoding
,errors
,**json_kwargs
)
(str, optional) — Convert to a json string or save it to json file</>to_toml
(
filename
,encoding
,errors
)
(str, optional) — Convert to a toml string or save it to toml file</>to_yaml
(
filename
,default_flow_style
,encoding
,errors
,**yaml_kwargs
)
(str, optional) — Convert to a yaml string or save it to yaml file</>unfreeze
(
recursive
)
— Unfreeze the diot object</>update
(
*value
,**kwargs
)
— Update the object. Shortcut:|=
</>update_recursively
(
*value
,**kwargs
)
— Update the object. Shortcut:|=
</>
from_namespace
(
namespace
, recursive=True
, diot_nest=True
, diot_transform='safe'
, diot_frozen=False
)
Get a Diot object from an argparse namespace
~~~python
from argparse import Namespace Diot.from_namespace(Namespace(a=1, b=2)) ~~~
namespace
(Namespace) — The namespace objectrecursive
(bool, optional) — Do it recursively?diot_nest
(Union(bool, iterable of type), optional) — Types to nestly convert valuesdiot_transform
(Union(callable(str: str), str), optional) — The transforms for keysdiot_frozen
(bool or str, optional) — Whether to generate a frozen diot.- - True: freeze the object recursively if there are Diot objects
- - False: Don'f freeze
- -
shallow
: Only freeze at depth = 1
diot_missing
— How to deal with missing keys when accessing them- - An exception class or object to raise
- -
None
to returnNone
- - A custom function with first argument the key and second
the diot object.
The converted diot object.
__setitem__
(
name
, value
)
Set self[key] to value.
__getitem__
(
name
)
→ any
x.getitem(y) <==> x[y]
pop
(
name
, *value
)
Pop a key from the object and return the value. If key does notexist, return the given default value
name
(str) — The key
The value corresponding to the name or the default value
DiotFrozenError
— when try to pop from a frozen diot
popitem
(
)
Pop last item from the object
A tuple of key and value
DiotFrozenError
— when try to pop from a frozen diot
update
(
*value
, **kwargs
)
Update the object. Shortcut: |=
DiotFrozenError
— when try to update a frozen diot
update_recursively
(
*value
, **kwargs
)
Update the object. Shortcut: |=
DiotFrozenError
— when try to update a frozen diot
__delitem__
(
name
)
Delete self[key].
freeze
(
frozen='shallow'
)
Freeze the diot object
frozen
(str or bool, optional) — The frozen argument indicating how to freeze:shallow: only freeze at depth=1 True: freeze recursively if there are diot objects in children False: Disable freezing
unfreeze
(
recursive=False
)
Unfreeze the diot object
recursive
(bool, optional) — Whether unfreeze all diot objects recursively
thaw
(
recursive=False
)
A context manager for temporarily change the diot
recursive
(bool, optional) — Whether unfreeze all diot objects recursively
self, the reference to this diot.
setdefault
(
name
, value
)
Set a default value to a key
name
(str) — The key namevalue
(any) — The default value
The existing value or the value passed in
DiotFrozenError
— when try to set default to a frozen diot
accessible_keys
(
)
Get the converted keys
The accessible (transformed) keys
get
(
name
, value=None
)
Get the value of a key name
name
(str) — The key namevalue
(any, optional) — The value to return if the key does not exist
The corresponding value or the value passed in if the key doesnot exist
__contains__
(
name
)
→ bool
True if the dictionary has the specified key, else False.
clear
(
)
Clear the object
to_dict
(
)
Turn the Box and sub Boxes back into a nativepython dictionary.
The converted python dictionary
to_json
(
filename=None
, encoding='utf-8'
, errors='strict'
, **json_kwargs
)
Convert to a json string or save it to json file
filename
(str, PathLike, or NoneType, optional) — The filename to save the json to, if not given a jsonstring will be returnedencoding
(str, optional) — The encoding for saving to fileerrors
(str, optional) — The errors handling for saveing to fileSee python's open function**json_kwargs
— Other kwargs for json.dumps
The json string with filename is not given
to_yaml
(
filename=None
, default_flow_style=False
, encoding='utf-8'
, errors='strict'
, **yaml_kwargs
)
Convert to a yaml string or save it to yaml file
filename
(str, PathLike, or NoneType, optional) — The filename to save the yaml to, if not given a yamlstring will be returneddefault_flow_style
(bool, optional) — The default flow style for yaml dumpingSeeyaml.dump
encoding
(str, optional) — The encoding for saving to fileerrors
(str, optional) — The errors handling for saveing to fileSee python's open function**yaml_kwargs
— Other kwargs foryaml.dump
The yaml string with filename is not given
to_toml
(
filename=None
, encoding='utf-8'
, errors='strict'
)
Convert to a toml string or save it to toml file
filename
(str, PathLike, or NoneType, optional) — The filename to save the toml to, if not given a tomlstring will be returnedencoding
(str, optional) — The encoding for saving to fileerrors
(str, optional) — The errors handling for saveing to fileSee python's open function
The toml string with filename is not given
With snake case conversion
*args
— Anything that can be sent to dict construct**kwargs
— keyword argument that can be sent to dict constructSome diot configurations can also be passed, including: diot_nest: Types to nestly convert values diot_transform: The transforms for keys diot_frozen: Whether to generate a frozen diot. True: freeze the object recursively if there are Diot objects in descendants False: Don'f freeze 'shallow': Only freeze at depth = 1
__contains__
(
name
)
(bool) — True if the dictionary has the specified key, else False.</>__delitem__
(
name
)
— Delete self[key].</>__getitem__
(
name
)
(any) — x.getitem(y) <==> x[y]</>__ior__
(
other
)
(Diot) — Return self|=value.</>__or__
(
other
)
(Diot) — Return self|value.</>__setitem__
(
name
,value
)
— Set self[key] to value.</>accessible_keys
(
)
(iterable of str) — Get the converted keys</>clear
(
)
— Clear the object</>copy
(
)
(Diot) — Shallow copy the object</>freeze
(
frozen
)
— Freeze the diot object</>from_namespace
(
namespace
,recursive
,diot_nest
,diot_transform
,diot_frozen
)
(Diot) — Get a Diot object from an argparse namespace</>get
(
name
,value
)
(any) — Get the value of a key name</>pop
(
name
,*value
)
(any) — Pop a key from the object and return the value. If key does notexist, return the given default value </>popitem
(
)
(str, any) — Pop last item from the object</>setdefault
(
name
,value
)
(any) — Set a default value to a key</>thaw
(
recursive
)
— A context manager for temporarily change the diot</>to_dict
(
)
(dict(str: any)) — Turn the Box and sub Boxes back into a nativepython dictionary. </>to_json
(
filename
,encoding
,errors
,**json_kwargs
)
(str, optional) — Convert to a json string or save it to json file</>to_toml
(
filename
,encoding
,errors
)
(str, optional) — Convert to a toml string or save it to toml file</>to_yaml
(
filename
,default_flow_style
,encoding
,errors
,**yaml_kwargs
)
(str, optional) — Convert to a yaml string or save it to yaml file</>unfreeze
(
recursive
)
— Unfreeze the diot object</>update
(
*value
,**kwargs
)
— Update the object. Shortcut:|=
</>update_recursively
(
*value
,**kwargs
)
— Update the object. Shortcut:|=
</>
from_namespace
(
namespace
, recursive=True
, diot_nest=True
, diot_transform='safe'
, diot_frozen=False
)
Get a Diot object from an argparse namespace
~~~python
from argparse import Namespace Diot.from_namespace(Namespace(a=1, b=2)) ~~~
namespace
(Namespace) — The namespace objectrecursive
(bool, optional) — Do it recursively?diot_nest
(Union(bool, iterable of type), optional) — Types to nestly convert valuesdiot_transform
(Union(callable(str: str), str), optional) — The transforms for keysdiot_frozen
(bool or str, optional) — Whether to generate a frozen diot.- - True: freeze the object recursively if there are Diot objects
- - False: Don'f freeze
- -
shallow
: Only freeze at depth = 1
diot_missing
— How to deal with missing keys when accessing them- - An exception class or object to raise
- -
None
to returnNone
- - A custom function with first argument the key and second
the diot object.
The converted diot object.
__setitem__
(
name
, value
)
Set self[key] to value.
__getitem__
(
name
)
→ any
x.getitem(y) <==> x[y]
pop
(
name
, *value
)
Pop a key from the object and return the value. If key does notexist, return the given default value
name
(str) — The key
The value corresponding to the name or the default value
DiotFrozenError
— when try to pop from a frozen diot
popitem
(
)
Pop last item from the object
A tuple of key and value
DiotFrozenError
— when try to pop from a frozen diot
update
(
*value
, **kwargs
)
Update the object. Shortcut: |=
DiotFrozenError
— when try to update a frozen diot
update_recursively
(
*value
, **kwargs
)
Update the object. Shortcut: |=
DiotFrozenError
— when try to update a frozen diot
__delitem__
(
name
)
Delete self[key].
freeze
(
frozen='shallow'
)
Freeze the diot object
frozen
(str or bool, optional) — The frozen argument indicating how to freeze:shallow: only freeze at depth=1 True: freeze recursively if there are diot objects in children False: Disable freezing
unfreeze
(
recursive=False
)
Unfreeze the diot object
recursive
(bool, optional) — Whether unfreeze all diot objects recursively
thaw
(
recursive=False
)
A context manager for temporarily change the diot
recursive
(bool, optional) — Whether unfreeze all diot objects recursively
self, the reference to this diot.
setdefault
(
name
, value
)
Set a default value to a key
name
(str) — The key namevalue
(any) — The default value
The existing value or the value passed in
DiotFrozenError
— when try to set default to a frozen diot
accessible_keys
(
)
Get the converted keys
The accessible (transformed) keys
get
(
name
, value=None
)
Get the value of a key name
name
(str) — The key namevalue
(any, optional) — The value to return if the key does not exist
The corresponding value or the value passed in if the key doesnot exist
__contains__
(
name
)
→ bool
True if the dictionary has the specified key, else False.
clear
(
)
Clear the object
to_dict
(
)
Turn the Box and sub Boxes back into a nativepython dictionary.
The converted python dictionary
to_json
(
filename=None
, encoding='utf-8'
, errors='strict'
, **json_kwargs
)
Convert to a json string or save it to json file
filename
(str, PathLike, or NoneType, optional) — The filename to save the json to, if not given a jsonstring will be returnedencoding
(str, optional) — The encoding for saving to fileerrors
(str, optional) — The errors handling for saveing to fileSee python's open function**json_kwargs
— Other kwargs for json.dumps
The json string with filename is not given
to_yaml
(
filename=None
, default_flow_style=False
, encoding='utf-8'
, errors='strict'
, **yaml_kwargs
)
Convert to a yaml string or save it to yaml file
filename
(str, PathLike, or NoneType, optional) — The filename to save the yaml to, if not given a yamlstring will be returneddefault_flow_style
(bool, optional) — The default flow style for yaml dumpingSeeyaml.dump
encoding
(str, optional) — The encoding for saving to fileerrors
(str, optional) — The errors handling for saveing to fileSee python's open function**yaml_kwargs
— Other kwargs foryaml.dump
The yaml string with filename is not given
to_toml
(
filename=None
, encoding='utf-8'
, errors='strict'
)
Convert to a toml string or save it to toml file
filename
(str, PathLike, or NoneType, optional) — The filename to save the toml to, if not given a tomlstring will be returnedencoding
(str, optional) — The encoding for saving to fileerrors
(str, optional) — The errors handling for saveing to fileSee python's open function
The toml string with filename is not given
The frozen diot
*args
— Anything that can be sent to dict construct**kwargs
— keyword argument that can be sent to dict constructSome diot configurations can also be passed, including: diot_nest: Types to nestly convert values diot_transform: The transforms for keys diot_frozen: Whether to generate a frozen diot. True: freeze the object recursively if there are Diot objects in descendants False: Don'f freeze 'shallow': Only freeze at depth = 1
__contains__
(
name
)
(bool) — True if the dictionary has the specified key, else False.</>__delitem__
(
name
)
— Delete self[key].</>__getitem__
(
name
)
(any) — x.getitem(y) <==> x[y]</>__ior__
(
other
)
(Diot) — Return self|=value.</>__or__
(
other
)
(Diot) — Return self|value.</>__setitem__
(
name
,value
)
— Set self[key] to value.</>accessible_keys
(
)
(iterable of str) — Get the converted keys</>clear
(
)
— Clear the object</>copy
(
)
(Diot) — Shallow copy the object</>freeze
(
frozen
)
— Freeze the diot object</>from_namespace
(
namespace
,recursive
,diot_nest
,diot_transform
,diot_frozen
)
(Diot) — Get a Diot object from an argparse namespace</>get
(
name
,value
)
(any) — Get the value of a key name</>pop
(
name
,*value
)
(any) — Pop a key from the object and return the value. If key does notexist, return the given default value </>popitem
(
)
(str, any) — Pop last item from the object</>setdefault
(
name
,value
)
(any) — Set a default value to a key</>thaw
(
recursive
)
— A context manager for temporarily change the diot</>to_dict
(
)
(dict(str: any)) — Turn the Box and sub Boxes back into a nativepython dictionary. </>to_json
(
filename
,encoding
,errors
,**json_kwargs
)
(str, optional) — Convert to a json string or save it to json file</>to_toml
(
filename
,encoding
,errors
)
(str, optional) — Convert to a toml string or save it to toml file</>to_yaml
(
filename
,default_flow_style
,encoding
,errors
,**yaml_kwargs
)
(str, optional) — Convert to a yaml string or save it to yaml file</>unfreeze
(
recursive
)
— Unfreeze the diot object</>update
(
*value
,**kwargs
)
— Update the object. Shortcut:|=
</>update_recursively
(
*value
,**kwargs
)
— Update the object. Shortcut:|=
</>
from_namespace
(
namespace
, recursive=True
, diot_nest=True
, diot_transform='safe'
, diot_frozen=False
)
Get a Diot object from an argparse namespace
~~~python
from argparse import Namespace Diot.from_namespace(Namespace(a=1, b=2)) ~~~
namespace
(Namespace) — The namespace objectrecursive
(bool, optional) — Do it recursively?diot_nest
(Union(bool, iterable of type), optional) — Types to nestly convert valuesdiot_transform
(Union(callable(str: str), str), optional) — The transforms for keysdiot_frozen
(bool or str, optional) — Whether to generate a frozen diot.- - True: freeze the object recursively if there are Diot objects
- - False: Don'f freeze
- -
shallow
: Only freeze at depth = 1
diot_missing
— How to deal with missing keys when accessing them- - An exception class or object to raise
- -
None
to returnNone
- - A custom function with first argument the key and second
the diot object.
The converted diot object.
__setitem__
(
name
, value
)
Set self[key] to value.
__getitem__
(
name
)
→ any
x.getitem(y) <==> x[y]
pop
(
name
, *value
)
Pop a key from the object and return the value. If key does notexist, return the given default value
name
(str) — The key
The value corresponding to the name or the default value
DiotFrozenError
— when try to pop from a frozen diot
popitem
(
)
Pop last item from the object
A tuple of key and value
DiotFrozenError
— when try to pop from a frozen diot
update
(
*value
, **kwargs
)
Update the object. Shortcut: |=
DiotFrozenError
— when try to update a frozen diot
update_recursively
(
*value
, **kwargs
)
Update the object. Shortcut: |=
DiotFrozenError
— when try to update a frozen diot
__delitem__
(
name
)
Delete self[key].
freeze
(
frozen='shallow'
)
Freeze the diot object
frozen
(str or bool, optional) — The frozen argument indicating how to freeze:shallow: only freeze at depth=1 True: freeze recursively if there are diot objects in children False: Disable freezing
unfreeze
(
recursive=False
)
Unfreeze the diot object
recursive
(bool, optional) — Whether unfreeze all diot objects recursively
thaw
(
recursive=False
)
A context manager for temporarily change the diot
recursive
(bool, optional) — Whether unfreeze all diot objects recursively
self, the reference to this diot.
setdefault
(
name
, value
)
Set a default value to a key
name
(str) — The key namevalue
(any) — The default value
The existing value or the value passed in
DiotFrozenError
— when try to set default to a frozen diot
accessible_keys
(
)
Get the converted keys
The accessible (transformed) keys
get
(
name
, value=None
)
Get the value of a key name
name
(str) — The key namevalue
(any, optional) — The value to return if the key does not exist
The corresponding value or the value passed in if the key doesnot exist
__contains__
(
name
)
→ bool
True if the dictionary has the specified key, else False.
clear
(
)
Clear the object
to_dict
(
)
Turn the Box and sub Boxes back into a nativepython dictionary.
The converted python dictionary
to_json
(
filename=None
, encoding='utf-8'
, errors='strict'
, **json_kwargs
)
Convert to a json string or save it to json file
filename
(str, PathLike, or NoneType, optional) — The filename to save the json to, if not given a jsonstring will be returnedencoding
(str, optional) — The encoding for saving to fileerrors
(str, optional) — The errors handling for saveing to fileSee python's open function**json_kwargs
— Other kwargs for json.dumps
The json string with filename is not given
to_yaml
(
filename=None
, default_flow_style=False
, encoding='utf-8'
, errors='strict'
, **yaml_kwargs
)
Convert to a yaml string or save it to yaml file
filename
(str, PathLike, or NoneType, optional) — The filename to save the yaml to, if not given a yamlstring will be returneddefault_flow_style
(bool, optional) — The default flow style for yaml dumpingSeeyaml.dump
encoding
(str, optional) — The encoding for saving to fileerrors
(str, optional) — The errors handling for saveing to fileSee python's open function**yaml_kwargs
— Other kwargs foryaml.dump
The yaml string with filename is not given
to_toml
(
filename=None
, encoding='utf-8'
, errors='strict'
)
Convert to a toml string or save it to toml file
filename
(str, PathLike, or NoneType, optional) — The filename to save the toml to, if not given a tomlstring will be returnedencoding
(str, optional) — The encoding for saving to fileerrors
(str, optional) — The errors handling for saveing to fileSee python's open function
The toml string with filename is not given
With key order preserved
*args
— Anything that can be sent to dict construct**kwargs
— keyword argument that can be sent to dict constructSome diot configurations can also be passed, including: diot_nest: Types to nestly convert values diot_transform: The transforms for keys diot_frozen: Whether to generate a frozen diot. True: freeze the object recursively if there are Diot objects in descendants False: Don'f freeze 'shallow': Only freeze at depth = 1
__contains__
(
name
)
(bool) — True if the dictionary has the specified key, else False.</>__delitem__
(
name
)
— Delete self[key].</>__getitem__
(
name
)
(any) — x.getitem(y) <==> x[y]</>__ior__
(
other
)
(Diot) — Return self|=value.</>__iter__
(
)
— Implement iter(self).</>__or__
(
other
)
(Diot) — Return self|value.</>__reversed__
(
)
— Return a reverse iterator over the dict keys.</>__setitem__
(
name
,value
)
— Set self[key] to value.</>accessible_keys
(
)
(iterable of str) — Get the converted keys</>clear
(
)
— Clear the object</>copy
(
)
(Diot) — Shallow copy the object</>copy
(
)
(OrderedDiot) — Shallow copy the object</>freeze
(
frozen
)
— Freeze the diot object</>from_namespace
(
namespace
,recursive
,diot_nest
,diot_transform
,diot_frozen
)
(Diot) — Get a Diot object from an argparse namespace</>get
(
name
,value
)
(any) — Get the value of a key name</>insert
(
position
,name
,value
)
— Insert an item to certain position</>insert_after
(
existing_key
,name
,value
)
— Insert items after the specified key</>insert_before
(
existing_key
,name
,value
)
— Insert items before the specified key</>items
(
)
(iterator of (str, any)) — Get the items in the order of the keys</>keys
(
)
— Get the keys in the order they are added</>pop
(
name
,*value
)
(any) — Pop a key from the object and return the value. If key does notexist, return the given default value </>popitem
(
)
(str, any) — Pop last item from the object</>setdefault
(
name
,value
)
(any) — Set a default value to a key</>thaw
(
recursive
)
— A context manager for temporarily change the diot</>to_dict
(
)
(dict(str: any)) — Turn the Box and sub Boxes back into a nativepython dictionary. </>to_json
(
filename
,encoding
,errors
,**json_kwargs
)
(str, optional) — Convert to a json string or save it to json file</>to_toml
(
filename
,encoding
,errors
)
(str, optional) — Convert to a toml string or save it to toml file</>to_yaml
(
filename
,default_flow_style
,encoding
,errors
,**yaml_kwargs
)
(str, optional) — Convert to a yaml string or save it to yaml file</>unfreeze
(
recursive
)
— Unfreeze the diot object</>update
(
*value
,**kwargs
)
— Update the object. Shortcut:|=
</>update_recursively
(
*value
,**kwargs
)
— Update the object. Shortcut:|=
</>values
(
)
— Get the values in the order they are added</>
from_namespace
(
namespace
, recursive=True
, diot_nest=True
, diot_transform='safe'
, diot_frozen=False
)
Get a Diot object from an argparse namespace
~~~python
from argparse import Namespace Diot.from_namespace(Namespace(a=1, b=2)) ~~~
namespace
(Namespace) — The namespace objectrecursive
(bool, optional) — Do it recursively?diot_nest
(Union(bool, iterable of type), optional) — Types to nestly convert valuesdiot_transform
(Union(callable(str: str), str), optional) — The transforms for keysdiot_frozen
(bool or str, optional) — Whether to generate a frozen diot.- - True: freeze the object recursively if there are Diot objects
- - False: Don'f freeze
- -
shallow
: Only freeze at depth = 1
diot_missing
— How to deal with missing keys when accessing them- - An exception class or object to raise
- -
None
to returnNone
- - A custom function with first argument the key and second
the diot object.
The converted diot object.
__getitem__
(
name
)
→ any
x.getitem(y) <==> x[y]
popitem
(
)
Pop last item from the object
A tuple of key and value
DiotFrozenError
— when try to pop from a frozen diot
update
(
*value
, **kwargs
)
Update the object. Shortcut: |=
DiotFrozenError
— when try to update a frozen diot
update_recursively
(
*value
, **kwargs
)
Update the object. Shortcut: |=
DiotFrozenError
— when try to update a frozen diot
freeze
(
frozen='shallow'
)
Freeze the diot object
frozen
(str or bool, optional) — The frozen argument indicating how to freeze:shallow: only freeze at depth=1 True: freeze recursively if there are diot objects in children False: Disable freezing
unfreeze
(
recursive=False
)
Unfreeze the diot object
recursive
(bool, optional) — Whether unfreeze all diot objects recursively
thaw
(
recursive=False
)
A context manager for temporarily change the diot
recursive
(bool, optional) — Whether unfreeze all diot objects recursively
self, the reference to this diot.
setdefault
(
name
, value
)
Set a default value to a key
name
(str) — The key namevalue
(any) — The default value
The existing value or the value passed in
DiotFrozenError
— when try to set default to a frozen diot
accessible_keys
(
)
Get the converted keys
The accessible (transformed) keys
get
(
name
, value=None
)
Get the value of a key name
name
(str) — The key namevalue
(any, optional) — The value to return if the key does not exist
The corresponding value or the value passed in if the key doesnot exist
__contains__
(
name
)
→ bool
True if the dictionary has the specified key, else False.
to_dict
(
)
Turn the Box and sub Boxes back into a nativepython dictionary.
The converted python dictionary
to_json
(
filename=None
, encoding='utf-8'
, errors='strict'
, **json_kwargs
)
Convert to a json string or save it to json file
filename
(str, PathLike, or NoneType, optional) — The filename to save the json to, if not given a jsonstring will be returnedencoding
(str, optional) — The encoding for saving to fileerrors
(str, optional) — The errors handling for saveing to fileSee python's open function**json_kwargs
— Other kwargs for json.dumps
The json string with filename is not given
to_yaml
(
filename=None
, default_flow_style=False
, encoding='utf-8'
, errors='strict'
, **yaml_kwargs
)
Convert to a yaml string or save it to yaml file
filename
(str, PathLike, or NoneType, optional) — The filename to save the yaml to, if not given a yamlstring will be returneddefault_flow_style
(bool, optional) — The default flow style for yaml dumpingSeeyaml.dump
encoding
(str, optional) — The encoding for saving to fileerrors
(str, optional) — The errors handling for saveing to fileSee python's open function**yaml_kwargs
— Other kwargs foryaml.dump
The yaml string with filename is not given
to_toml
(
filename=None
, encoding='utf-8'
, errors='strict'
)
Convert to a toml string or save it to toml file
filename
(str, PathLike, or NoneType, optional) — The filename to save the toml to, if not given a tomlstring will be returnedencoding
(str, optional) — The encoding for saving to fileerrors
(str, optional) — The errors handling for saveing to fileSee python's open function
The toml string with filename is not given
__setitem__
(
name
, value
)
Set self[key] to value.
items
(
)
Get the items in the order of the keys
The items (key-value) of the object
insert
(
position
, name
, value=None
)
Insert an item to certain position
position
(int) — The position where the name-value pair to be insertedname
(Union(str, (str, any))) — The key name to be insertedIt could also be a tuple of key-value pair. In such a case, value is ignored. It could be an ordered dictionary as wellvalue
(any, optional) — The value to be inserted
ValueError
— when try to pass a value if name is key-value pair ora dictonary.ValueError
— when name is a tuple but not with 2 elements
insert_before
(
existing_key
, name
, value=None
)
Insert items before the specified key
existing_key
(str) — The key where the new elements to be inserted beforename
(str) — The key name to be insertedvalue
(any, optional) — The value to be insertedSame as name and value arguments forinsert
KeyError
— when existing key does not existKeyError
— when name is an existing key
insert_after
(
existing_key
, name
, value=None
)
Insert items after the specified key
existing_key
(str) — The key where the new elements to be inserted aftername
(str) — The key name to be insertedvalue
(any, optional) — The value to be insertedSame as name and value arguments forinsert
KeyError
— when existing key does not existKeyError
— when name is an existing key
keys
(
)
Get the keys in the order they are added
The keys (untransformed)
__iter__
(
)
Implement iter(self).
values
(
)
Get the values in the order they are added
The values of the object
__delitem__
(
name
)
Delete self[key].
pop
(
name
, *value
)
Pop a key from the object and return the value. If key does notexist, return the given default value
name
(str) — The key
The value corresponding to the name or the default value
DiotFrozenError
— when try to pop from a frozen diot
__reversed__
(
)
Return a reverse iterator over the dict keys.
clear
(
)
Clear the object
copy
(
)
Shallow copy the object
The copied object