backtrader.utils.autodict module¶
AutoDict Module - Enhanced dictionary classes.
This module provides dictionary subclasses with automatic key creation, dot notation access, and ordered dict support.
- Classes:
AutoDict: Dict with automatic nested dict creation. AutoOrderedDict: OrderedDict with automatic nested dict creation. DotDict: Dict with attribute-style access (obj.key). AutoDictList: Dict with automatic list creation for missing keys.
Example
>>> d = AutoOrderedDict()
>>> d['a']['b']['c'] = 1 # Automatically creates nested dicts
>>> print(d['a']['b']['c'])
1
- backtrader.utils.autodict.Tree()[source]¶
Create a recursive defaultdict structure.
Returns a defaultdict that automatically creates nested defaultdicts for any missing key, allowing for infinite nesting.
- Returns:
A recursive defaultdict structure.
- Return type:
defaultdict
- class backtrader.utils.autodict.AutoDictList[source]¶
Bases:
dictDictionary that creates an empty list for missing keys.
When accessing a key that doesn’t exist, automatically creates a new empty list for that key.
Example
>>> d = AutoDictList() >>> d['key'].append('value') >>> print(d['key']) ['value']
- class backtrader.utils.autodict.DotDict[source]¶
Bases:
dictDictionary with attribute-style access.
Allows accessing dictionary values as attributes using dot notation. If an attribute is not found in the usual places, the dict itself is checked.
Example
>>> d = DotDict() >>> d['key'] = 'value' >>> print(d.key) 'value'
- class backtrader.utils.autodict.AutoDict[source]¶
Bases:
dictDictionary with automatic nested dict creation and closeable state.
Extends dict with: - Automatic nested dict creation for missing keys - Closeable state (_closed) to prevent further auto-creation - Attribute-style access
- _closed¶
If True, __missing__ raises KeyError instead of creating nested dicts.
- class backtrader.utils.autodict.AutoOrderedDict[source]¶
Bases:
OrderedDictOrderedDict with automatic nested dict creation and closeable state.
Combines OrderedDict’s insertion ordering with AutoDict’s automatic nested dict creation and closeable state.
- _closed¶
If True, __missing__ raises KeyError instead of creating nested dicts.
Example
>>> d = AutoOrderedDict() >>> d['a']['b'] = 1 # Automatically creates nested dicts >>> d._close() # Prevent further auto-creation