Skip to main content

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 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

Project details


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.1.tar.gz (36.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rustbridge-1.0.1-py3-none-any.whl (27.2 kB view details)

Uploaded Python 3

File details

Details for the file rustbridge-1.0.1.tar.gz.

File metadata

  • Download URL: rustbridge-1.0.1.tar.gz
  • Upload date:
  • Size: 36.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for rustbridge-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6b974efa25fbe9e1371656a77dc177653b7f02b94f93c2644363057a7890b8af
MD5 a9bd5fe1af93d34b603f82e66566fdd9
BLAKE2b-256 5046b19b216921ce452bb193090c382942372e1c03835959cae8970ce25f71e9

See more details on using hashes here.

File details

Details for the file rustbridge-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: rustbridge-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 27.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for rustbridge-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 10164b1972d734f302296f3db0a3cd8ba51665a1d744a308f5d771a2bd66cee0
MD5 c10a95c6bd671f5810f6d9ef9f8f62fc
BLAKE2b-256 ec24c488fbeda324fc362be1ad20dd0a473c17b10d229950f8fd90abe39116b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page