Python bindings for rustbridge - Rust shared libraries callable from Python
Project description
rustbridge-python
Python bindings for rustbridge - call Rust shared libraries from Python using ctypes.
Installation
pip install .
# Or for development
pip install -e ".[dev]"
Quick Start
Direct Library Loading
from rustbridge import NativePluginLoader, PluginConfig, LogLevel
# Simple loading
with NativePluginLoader.load("libmyplugin.so") as plugin:
response = plugin.call("echo", '{"message": "hello"}')
print(response)
# With configuration
config = PluginConfig.defaults().log_level(LogLevel.DEBUG)
with NativePluginLoader.load_with_config("libmyplugin.so", config) as plugin:
response = plugin.call("echo", '{"message": "hello"}')
Bundle Loading (with signature verification)
from rustbridge import BundleLoader, PluginConfig
# Load with signature verification (default)
loader = BundleLoader(verify_signatures=True)
with loader.load("my-plugin-1.0.0.rbp") as plugin:
response = plugin.call("echo", '{"message": "hello"}')
# Skip verification for development
loader = BundleLoader(verify_signatures=False)
with loader.load("my-plugin-1.0.0.rbp") as plugin:
...
With Log Callback
from rustbridge import NativePluginLoader, PluginConfig, LogLevel
def on_log(level: LogLevel, target: str, message: str):
print(f"[{level.name}] {target}: {message}")
config = PluginConfig.defaults().log_level(LogLevel.DEBUG)
with NativePluginLoader.load_with_config("libmyplugin.so", config, log_callback=on_log) as plugin:
response = plugin.call("echo", '{"message": "hello"}')
Configuration
from rustbridge import PluginConfig, LogLevel
config = (PluginConfig.defaults()
.log_level(LogLevel.DEBUG) # Set log level
.worker_threads(4) # Set worker threads
.max_concurrent_ops(500) # Max concurrent operations
.shutdown_timeout_ms(10000) # Shutdown timeout
.set("custom_key", "value") # Custom configuration
.init_param("db_url", "...")) # Initialization parameter
API Reference
Core Types
LogLevel- Log level enum (TRACE, DEBUG, INFO, WARN, ERROR, OFF)LifecycleState- Plugin lifecycle state (INSTALLED, STARTING, ACTIVE, STOPPING, STOPPED, FAILED)PluginConfig- Configuration builderPluginException- Exception with error codeResponseEnvelope- JSON response wrapper
Native Plugin
NativePluginLoader.load(path)- Load a pluginNativePluginLoader.load_with_config(path, config, callback)- Load with configurationplugin.call(type_tag, request)- Make a JSON callplugin.call_typed(type_tag, request)- Make a typed call (auto JSON serialization)plugin.state- Get lifecycle stateplugin.set_log_level(level)- Set log levelplugin.shutdown()- Shutdown the plugin
Bundle Loading
BundleLoader(verify_signatures=True)- Create a loaderloader.load(path)- Load plugin from bundleloader.load_with_config(path, config, callback)- Load with configurationloader.get_manifest(path)- Read bundle manifestBundleLoader.get_current_platform()- Get current platform string
Development
# Install development dependencies
pip install -e ".[dev]"
# Run tests
python -m pytest tests/ -v
# Run specific test
python -m pytest tests/test_log_level.py -v
# Build hello-plugin for integration tests
cargo build -p hello-plugin --release
Requirements
- Python 3.10+
- PyNaCl (for Ed25519 signature verification)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rustbridge-1.0.0.tar.gz
(35.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rustbridge-1.0.0.tar.gz.
File metadata
- Download URL: rustbridge-1.0.0.tar.gz
- Upload date:
- Size: 35.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0283b9b5990d3087e72f34badbee78f5c9abc040103a8290eb7cb8de48195595
|
|
| MD5 |
7bbea0ea08b8d900f631d0b330be1520
|
|
| BLAKE2b-256 |
244d6dfc3f9075506f33f906d5b0a5f0625162873d81b47fdd14d09aa17ef35d
|
File details
Details for the file rustbridge-1.0.0-py3-none-any.whl.
File metadata
- Download URL: rustbridge-1.0.0-py3-none-any.whl
- Upload date:
- Size: 26.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1564e1608c41b66a7d2d824e751763d0e3717b2d7bcf0a0a7ed47a1b9ec51769
|
|
| MD5 |
4f3d9365f09427f1a3fcf2a1e2692be5
|
|
| BLAKE2b-256 |
85b6328d9ae60af966980aca52d2f666f0bd8a2fa2fd959c4352cfff074e8025
|