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: dict

Dictionary 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: dict

Dictionary 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: dict

Dictionary 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.

_close()[source]

Set _closed to True to prevent auto-creation.

_open()[source]

Set _closed to False to enable auto-creation.

class backtrader.utils.autodict.AutoOrderedDict[source]

Bases: OrderedDict

OrderedDict 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.

_close()[source]

Set _closed to True to prevent auto-creation.

_open()[source]

Set _closed to False to enable auto-creation.

Example

>>> d = AutoOrderedDict()
>>> d['a']['b'] = 1  # Automatically creates nested dicts
>>> d._close()  # Prevent further auto-creation
lvalues()[source]

Return dictionary values as a list.

Provides Python 2/3 compatible list of values.

Returns:

List of all values in the dictionary.

Return type:

list