backtrader.mixins package

Backtrader mixins module.

This module provides mixin classes that can be used to add functionality to other classes without using metaclasses. These mixins are part of the effort to remove metaprogramming from backtrader while maintaining backward compatibility.

class backtrader.mixins.SingletonMixin[source]

Bases: object

Mixin class to implement singleton pattern using __new__ method.

This replaces the MetaSingleton metaclass pattern, providing the same functionality without using metaclasses. Each class that inherits from this mixin will maintain exactly one instance per class.

Thread-safe implementation using threading.Lock.

Features: - Thread-safe singleton creation - Per-class singleton instances (subclasses get their own instances) - Automatic cleanup when instances are garbage collected - Maintains compatibility with existing parameter systems

static __new__(cls, *args, **kwargs)[source]

Create or return existing singleton instance for the class.

class backtrader.mixins.ParameterizedSingletonMixin[source]

Bases: SingletonMixin

Enhanced singleton mixin that integrates with parameter systems.

This version is specifically designed to work with backtrader’s parameter system, maintaining compatibility with MetaParams functionality.

__init__(*args, **kwargs)[source]

Initialize singleton instance only once.

backtrader.mixins.StoreBase

alias of ParameterizedSingletonMixin

Submodules