Python bindings for SLIM (Secure Low-Latency Interactive Messaging) using UniFFI
Project description
SLIM Python Bindings (UniFFI)
Python bindings for SLIM (Secure Low-Latency Interactive Messaging) using UniFFI.
This provides a Python interface to the SLIM data plane, enabling secure, low-latency messaging with support for point-to-point and group (multicast) communication patterns.
Overview
These Python bindings are generated from the agntcy-slim-bindings crate
using UniFFI, providing a native
Python interface that wraps the high-performance Rust implementation.
Key Features
- Point-to-Point Messaging: Direct communication between two endpoints
- Group Messaging: Multicast communication with multiple participants
- Secure by Default: Support for TLS, mTLS, and various authentication methods
- MLS Encryption: End-to-end encryption for sessions
- Delivery Confirmation: Optional completion handles for reliable messaging
- Flexible Authentication: Shared secrets, JWT, SPIRE integration
- slimrpc Support: Protocol Buffers RPC over SLIM - see SLIMRPC.md for details
Architecture
The Python bindings are built using Maturin, which automatically generates Python bindings from the Rust UniFFI adapter:
data-plane/bindings/
├── rust/ # Rust UniFFI bindings (shared by Go, Python, etc.)
│ ├── src/
│ │ ├── app.rs
│ │ ├── build_info.rs
│ │ ├── client_config.rs
│ │ ├── common_config.rs
│ │ ├── completion_handle.rs
│ │ ├── config.rs
│ │ ├── errors.rs
│ │ ├── identity.rs
│ │ ├── identity_config.rs
│ │ ├── init_config.rs
│ │ ├── lib.rs
│ │ ├── message_context.rs
│ │ ├── name.rs
│ │ ├── server_config.rs
│ │ ├── service.rs
│ │ └── session.rs
│ └── Cargo.toml
├── go/ # Go-specific bindings and examples
└── python/ # Python-specific bindings and examples (this directory)
├── examples/ # Example applications
├── tests/ # Unit and integration tests
└── Taskfile.yaml # Build and development tasks
Prerequisites
- Rust toolchain (1.70+)
- Python (3.10+)
- uv (Python package manager): https://docs.astral.sh/uv/
- Task (optional, for convenient build commands)
Installation
Development Build
cd data-plane/bindings/python
task python:bindings:build
This will:
- Install all dependencies
- Compile the Rust UniFFI adapter
- Generate Python bindings using Maturin
- Install the package in development mode
Creating Distribution Packages
Build Wheels for Multiple Python Versions
To create distributable wheel packages for Python 3.10, 3.11, 3.12, 3.13 and 3.14:
task python:bindings:packaging
Or directly with Maturin:
uv run maturin build --release -i 3.10 3.11 3.12 3.13
Maturin automatically:
- Compiles the Rust UniFFI adapter library
- Generates Python bindings from UniFFI scaffolding
- Bundles the native library into platform-specific wheels
- Creates wheels for each specified Python version
The resulting wheels are self-contained and ready for distribution.
Custom Build Options
You can customize the build with the following variables:
# Build for a specific target architecture
task python:bindings:packaging TARGET=aarch64-apple-darwin
# Build in debug mode (default is release)
task python:bindings:packaging PROFILE=debug
# Cross-compile for Linux on macOS
task python:bindings:packaging TARGET=x86_64-unknown-linux-gnu
Output Structure
After running the packaging task, you'll find:
dist/
├── slim_uniffi_bindings-0.7.0-cp310-*.whl # Python 3.10 wheel
├── slim_uniffi_bindings-0.7.0-cp311-*.whl # Python 3.11 wheel
├── slim_uniffi_bindings-0.7.0-cp312-*.whl # Python 3.12 wheel
└── slim_uniffi_bindings-0.7.0-cp313-*.whl # Python 3.13 wheel
Note: The native library is automatically bundled inside each wheel.
Installing from Wheel
Users can install the wheel package directly:
pip install slim_uniffi_bindings-0.7.0-cp310-*.whl
The native library is automatically included in the wheel and will be loaded at runtime.
Examples
Examples are a separate project in the examples/ directory.
See examples/README.md for detailed instructions.
Quick Start with Examples
cd examples
# View available examples
task
# Run simple example
task simple
# Run point-to-point examples
task p2p:alice # Terminal 1
task p2p:bob # Terminal 2
Quick Start
Simple Example
import slim_uniffi_bindings as slim
# Initialize crypto provider
slim.initialize_crypto_provider()
# Get version
print(f"SLIM Version: {slim.get_version()}")
# Create an app with shared secret authentication
app_name = {
'components': ['org', 'example', 'app'],
'id': None
}
app = slim.create_app_with_secret(app_name, "my-secret")
print(f"App ID: {app.id()}")
print(f"App Name: {'/'.join(app.name().components)}")
Run the simple example:
cd examples
task simple
Point-to-Point Communication
Terminal 1 - Receiver (Alice):
cd examples
task p2p:alice
Terminal 2 - Sender (Bob):
cd examples
task p2p:bob
Group Communication
Terminal 1 - Participant (Alice):
cd examples
task group:participant:alice
Terminal 2 - Participant (Bob):
cd examples
task group:participant:bob
Terminal 3 - Moderator:
cd examples
task group:moderator
For more details, see examples/README.md.
API Overview
Application Creation
# Create app with shared secret
app = slim.create_app_with_secret(app_name, shared_secret)
# Get app information
app_id = app.id()
app_name = app.name()
Server Operations
# Connect to server
client_config = {
'endpoint': 'http://localhost:46357',
'tls': {'insecure': True, ...}
}
conn_id = app.connect(client_config)
# Run server
server_config = {
'endpoint': '127.0.0.1:46357',
'tls': {'insecure': True, ...}
}
app.run_server(server_config)
# Disconnect
app.disconnect(conn_id)
Session Management
# Create session
session_config = {
'session_type': 'PointToPoint', # or 'Group'
'enable_mls': False,
'max_retries': 3,
'interval_ms': 100,
'initiator': True,
'metadata': {}
}
session = app.create_session(session_config, destination_name)
# Listen for incoming session
session = app.listen_for_session(timeout_ms=30000)
# Delete session
app.delete_session(session)
Messaging
# Send message (fire-and-forget)
session.publish(data, "text/plain", metadata)
# Send with delivery confirmation
completion = session.publish_with_completion(data, "text/plain", metadata)
completion.wait() # Block until delivered
# Receive message
msg = session.get_message(timeout_ms=5000)
print(f"Payload: {msg.payload}")
print(f"From: {msg.context.source_name}")
print(f"Type: {msg.context.payload_type}")
# Reply to message
session.publish_to(msg.context, reply_data, "text/plain", None)
Group Operations
# Invite participant to group
session.invite(participant_name)
# Remove participant
session.remove(participant_name)
Examples
Examples Directory Structure
examples/
├── common/
│ └── common.py # Shared utilities
├── simple/
│ └── main.py # Basic functionality demo
├── point_to_point/
│ └── main.py # P2P messaging
└── group/
└── main.py # Group/multicast messaging
Running Examples
All examples require a running SLIM server. Start the Go server:
cd data-plane/bindings/go
task example:server
Then run Python examples:
# Simple example
task example
# Point-to-point
task example:p2p:alice # Terminal 1
task example:p2p:bob # Terminal 2
# Group messaging
task example:group:participant:alice # Terminal 1
task example:group:participant:bob # Terminal 2
task example:group:moderator # Terminal 3
Testing
Unit Tests
task test
# or
python -m pytest tests/unit_test.py -v
Integration Tests
Integration tests require a running SLIM server:
# Terminal 1: Start server
cd ../go && task example:server
# Terminal 2: Run integration tests
SLIM_INTEGRATION_TEST=1 python -m pytest tests/integration_test.py -v -s
Development
Available Tasks
task # Show help
task build # Build package with Maturin
task test # Run tests
task python:bindings:packaging # Build wheels for multiple Python versions
task clean # Clean build artifacts
Project Structure
slim_uniffi_bindings/- Python package (bindings generated by Maturin)examples/- Example applicationstests/- Unit and integration testsTaskfile.yaml- Build automationpyproject.toml- Package configuration (Maturin build system)
Comparison with Go Bindings
Both Python and Go bindings use the same UniFFI adapter, ensuring API consistency:
| Feature | Python | Go |
|---|---|---|
| Binding Generation | uniffi-bindgen | uniffi-bindgen-go |
| API Style | Pythonic (snake_case) | Idiomatic Go (PascalCase) |
| Error Handling | Exceptions | Error returns |
| Async Support | Sync wrapper over async Rust | Sync wrapper over async Rust |
| Examples | ✅ | ✅ |
| Tests | ✅ | ✅ |
API Reference
Core Types
Name: Application/service identifier with components and optional IDSessionConfig: Configuration for creating sessionsTlsConfig: TLS settings for secure connectionsServerConfig: Server endpoint and TLS configurationClientConfig: Client endpoint and TLS configurationMessageContext: Message metadata (source, destination, type, metadata)ReceivedMessage: Received message with context and payload
Main Classes
BindingsAdapter: Main app interface for session managementBindingsSessionContext: Session interface for messagingFfiCompletionHandle: Completion handle for delivery confirmation
Session Types
PointToPoint: Direct one-to-one communicationGroup: One-to-many multicast communication
Troubleshooting
ImportError: Cannot find slim_uniffi_bindings
Make sure you've built the package:
task build
# or
uv run maturin develop
Connection Refused
Ensure the SLIM server is running:
cd ../go && task example:server
Build Errors
If you encounter build errors, try cleaning and rebuilding:
task clean
uv run maturin develop
Contributing
When contributing to the Python bindings:
- Maintain API consistency with Go bindings
- Follow Python naming conventions (snake_case)
- Add tests for new functionality
- Update examples if adding features
- Keep documentation up to date
License
Apache-2.0 - See LICENSE.md for details
See Also
- slimrpc Documentation - Protocol Buffers RPC over SLIM
- Go Bindings
- UniFFI Adapter
- SLIM Documentation
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 Distributions
Built Distributions
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 slim_bindings-1.1.0-py3-none-win_arm64.whl.
File metadata
- Download URL: slim_bindings-1.1.0-py3-none-win_arm64.whl
- Upload date:
- Size: 11.1 MB
- Tags: Python 3, Windows ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f11638fe0786729eb3fbb9bb0273029751b6fd1eae03e7370d70a913c8933972
|
|
| MD5 |
3ca0886ecde2fa543d582fb514969507
|
|
| BLAKE2b-256 |
d815c052f72407ee925163826548d22b09e4256f335e485d519f9a0167c0e217
|
File details
Details for the file slim_bindings-1.1.0-py3-none-win_amd64.whl.
File metadata
- Download URL: slim_bindings-1.1.0-py3-none-win_amd64.whl
- Upload date:
- Size: 11.9 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
102826053bf775bd4109fb771c1b5387bc142f315d0bdaba9d1de4dc8331686f
|
|
| MD5 |
45c2f38cc32f2a8d343570acf2c25520
|
|
| BLAKE2b-256 |
58eb95311273d7c019e3a4adae7fe2b0dab177482aa2c7c44c6632b09499d6a1
|
File details
Details for the file slim_bindings-1.1.0-py3-none-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: slim_bindings-1.1.0-py3-none-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 13.1 MB
- Tags: Python 3, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c5ab6b5fc950d5f3f9d0d0a0fe9cbafd698562c44cabfc1dc57ad43efc8998e
|
|
| MD5 |
1b458ca63e133d80603a0335004a0969
|
|
| BLAKE2b-256 |
93e6a10522130a200932898660435634f96ff7c5dc0dcb8355e08d123100f1c6
|
File details
Details for the file slim_bindings-1.1.0-py3-none-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: slim_bindings-1.1.0-py3-none-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 12.7 MB
- Tags: Python 3, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
315a045dce4b1e79022edb1de7519227aec913cbc3f4cdb6ccd32894d55114ea
|
|
| MD5 |
0e35cfc5f282064c2841ac3e3510c9d1
|
|
| BLAKE2b-256 |
34ccdde4efccd646f6e9dd1ce8bc95a51dd1eb5709318c36f7f62cce6b075535
|
File details
Details for the file slim_bindings-1.1.0-py3-none-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: slim_bindings-1.1.0-py3-none-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 13.1 MB
- Tags: Python 3, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe738b8fa80c2246638bd7d9136a3d401e72e5e9205ff21d01511bb2b501ecf2
|
|
| MD5 |
21d5f73ab681b16698311d5de591924a
|
|
| BLAKE2b-256 |
f9728cb61b9571867331f17463c9a7be3de519e0e6295f818ed6cf9657c5a56f
|
File details
Details for the file slim_bindings-1.1.0-py3-none-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: slim_bindings-1.1.0-py3-none-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 12.7 MB
- Tags: Python 3, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c061df67ae51cb5e8f225004123b0c64b66520df448c3939c3a7aaa31c1e89f
|
|
| MD5 |
3b75b1df83bed0436a93f8c59c0b1f84
|
|
| BLAKE2b-256 |
f34705d3e74634a1e330e1ad99ae3286b8e2fe99cc9bf6d22738ca8de40766d6
|
File details
Details for the file slim_bindings-1.1.0-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: slim_bindings-1.1.0-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 14.1 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c35b5b56d3d5f5b531f1017ef311434db293fc84e4c911627e70d1c06bd3adc
|
|
| MD5 |
5e7b787d1ec9d17e7fbd20100a6776a1
|
|
| BLAKE2b-256 |
3f465630127218e9f21eebb690690926e48d1f8aa8ade66a270fff25fdea790e
|
File details
Details for the file slim_bindings-1.1.0-py3-none-macosx_10_12_x86_64.whl.
File metadata
- Download URL: slim_bindings-1.1.0-py3-none-macosx_10_12_x86_64.whl
- Upload date:
- Size: 14.4 MB
- Tags: Python 3, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22466d4df1e757a1836b230db59d08f33e41972a6dd2bee18a8fb271003a0ee6
|
|
| MD5 |
319fa77c4418db7e3cfc9d81bb8c57e4
|
|
| BLAKE2b-256 |
063522a2bb66a3fb6913be17574c8f6dc12b2c276c7a6915a0b3370c78b27209
|