serialix.formats package#
Module contents#
Subpackage with implementation of main features for various serialization languages
Submodules#
serialix.formats.json module#
JSON
language support
- class serialix.formats.json.JSON_Format(file_path: str, default_dictionary: dict = {}, auto_file_creation: bool = True, force_overwrite_file: bool = False, parser_write_kwargs: dict = {}, parser_read_kwargs: dict = {})#
Bases:
BaseLang
JSON data serialization format implementation
- Parameters:
file_path – Path to preferred local file destination. If the file does not exist at the specified path, it will be created
default_dictionary – Default local file path
str
ordict
that will be used for local file start values, defaults to{}
(empty dict)auto_file_creation – Automatic local file creation on object initialization, defaults to True
force_overwrite_file – Whether the file needs to be overwritten if it already exists, defaults to False
parser_write_kwargs – Pass custom arguments to parser’s write to local file action, defaults to
{}
(empty dict)parser_read_kwargs – Pass custom arguments to parser’s read from local file action, defaults to
{}
(empty dict)
- Raises:
ValueError – If provided data type in argument
default_dictionary
can’t be represented as pathstr
ordict
Note
Methods
.clear()
,.fromkeys()
,.get()
,.items()
,.keys()
,values()
,pop()
,popitem()
,setdefault()
,update()
are bound to the attributedictionary
, so executing:>>> this_object.update({'check': True})
Is equal to:
>>> this_object.dictionary.update({'check': True})
- clear()#
Remove all keys from this object’s
dictionary
. No changes will be commited to local file without manual.commit()
call
- commit()#
Commit all changes from object to local file
- copy(deep_mode=True) dict #
Get the copy of this object keys and values. This method uses the recursive copy function by default that will remove all references to original dictionary.
- Parameters:
deep_mode – Use the recursive copy function to remove all references to original dictionary. Disabling this will lead to saving the references of the nested dictionaries to the copy object, defaults to True.
- Returns:
dictionary
copy
- create_file() bool #
Create new local file from default dictionary
- Returns:
Was the file created successfully
- delete_file() bool #
Delete local file
- Returns:
Was the file removed. False will be returned only if the local file does not exist at the time of deletion.
- property dictionary: dict#
Full access to the object’s dictionary attribute. Contains local file data parsed to dictionary
- Returns:
dictionary
attribute
- property dictionary_default: dict#
Full access to the object’s default dictionary. Contains dictionary with default keys that was specified in
default_dictionary
argument.- Returns:
default dictionary
- file_exists() bool #
Check local file existence
- Returns:
Does the file exist
- get(key, default=None) Any #
Get key from object’s
dictionary
- Parameters:
key – Key name
default – Default value, if key was not found, defaults to None
- Returns:
Value of requested
key
, ordefault
value if key wasn’t found.
- is_file_exist() bool #
Deprecated in
2.3.0
, use.file_exists()
method instead. This method will be removed in3.0.0
release.Check local file existence.
- Returns:
Does the file exist
- items() list #
Get items of the object’s
dictionary
- Returns:
Items of the
dictionary
((key, value) pairs)
- keys() list #
Get keys of the object’s
dictionary
- Returns:
Keys of the
dictionary
(, key)
- property parser_read_kwargs: dict#
Arguments that will be passed to parser on read from file action. This property can be modified. Note that only
dict
type is allowed.- Returns:
already specified arguments
- property parser_write_kwargs: dict#
Arguments that will be passed to parser on write to file action. This property can be modified. Note that only
dict
type is allowed.- Returns:
already specified arguments
- pop(key: str, default=None) Any #
Pop key from object’s
dictionary
- Parameters:
key – Key name
default – Default value, if key was not found, defaults to None
- Returns:
Value of requested
key
, ordefault
value if key wasn’t found, defaults to None.
- popitem() Any #
Pop item from object’s
dictionary
in LIFO order.- Parameters:
key – Key name
default – Default value, if key was not found, defaults to None
- Returns:
Value of requested
key
, ordefault
value if key wasn’t found, defaults to None.
- read_file_as_dict() dict #
Read local file bound to this object as dictionary
- Returns:
Parsed to dictionary local file
- refresh(safe_mode=True) bool #
Refresh object’s
dictionary
values from local file. Note that this method does not remove user-added keys, it will only add non existent keys and modify the already existing keys.- Parameters:
safe_mode – Provides the recursive merge of dictionary from local file to object’s
dictionary
. This option prevents object’s nested dictionaries to be overwritten by local files, but is much slower than simpledict.update()
method call. So if you don’t care about nested dictionaries be overwritten, you can disable this feature to boost the execution speed- Returns:
Status of local file read action. If file does not exist -
False
will be returned.
- reload() bool #
Reset all not commited changes made to object’s
dictionary
to values from local file- Returns:
Status of local file read action. If file does not exist -
False
will be returned.
- reset_to_defaults()#
Reset the object’s
dictionary
to values fromdictionary_default
attribute. Note that local file will stay untouched.
- setdefault(key: str, default=None) Any #
If key is in the object’s
dictionary
, return its value. If not, insert key with a value ofdefault
and returndefault
- Parameters:
key – Name of the key
default – Default value, defaults to None
- Returns:
If key is in the dictionary, return its value, else: returns
defalut
- update(dictionary: dict)#
Update object’s
dictionary
with another dictionary- Parameters:
dictionary – Dictionary, that will be merged to
dictionary
- values() list #
Get values of the object’s
dictionary
- Returns:
Values of the
dictionary
(, value)
- write_dict_to_file(dictionary: dict)#
Write dict from
dictionary
argument to local file bound to this object- Parameters:
dictionary – Dictionary that should be written to file
serialix.formats.yaml module#
YAML
language support
- class serialix.formats.yaml.YAML_Format(file_path: str, default_dictionary: dict = {}, auto_file_creation: bool = True, force_overwrite_file: bool = False, parser_write_kwargs: dict = {}, parser_read_kwargs: dict = {})#
Bases:
BaseLang
YAML data serialization format implementation
- Parameters:
file_path – Path to preferred local file destination. If the file does not exist at the specified path, it will be created
default_dictionary – Default local file path
str
ordict
that will be used for local file start values, defaults to{}
(empty dict)auto_file_creation – Automatic local file creation on object initialization, defaults to True
force_overwrite_file – Whether the file needs to be overwritten if it already exists, defaults to False
parser_write_kwargs – Pass custom arguments to parser’s write to local file action, defaults to
{}
(empty dict)parser_read_kwargs – Pass custom arguments to parser’s read from local file action, defaults to
{}
(empty dict)
- Raises:
ValueError – If provided data type in argument
default_dictionary
can’t be represented as pathstr
ordict
Note
Methods
.clear()
,.fromkeys()
,.get()
,.items()
,.keys()
,values()
,pop()
,popitem()
,setdefault()
,update()
are bound to the attributedictionary
, so executing:>>> this_object.update({'check': True})
Is equal to:
>>> this_object.dictionary.update({'check': True})
- clear()#
Remove all keys from this object’s
dictionary
. No changes will be commited to local file without manual.commit()
call
- commit()#
Commit all changes from object to local file
- copy(deep_mode=True) dict #
Get the copy of this object keys and values. This method uses the recursive copy function by default that will remove all references to original dictionary.
- Parameters:
deep_mode – Use the recursive copy function to remove all references to original dictionary. Disabling this will lead to saving the references of the nested dictionaries to the copy object, defaults to True.
- Returns:
dictionary
copy
- create_file() bool #
Create new local file from default dictionary
- Returns:
Was the file created successfully
- delete_file() bool #
Delete local file
- Returns:
Was the file removed. False will be returned only if the local file does not exist at the time of deletion.
- property dictionary: dict#
Full access to the object’s dictionary attribute. Contains local file data parsed to dictionary
- Returns:
dictionary
attribute
- property dictionary_default: dict#
Full access to the object’s default dictionary. Contains dictionary with default keys that was specified in
default_dictionary
argument.- Returns:
default dictionary
- file_exists() bool #
Check local file existence
- Returns:
Does the file exist
- get(key, default=None) Any #
Get key from object’s
dictionary
- Parameters:
key – Key name
default – Default value, if key was not found, defaults to None
- Returns:
Value of requested
key
, ordefault
value if key wasn’t found.
- is_file_exist() bool #
Deprecated in
2.3.0
, use.file_exists()
method instead. This method will be removed in3.0.0
release.Check local file existence.
- Returns:
Does the file exist
- items() list #
Get items of the object’s
dictionary
- Returns:
Items of the
dictionary
((key, value) pairs)
- keys() list #
Get keys of the object’s
dictionary
- Returns:
Keys of the
dictionary
(, key)
- property parser_read_kwargs: dict#
Arguments that will be passed to parser on read from file action. This property can be modified. Note that only
dict
type is allowed.- Returns:
already specified arguments
- property parser_write_kwargs: dict#
Arguments that will be passed to parser on write to file action. This property can be modified. Note that only
dict
type is allowed.- Returns:
already specified arguments
- pop(key: str, default=None) Any #
Pop key from object’s
dictionary
- Parameters:
key – Key name
default – Default value, if key was not found, defaults to None
- Returns:
Value of requested
key
, ordefault
value if key wasn’t found, defaults to None.
- popitem() Any #
Pop item from object’s
dictionary
in LIFO order.- Parameters:
key – Key name
default – Default value, if key was not found, defaults to None
- Returns:
Value of requested
key
, ordefault
value if key wasn’t found, defaults to None.
- read_file_as_dict() dict #
Read local file bound to this object as dictionary
- Returns:
Parsed to dictionary local file
- refresh(safe_mode=True) bool #
Refresh object’s
dictionary
values from local file. Note that this method does not remove user-added keys, it will only add non existent keys and modify the already existing keys.- Parameters:
safe_mode – Provides the recursive merge of dictionary from local file to object’s
dictionary
. This option prevents object’s nested dictionaries to be overwritten by local files, but is much slower than simpledict.update()
method call. So if you don’t care about nested dictionaries be overwritten, you can disable this feature to boost the execution speed- Returns:
Status of local file read action. If file does not exist -
False
will be returned.
- reload() bool #
Reset all not commited changes made to object’s
dictionary
to values from local file- Returns:
Status of local file read action. If file does not exist -
False
will be returned.
- reset_to_defaults()#
Reset the object’s
dictionary
to values fromdictionary_default
attribute. Note that local file will stay untouched.
- setdefault(key: str, default=None) Any #
If key is in the object’s
dictionary
, return its value. If not, insert key with a value ofdefault
and returndefault
- Parameters:
key – Name of the key
default – Default value, defaults to None
- Returns:
If key is in the dictionary, return its value, else: returns
defalut
- update(dictionary: dict)#
Update object’s
dictionary
with another dictionary- Parameters:
dictionary – Dictionary, that will be merged to
dictionary
- values() list #
Get values of the object’s
dictionary
- Returns:
Values of the
dictionary
(, value)
- write_dict_to_file(dictionary: dict)#
Write dict from
dictionary
argument to local file bound to this object- Parameters:
dictionary – Dictionary that should be written to file
serialix.formats.toml module#
TOML
language support
- class serialix.formats.toml.TOML_Format(file_path: str, default_dictionary: dict = {}, auto_file_creation: bool = True, force_overwrite_file: bool = False, parser_write_kwargs: dict = {}, parser_read_kwargs: dict = {})#
Bases:
BaseLang
TOML data serialization format implementation
- Parameters:
file_path – Path to preferred local file destination. If the file does not exist at the specified path, it will be created
default_dictionary – Default local file path
str
ordict
that will be used for local file start values, defaults to{}
(empty dict)auto_file_creation – Automatic local file creation on object initialization, defaults to True
force_overwrite_file – Whether the file needs to be overwritten if it already exists, defaults to False
parser_write_kwargs – Pass custom arguments to parser’s write to local file action, defaults to
{}
(empty dict)parser_read_kwargs – Pass custom arguments to parser’s read from local file action, defaults to
{}
(empty dict)
- Raises:
ValueError – If provided data type in argument
default_dictionary
can’t be represented as pathstr
ordict
Note
Methods
.clear()
,.fromkeys()
,.get()
,.items()
,.keys()
,values()
,pop()
,popitem()
,setdefault()
,update()
are bound to the attributedictionary
, so executing:>>> this_object.update({'check': True})
Is equal to:
>>> this_object.dictionary.update({'check': True})
- clear()#
Remove all keys from this object’s
dictionary
. No changes will be commited to local file without manual.commit()
call
- commit()#
Commit all changes from object to local file
- copy(deep_mode=True) dict #
Get the copy of this object keys and values. This method uses the recursive copy function by default that will remove all references to original dictionary.
- Parameters:
deep_mode – Use the recursive copy function to remove all references to original dictionary. Disabling this will lead to saving the references of the nested dictionaries to the copy object, defaults to True.
- Returns:
dictionary
copy
- create_file() bool #
Create new local file from default dictionary
- Returns:
Was the file created successfully
- delete_file() bool #
Delete local file
- Returns:
Was the file removed. False will be returned only if the local file does not exist at the time of deletion.
- property dictionary: dict#
Full access to the object’s dictionary attribute. Contains local file data parsed to dictionary
- Returns:
dictionary
attribute
- property dictionary_default: dict#
Full access to the object’s default dictionary. Contains dictionary with default keys that was specified in
default_dictionary
argument.- Returns:
default dictionary
- file_exists() bool #
Check local file existence
- Returns:
Does the file exist
- get(key, default=None) Any #
Get key from object’s
dictionary
- Parameters:
key – Key name
default – Default value, if key was not found, defaults to None
- Returns:
Value of requested
key
, ordefault
value if key wasn’t found.
- is_file_exist() bool #
Deprecated in
2.3.0
, use.file_exists()
method instead. This method will be removed in3.0.0
release.Check local file existence.
- Returns:
Does the file exist
- items() list #
Get items of the object’s
dictionary
- Returns:
Items of the
dictionary
((key, value) pairs)
- keys() list #
Get keys of the object’s
dictionary
- Returns:
Keys of the
dictionary
(, key)
- property parser_read_kwargs: dict#
Arguments that will be passed to parser on read from file action. This property can be modified. Note that only
dict
type is allowed.- Returns:
already specified arguments
- property parser_write_kwargs: dict#
Arguments that will be passed to parser on write to file action. This property can be modified. Note that only
dict
type is allowed.- Returns:
already specified arguments
- pop(key: str, default=None) Any #
Pop key from object’s
dictionary
- Parameters:
key – Key name
default – Default value, if key was not found, defaults to None
- Returns:
Value of requested
key
, ordefault
value if key wasn’t found, defaults to None.
- popitem() Any #
Pop item from object’s
dictionary
in LIFO order.- Parameters:
key – Key name
default – Default value, if key was not found, defaults to None
- Returns:
Value of requested
key
, ordefault
value if key wasn’t found, defaults to None.
- read_file_as_dict() dict #
Read local file bound to this object as dictionary
- Returns:
Parsed to dictionary local file
- refresh(safe_mode=True) bool #
Refresh object’s
dictionary
values from local file. Note that this method does not remove user-added keys, it will only add non existent keys and modify the already existing keys.- Parameters:
safe_mode – Provides the recursive merge of dictionary from local file to object’s
dictionary
. This option prevents object’s nested dictionaries to be overwritten by local files, but is much slower than simpledict.update()
method call. So if you don’t care about nested dictionaries be overwritten, you can disable this feature to boost the execution speed- Returns:
Status of local file read action. If file does not exist -
False
will be returned.
- reload() bool #
Reset all not commited changes made to object’s
dictionary
to values from local file- Returns:
Status of local file read action. If file does not exist -
False
will be returned.
- reset_to_defaults()#
Reset the object’s
dictionary
to values fromdictionary_default
attribute. Note that local file will stay untouched.
- setdefault(key: str, default=None) Any #
If key is in the object’s
dictionary
, return its value. If not, insert key with a value ofdefault
and returndefault
- Parameters:
key – Name of the key
default – Default value, defaults to None
- Returns:
If key is in the dictionary, return its value, else: returns
defalut
- update(dictionary: dict)#
Update object’s
dictionary
with another dictionary- Parameters:
dictionary – Dictionary, that will be merged to
dictionary
- values() list #
Get values of the object’s
dictionary
- Returns:
Values of the
dictionary
(, value)
- write_dict_to_file(dictionary: dict)#
Write dict from
dictionary
argument to local file bound to this object- Parameters:
dictionary – Dictionary that should be written to file