State & Config
biopro_sdk.plugin.state
Plugin state management for BioPro SDK.
Provides base class for plugin state that integrates with BioPro's undo/redo history system. Enables serialization and deserialization of plugin states for workflow persistence.
PluginState
dataclass
Bases: ABC
Base state class for plugin analysis state.
Subclass this in your plugin and use @dataclass for automatic serialization. Enables undo/redo integration via BioPro's HistoryManager.
All fields in your state should be simple types (str, int, float, list, dict) to ensure proper serialization. Complex objects should be stored as paths or serializable representations.
This class strictly prevents dynamic attribute assignment. All attributes must be declared as fields in the subclass dataclass.
Source code in src/biopro_sdk/plugin/state.py
from_dict(data)
classmethod
Reconstruct state from dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
Dictionary previously produced by to_dict() |
required |
Returns:
| Type | Description |
|---|---|
PluginState
|
New instance of this state class |
Source code in src/biopro_sdk/plugin/state.py
to_dict()
Convert state to dictionary for serialization.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary representation of the state |
biopro_sdk.plugin.io
File I/O utilities for BioPro SDK.
Provides convenient wrappers for JSON serialization and configuration management for plugins.
PluginConfig
Bases: PreferenceManagerProtocol
Simple configuration management for plugins.
Stores settings in JSON in ~/.biopro/plugin_configs/{plugin_id}.json
This is useful for persisting user settings across sessions, like the last used parameters or paths.
Example
config = PluginConfig('my_plugin') config.set('threshold', 0.5) config.set('last_image_dir', '/path/to/images') threshold = config.get('threshold', default=0.0) config.save()
Source code in src/biopro_sdk/plugin/io.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
__getitem__(key)
__init__(plugin_id)
Initialize config manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plugin_id
|
str
|
Unique plugin identifier (used for filename) |
required |
Source code in src/biopro_sdk/plugin/io.py
__setitem__(key, value)
clear()
get(key, default=None)
Get a configuration value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Configuration key |
required |
default
|
Any
|
Value to return if key doesn't exist |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Configuration value or default |
Source code in src/biopro_sdk/plugin/io.py
has(key)
Check if a key exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Configuration key |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if key exists |
load()
Load config from disk.
Called automatically in init. Call again to reload from disk.
Source code in src/biopro_sdk/plugin/io.py
save()
Save config to disk.
Raises:
| Type | Description |
|---|---|
IOError
|
If file cannot be written |
Source code in src/biopro_sdk/plugin/io.py
set(key, value)
Set a configuration value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Configuration key |
required |
value
|
Any
|
Configuration value (should be JSON-serializable) |
required |
get_plugin_logger(plugin_id)
Get a logger for a plugin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plugin_id
|
str
|
Plugin identifier |
required |
Returns:
| Type | Description |
|---|---|
Logger
|
Configured logger with plugin name prefixed to 'biopro.plugins' |
Example
logger = get_plugin_logger("my_plugin") logger.info("Plugin initialized") # Logs to "biopro.plugins.my_plugin"
Source code in src/biopro_sdk/plugin/io.py
load_json(path)
Load JSON from file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
File path |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Parsed JSON dictionary |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If file doesn't exist |
JSONDecodeError
|
If JSON is invalid |
Source code in src/biopro_sdk/plugin/io.py
read_binary(path)
save_json(path, data, pretty=True)
Save JSON to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
File path |
required |
data
|
dict[str, Any]
|
Dictionary to save |
required |
pretty
|
bool
|
If True, indent for readability (2 spaces) |
True
|
Source code in src/biopro_sdk/plugin/io.py
biopro_sdk.plugin.preferences
Preference Manager Interface for BioPro SDK.
PreferenceManagerProtocol
Bases: Protocol
Standardized interface for preference management.
This interface ensures that both the Core application and SDK plugins have a unified way to interact with preferences, adhering to the Dependency Inversion Principle (DIP).