Skip to main content

rustbridge-python

Python bindings for rustbridge - call Rust shared libraries from Python using ctypes.

Installation

pip install rustbridge

Development

To install from source 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 builder
  • PluginException - Exception with error code
  • ResponseEnvelope - JSON response wrapper

Native Plugin

  • NativePluginLoader.load(path) - Load a plugin
  • NativePluginLoader.load_with_config(path, config, callback) - Load with configuration
  • plugin.call(type_tag, request) - Make a JSON call
  • plugin.call_typed(type_tag, request) - Make a typed call (auto JSON serialization)
  • plugin.state - Get lifecycle state
  • plugin.set_log_level(level) - Set log level
  • plugin.shutdown() - Shutdown the plugin

Bundle Loading

  • BundleLoader(verify_signatures=True) - Create a loader
  • loader.load(path) - Load plugin from bundle
  • loader.load_with_config(path, config, callback) - Load with configuration
  • loader.get_manifest(path) - Read bundle manifest
  • BundleLoader.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

Metadata

Release files for rustbridge 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rustbridge 1.0.1
File Size Uploaded
rustbridge-1.0.1.tar.gz 36.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rustbridge 1.0.1
File Interpreter ABI Platform
rustbridge-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 63.3 kB

Release files / rustbridge-1.0.1.tar.gz

Download URL rustbridge-1.0.1.tar.gz
Size 36.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6b974efa25fbe9e1371656a77dc177653b7f02b94f93c2644363057a7890b8af
BLAKE2b-256 checksum
How to use checksums
5046b19b216921ce452bb193090c382942372e1c03835959cae8970ce25f71e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / rustbridge-1.0.1-py3-none-any.whl

Download URL rustbridge-1.0.1-py3-none-any.whl
Size 27.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
10164b1972d734f302296f3db0a3cd8ba51665a1d744a308f5d771a2bd66cee0
BLAKE2b-256 checksum
How to use checksums
ec24c488fbeda324fc362be1ad20dd0a473c17b10d229950f8fd90abe39116b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page