config module¶
Utilities for configuration.
ext_settings_paths_config HybridConfig¶
Config for (currently active) extensional settings paths.
Stores tuples of class names and their settings paths by unique ids.
spec_settings_paths_config HybridConfig¶
Config for (currently active) specialized settings paths.
Stores settings path dictionaries by unique ids. In a path dictionary, each key is a path that points to one or more other paths. For instance, a relationship "knowledge" -> "pages" will also consider "pages" settings whenever "knowledge" settings are requested.
unsetkey literal¶
When passed as a value, the corresponding key will be unset.
It can still be overridden by another dict.
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.
flat_merge_dicts function¶
Merge dicts with default arguments and nested=False.
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.
reorder_dict function¶
Reorder a dict based on a list of keys.
The keys list can include all keys, or a subset of keys with a single Ellipsis (...) representing all other keys.
reorder_list function¶
Reorder a list based on a list of integer indices.
The keys list can include all indices, or a subset of indices with a single Ellipsis (...) representing all other indices. When skip_missing is True, missing indices are ignored.
resolve_dict function¶
Select keyword arguments.
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
- Base
- Comparable
- Config
- Pickleable
- Prettified
- atomic_dict
builtins.dict- pdict
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- 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
- Prettified.pprint
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. override_keys:setofstr- Keys to override if
as_attrsis 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
- Base
- Comparable
- Pickleable
- Prettified
builtins.dict- pdict
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- 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
- Prettified.pprint
- 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_ class 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
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- Cacheable.get_ca_setup
- Chainable.chain
- 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.pprint
- Prettified.prettify
Subclasses
- ArrayWrapper
- AssetCacheManager
- BaseIDXAccessor
- BasePreparer
- Chunker
- Completions
- ContentFormatter
- DataUpdater
- DocumentRanker
- Embeddings
- ExecutionEngine
- Executor
- FormatHTML
- Grouper
- IndicatorFactory
- Jitter
- KnowledgeAsset
- ObjectStore
- PFPrepResult
- Parameterizer
- QSAdapter
- Resampler
- TVClient
- TelegramBot
- TextSplitter
- ToHTML
- ToMarkdown
- Tokenizer
- TraceType
- Wrapping
config class 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.
ExtSettingsPath class¶
Context manager to add extensional settings paths.
Superclasses
Inherited members
ext_settings_paths class property¶
Dictionary with extensional settings paths.
unique_id class property¶
Unique id.
FrozenConfig class¶
Config with frozen_keys flag set to True.
Superclasses
- Base
- Comparable
- Config
- Pickleable
- Prettified
builtins.dict- pdict
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- 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
- Prettified.pprint
HasSettings class¶
Class that has settings in vectorbtpro._settings.
Superclasses
Inherited members
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,
merge=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,
default=_Missing.MISSING,
path_id=None,
inherit=True,
sub_path=None,
sub_path_only=False,
merge=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¶
HasSettings.resolve_settings_paths(
path_id=None,
inherit=True,
super_first=True,
unique_only=True
)
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
- Base
- Comparable
- Config
- Pickleable
- Prettified
builtins.dict- pdict
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- 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
- Prettified.pprint
MetaConfigured class¶
Metaclass for Configured.
Superclasses
builtins.type
Subclasses
ReadonlyConfig class¶
Config with readonly flag set to True.
Superclasses
- Base
- Comparable
- Config
- Pickleable
- Prettified
builtins.dict- pdict
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- 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
- Prettified.pprint
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
SpecSettingsPath class¶
Context manager to add specialized settings paths.
Superclasses
Inherited members
spec_settings_paths class property¶
Dictionary with specialized settings paths.
unique_id class property¶
Unique id.
atomic_dict class¶
Dict that behaves like a single value when merging.
Superclasses
- Base
- Comparable
- Pickleable
- Prettified
builtins.dict- pdict
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- 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
- Prettified.pprint
- pdict.equals
- pdict.load_update
- pdict.prettify
- pdict.rec_state
Subclasses
child_dict class¶
Subclass of dict acting as a child dict.
Superclasses
- Base
- Comparable
- Pickleable
- Prettified
builtins.dict- pdict
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- 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
- Prettified.pprint
- pdict.equals
- pdict.load_update
- pdict.prettify
- pdict.rec_state
hdict class¶
Hashable dict.
Superclasses
- Base
builtins.dict
Inherited members