PythonBridge
PythonBridge
Connects a live DataManager instance to the embedded Python interpreter. More…
#include <PythonBridge.hpp>
Public Functions
| Name | |
|---|---|
| PythonBridge(std::shared_ptr< DataManager > dm, PythonEngine & engine) Construct a bridge between a DataManager and a PythonEngine. |
|
| ~PythonBridge() =default | |
| PythonBridge(PythonBridge const & ) =delete | |
| PythonBridge & | operator=(PythonBridge const & ) =delete |
| PythonBridge(PythonBridge && ) =delete | |
| PythonBridge & | operator=(PythonBridge && ) =delete |
| void | exposeDataManager() Inject the DataManager into Python namespace as dm. |
| bool | exposeData(std::string const & key, std::string const & python_name) Inject a single data object by key into the Python namespace. |
| bool | exposeTimeFrame(std::string const & time_key, std::string const & python_name) Expose a TimeFrame by its TimeKey under python_name. |
| std::vector< std::string > | importNewData(std::string const & default_time_key =“time”) Scan Python namespace for new data objects and register them. |
| PythonResult | execute(std::string const & code) Execute Python code with the DataManager already exposed. |
| PythonResult | executeFile(std::filesystem::path const & path) Execute a .py file with the DataManager already exposed. |
| bool | isDataManagerExposed() const Check whether the DataManager is currently exposed in the Python namespace. |
| std::shared_ptr< DataManager > const & | dataManager() const Get the underlying DataManager. |
| PythonEngine & | engine() Get the underlying PythonEngine. |
| PythonEngine const & | engine() const |
Detailed Description
class PythonBridge;Connects a live DataManager instance to the embedded Python interpreter.
Typical lifecycle:
auto dm = std::make_shared<DataManager>();
PythonEngine engine;
PythonBridge bridge(dm, engine);
bridge.exposeDataManager(); // dm available as `dm` in Python
engine.execute("print(dm.getAllKeys())");
// After user script adds data via dm.setData():
auto new_keys = bridge.importNewData();Public Functions Documentation
function PythonBridge
explicit PythonBridge(
std::shared_ptr< DataManager > dm,
PythonEngine & engine
)Construct a bridge between a DataManager and a PythonEngine.
Parameters:
- dm Shared pointer to the live DataManager.
- engine Reference to the (already-initialized) PythonEngine.
function ~PythonBridge
~PythonBridge() =defaultfunction PythonBridge
PythonBridge(
PythonBridge const &
) =deletefunction operator=
PythonBridge & operator=(
PythonBridge const &
) =deletefunction PythonBridge
PythonBridge(
PythonBridge &&
) =deletefunction operator=
PythonBridge & operator=(
PythonBridge &&
) =deletefunction exposeDataManager
void exposeDataManager()Inject the DataManager into Python namespace as dm.
Also auto-imports the whiskertoolbox_python module as [wt](/api_generated/Namespaces/namespacewt.md) for convenient access to type constructors (e.g. wt.AnalogTimeSeries).
Safe to call multiple times — re-injects the same shared_ptr.
function exposeData
bool exposeData(
std::string const & key,
std::string const & python_name
)Inject a single data object by key into the Python namespace.
Parameters:
- key The DataManager key for the data.
- python_name The name to use in the Python namespace.
Return: true if injection succeeded.
Retrieves the data from the DataManager via getDataVariant() and injects it under python_name. Returns false if the key does not exist or the type is not bound.
function exposeTimeFrame
bool exposeTimeFrame(
std::string const & time_key,
std::string const & python_name
)Expose a TimeFrame by its TimeKey under python_name.
Parameters:
Return: true if the TimeFrame exists and was injected.
function importNewData
std::vector< std::string > importNewData(
std::string const & default_time_key ="time"
)Scan Python namespace for new data objects and register them.
Parameters:
- default_time_key TimeKey to use for newly imported data (defaults to “time”).
Return: Names of newly registered data keys.
After script execution, this method inspects user-defined variables in the Python namespace. Any variable whose value is a bound WhiskerToolbox data type (AnalogTimeSeries, DigitalEventSeries, etc.) that is not already registered in the DataManager is added under the variable’s Python name, using the default time key.
Objects that are already in the DataManager (because the user called dm.setData() directly) are skipped — this method only catches “orphan” data objects.
function execute
PythonResult execute(
std::string const & code
)Execute Python code with the DataManager already exposed.
Parameters:
- code Python code string to execute.
Return: PythonResult with stdout/stderr capture.
Equivalent to calling [exposeDataManager()](/api_generated/Classes/classPythonBridge.md#function-exposedatamanager) then engine.execute(code). Guarantees that dm and [wt](/api_generated/Namespaces/namespacewt.md) are available in the namespace.
function executeFile
PythonResult executeFile(
std::filesystem::path const & path
)Execute a .py file with the DataManager already exposed.
Parameters:
- path Path to the .py file.
Return: PythonResult with stdout/stderr capture.
Equivalent to calling [exposeDataManager()](/api_generated/Classes/classPythonBridge.md#function-exposedatamanager) then engine.executeFile(path).
function isDataManagerExposed
bool isDataManagerExposed() constCheck whether the DataManager is currently exposed in the Python namespace.
function dataManager
std::shared_ptr< DataManager > const & dataManager() constGet the underlying DataManager.
function engine
PythonEngine & engine()Get the underlying PythonEngine.
function engine
PythonEngine const & engine() constUpdated on 2026-11-13 at 20:25:40 +0000