config module¶
Utilities for configuration.
unsetkey _unsetkey¶
When passed as a value, the corresponding key will be unset.
It can still be overridden by another dict.
combine_pathlike_keys function¶
Combine two path-like keys.
convert_to_dict function¶
Convert any config to dict.
Set nested to True to convert all child dicts in recursive manner.
If a config is an instance of AtomicConfig, will convert it to atomic_dict.
copy_dict function¶
Copy dict based on a copy mode.
The following modes are supported:
- 'none': Does not copy
- 'shallow': Copies keys only
- 'hybrid': Copies keys and values using
copy.copy - 'deep': Copies the whole thing using
copy.deepcopy
Set nested to True to copy all child dicts in recursive manner.
del_dict_item function¶
Delete dict item.
If the dict is of the type Config, also passes force keyword to override blocking flags.
get_dict_item function¶
Get dict item under the key k.
The key can be nested using the dot notation, pathlib.Path, or a tuple, and must be hashable.
merge_dicts function¶
Merge dicts.
Args
*dicts:dict- Dicts.
to_dict:bool- Whether to call convert_to_dict() on each dict prior to copying.
copy_mode:str- Mode for copy_dict() to copy each dict prior to merging.
nested:bool-
Whether to merge all child dicts in recursive manner.
If None, checks whether any dict is nested.
same_keys:bool- Whether to merge on the overlapping keys only.
resolve_dict function¶
Select keyword arguments.
resolve_pathlike_key function¶
Convert a path-like key into a tuple.
set_dict_item function¶
Set dict item.
If the dict is of the type Config, also passes force keyword to override blocking flags.
unset_keys function¶
Unset the keys that have the value unsetkey.
update_dict function¶
Update dict with keys and values from other dict.
Set nested to True to update all child dicts in recursive manner.
For force, see set_dict_item().
If you want to treat any dict as a single value, wrap it with atomic_dict.
If nested is True, a value in x is an instance of Configured, and the corresponding value in y is a dictionary, calls Configured.replace().
Note
If the child dict is not atomic, it will copy only its values, not its meta.
AtomicConfig class¶
Config that behaves like a single value when merging.
Superclasses
- Comparable
- Config
- Pickleable
- Prettified
- atomic_dict
builtins.dict- pdict
Inherited members
- Config.clear()
- Config.copy()
- Config.equals()
- Config.get_option()
- Config.load_update()
- Config.make_checkpoint()
- Config.merge_with()
- Config.options_
- Config.pop()
- Config.popitem()
- Config.prettify()
- Config.rec_state
- Config.reset()
- Config.set_option()
- Config.to_dict()
- Config.update()
- Pickleable.decode_config()
- Pickleable.decode_config_node()
- Pickleable.dumps()
- Pickleable.encode_config()
- Pickleable.encode_config_node()
- Pickleable.file_exists()
- Pickleable.getsize()
- Pickleable.load()
- Pickleable.loads()
- Pickleable.modify_state()
- Pickleable.resolve_file_path()
- Pickleable.save()
Config class¶
Extends pickleable dict with config features such as nested updates, freezing, and resetting.
Args
*args- Arguments to construct the dict from.
options_:dict- Config options (see below).
**kwargs- Keyword arguments to construct the dict from.
Options can have the following keys:
Attributes
copy_kwargs:dict-
Keyword arguments passed to copy_dict() for copying main dict and
reset_dct.Copy mode defaults to 'none'.
reset_dct:dict-
Dict to fall back to in case of resetting.
Defaults to None. If None, copies main dict using
reset_dct_copy_kwargs.Note
Defaults to main dict in case it's None and
readonlyis True. reset_dct_copy_kwargs:dict-
Keyword arguments that override
copy_kwargsforreset_dct.Copy mode defaults to 'none' if
readonlyis True, else to 'hybrid'. pickle_reset_dct:bool- Whether to pickle
reset_dct. frozen_keys:bool-
Whether to deny updates to the keys of the config.
Defaults to False.
readonly:bool-
Whether to deny updates to the keys and values of the config.
Defaults to False.
nested:bool-
Whether to do operations recursively on each child dict.
Such operations include copy, update, and merge. Disable to treat each child dict as a single value. Defaults to True.
convert_children:boolortype-
Whether to convert child dicts of type child_dict to configs with the same configuration.
This will trigger a waterfall reaction across all child dicts. Won't convert dicts that are already configs. Apart from boolean, you can set it to any subclass of Config to use it for construction. Requires
nestedto be True. Defaults to False. as_attrs:bool-
Whether to enable accessing dict keys via the dot notation.
Enables autocompletion (but only during runtime!). Raises error in case of naming conflicts. Defaults to True if
frozen_keysorreadonly, otherwise False.To make nested dictionaries also accessible via the dot notation, wrap them with child_dict and set
convert_childrenandnestedto True.
Defaults can be overridden with settings under config.
If another config is passed, its properties are copied over, but they can still be overridden with the arguments passed to the initializer.
Note
All arguments are applied only once during initialization.
Superclasses
- Comparable
- Pickleable
- Prettified
builtins.dict- pdict
Inherited members
- Pickleable.decode_config()
- Pickleable.decode_config_node()
- Pickleable.dumps()
- Pickleable.encode_config()
- Pickleable.encode_config_node()
- Pickleable.file_exists()
- Pickleable.getsize()
- Pickleable.load()
- Pickleable.loads()
- Pickleable.modify_state()
- Pickleable.resolve_file_path()
- Pickleable.save()
- pdict.equals()
- pdict.load_update()
- pdict.prettify()
- pdict.rec_state
Subclasses
clear method¶
Remove all items.
copy method¶
Copy the instance.
By default, copies in the same way as during the initialization.
get_option method¶
Get an option.
make_checkpoint method¶
Replace reset_dct by the current state.
reset_dct_copy_kwargs override reset_dct_copy_kwargs.
merge_with method¶
Merge with another dict into one single dict.
See merge_dicts().
options_ property¶
Config options.
pop method¶
Remove and return the pair by the key.
popitem method¶
Remove and return some pair.
reset method¶
Clears the config and updates it with the initial config.
reset_dct_copy_kwargs override reset_dct_copy_kwargs.
set_option method¶
Set an option.
to_dict method¶
Convert to dict.
update method¶
Update the config.
See update_dict().
Configured class¶
Class with an initialization config.
All subclasses of Configured are initialized using Config, which makes it easier to pickle.
Settings are defined under configured.
Warning
If any attribute has been overwritten that isn't listed in Configured._writeable_attrs, or if any Configured argument depends upon global defaults, their values won't be copied over. Make sure to pass them explicitly to make that the saved & loaded / copied instance is resilient to any changes in globals.
Superclasses
Inherited members
- Cacheable.get_ca_setup()
- Chainable.pipe()
- HasSettings.get_path_setting()
- HasSettings.get_path_settings()
- HasSettings.get_setting()
- HasSettings.get_settings()
- HasSettings.has_path_setting()
- HasSettings.has_path_settings()
- HasSettings.has_setting()
- HasSettings.has_settings()
- HasSettings.reset_settings()
- HasSettings.resolve_setting()
- HasSettings.resolve_settings_paths()
- HasSettings.set_settings()
- Pickleable.decode_config()
- Pickleable.decode_config_node()
- Pickleable.dumps()
- Pickleable.encode_config()
- Pickleable.encode_config_node()
- Pickleable.file_exists()
- Pickleable.getsize()
- Pickleable.load()
- Pickleable.loads()
- Pickleable.modify_state()
- Pickleable.rec_state
- Pickleable.resolve_file_path()
- Pickleable.save()
- Prettified.prettify()
Subclasses
- ArrayWrapper
- Bar
- BaseIDXAccessor
- BasePreparer
- Box
- Chunker
- DataUpdater
- ExecutionEngine
- Executor
- Gauge
- Grouper
- Heatmap
- Histogram
- IndicatorFactory
- Jitter
- PFPrepResult
- Parameterizer
- QSAdapter
- Resampler
- Scatter
- TVClient
- TelegramBot
- Volume
- Wrapping
config property¶
Initialization config.
copy method¶
Create a new instance by copying the config.
See Configured.replace().
equals method¶
Check two objects for equality.
get_writeable_attrs class method¶
Get set of attributes that are writeable by this class or by any of its base classes.
replace method¶
Configured.replace(
copy_mode_=None,
nested_=None,
cls_=None,
copy_writeable_attrs_=None,
**new_config
)
Create a new instance by copying and (optionally) changing the config.
Warning
This operation won't return a copy of the instance but a new instance initialized with the same config and writeable attributes (or their copy, depending on copy_mode).
resolve_merge_kwargs class method¶
Resolve keyword arguments for initializing Configured after merging.
update_config method¶
Force-update the config.
FrozenConfig class¶
Config with frozen_keys flag set to True.
Superclasses
- Comparable
- Config
- Pickleable
- Prettified
builtins.dict- pdict
Inherited members
- Config.clear()
- Config.copy()
- Config.equals()
- Config.get_option()
- Config.load_update()
- Config.make_checkpoint()
- Config.merge_with()
- Config.options_
- Config.pop()
- Config.popitem()
- Config.prettify()
- Config.rec_state
- Config.reset()
- Config.set_option()
- Config.to_dict()
- Config.update()
- Pickleable.decode_config()
- Pickleable.decode_config_node()
- Pickleable.dumps()
- Pickleable.encode_config()
- Pickleable.encode_config_node()
- Pickleable.file_exists()
- Pickleable.getsize()
- Pickleable.load()
- Pickleable.loads()
- Pickleable.modify_state()
- Pickleable.resolve_file_path()
- Pickleable.save()
HasSettings class¶
Class that has settings in vectorbtpro._settings.
Subclasses
get_path_setting class method¶
HasSettings.get_path_setting(
path,
key,
default=_Missing.MISSING,
sub_path=None,
sub_path_only=False
)
Get a value from the settings under a path.
get_path_settings class method¶
Get the settings under a path.
get_setting class method¶
HasSettings.get_setting(
key,
default=_Missing.MISSING,
path_id=None,
inherit=True,
sub_path=None,
sub_path_only=False
)
Get a value under the settings associated with this class and its superclasses (if inherit is True).
get_settings class method¶
Get the settings associated with this class and its superclasses (if inherit is True).
has_path_setting class method¶
Return whether the setting under a path exists.
has_path_settings class method¶
Return whether the settings under a path exist.
has_setting class method¶
Return whether the settings associated with this class and its superclasses (if inherit is True) exists.
has_settings class method¶
Return whether there the settings associated with this class and its superclasses (if inherit is True) exist.
reset_settings class method¶
Reset the settings in vectorbtpro._settings associated with this class.
resolve_setting class method¶
HasSettings.resolve_setting(
value,
key,
merge=False,
default=_Missing.MISSING,
path_id=None,
inherit=True,
sub_path=None,
sub_path_only=False
)
Resolve a value that has a key under the settings in vectorbtpro._settings associated with this class.
If the provided value is None, returns the setting, otherwise the value. If the value is a dict and merge is True, merges it over the corresponding dict in the settings.
If sub_path is provided, appends it to the resolved path and gives it more priority. If only the sub_path should be considered, set sub_path_only to True.
resolve_settings_paths class method¶
Resolve the settings paths associated with this class and its superclasses (if inherit is True).
set_settings class method¶
Set the settings in vectorbtpro._settings associated with this class.
If the settings do not exist yet, pass populate_=True.
HybridConfig class¶
Config with copy_kwargs set to copy_mode='hybrid'.
Superclasses
- Comparable
- Config
- Pickleable
- Prettified
builtins.dict- pdict
Inherited members
- Config.clear()
- Config.copy()
- Config.equals()
- Config.get_option()
- Config.load_update()
- Config.make_checkpoint()
- Config.merge_with()
- Config.options_
- Config.pop()
- Config.popitem()
- Config.prettify()
- Config.rec_state
- Config.reset()
- Config.set_option()
- Config.to_dict()
- Config.update()
- Pickleable.decode_config()
- Pickleable.decode_config_node()
- Pickleable.dumps()
- Pickleable.encode_config()
- Pickleable.encode_config_node()
- Pickleable.file_exists()
- Pickleable.getsize()
- Pickleable.load()
- Pickleable.loads()
- Pickleable.modify_state()
- Pickleable.resolve_file_path()
- Pickleable.save()
ReadonlyConfig class¶
Config with readonly flag set to True.
Superclasses
- Comparable
- Config
- Pickleable
- Prettified
builtins.dict- pdict
Inherited members
- Config.clear()
- Config.copy()
- Config.equals()
- Config.get_option()
- Config.load_update()
- Config.make_checkpoint()
- Config.merge_with()
- Config.options_
- Config.pop()
- Config.popitem()
- Config.prettify()
- Config.rec_state
- Config.reset()
- Config.set_option()
- Config.to_dict()
- Config.update()
- Pickleable.decode_config()
- Pickleable.decode_config_node()
- Pickleable.dumps()
- Pickleable.encode_config()
- Pickleable.encode_config_node()
- Pickleable.file_exists()
- Pickleable.getsize()
- Pickleable.load()
- Pickleable.loads()
- Pickleable.modify_state()
- Pickleable.resolve_file_path()
- Pickleable.save()
SettingNotFoundError class¶
Gets raised if a setting could not be found.
Superclasses
builtins.BaseExceptionbuiltins.Exceptionbuiltins.KeyErrorbuiltins.LookupError
SettingsNotFoundError class¶
Gets raised if settings could not be found.
Superclasses
builtins.BaseExceptionbuiltins.Exceptionbuiltins.KeyErrorbuiltins.LookupError
atomic_dict class¶
Dict that behaves like a single value when merging.
Superclasses
- Comparable
- Pickleable
- Prettified
builtins.dict- pdict
Inherited members
- Pickleable.decode_config()
- Pickleable.decode_config_node()
- Pickleable.dumps()
- Pickleable.encode_config()
- Pickleable.encode_config_node()
- Pickleable.file_exists()
- Pickleable.getsize()
- Pickleable.load()
- Pickleable.loads()
- Pickleable.modify_state()
- Pickleable.resolve_file_path()
- Pickleable.save()
- pdict.equals()
- pdict.load_update()
- pdict.prettify()
- pdict.rec_state
Subclasses
child_dict class¶
Subclass of dict acting as a child dict.
Superclasses
- Comparable
- Pickleable
- Prettified
builtins.dict- pdict
Inherited members
- Pickleable.decode_config()
- Pickleable.decode_config_node()
- Pickleable.dumps()
- Pickleable.encode_config()
- Pickleable.encode_config_node()
- Pickleable.file_exists()
- Pickleable.getsize()
- Pickleable.load()
- Pickleable.loads()
- Pickleable.modify_state()
- Pickleable.resolve_file_path()
- Pickleable.save()
- pdict.equals()
- pdict.load_update()
- pdict.prettify()
- pdict.rec_state
hdict class¶
Hashable dict.
Superclasses
builtins.dict