Core Concepts¶
Understanding the fundamental concepts behind Pyvider RPC Plugin will help you build more effective and secure plugin systems.
๐ค AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
Overview¶
Pyvider RPC Plugin enables process-based plugin architectures where plugins run as separate processes and communicate via RPC (Remote Procedure Call). This approach provides isolation, security, and language flexibility while maintaining high performance.
Plugin vs Host Application¶
- ๐ Host Application (Client): The main application that launches, manages, and communicates with plugins. Uses
RPCPluginClientto initiate connections. - ๐ Plugin Process (Server): An external executable that provides specific services. Uses
RPCPluginServerto serve RPC requests. - ๐ก RPC Communication: gRPC-based communication allows the host to call plugin functions as if they were local.
Core Classes¶
| Class | Role | Description |
|---|---|---|
RPCPluginClient |
Host Application | Manages plugin lifecycle and RPC communication |
RPCPluginServer |
Plugin Process | Serves RPC requests from the host |
RPCPluginProtocol |
Both | Defines the RPC interface and service methods |
Handler/Servicer |
Plugin Process | Implements the actual business logic |
Essential Concepts¶
๐ค RPC Architecture & Handshake¶
The plugin system implements a robust RPC architecture built on gRPC with a secure handshake protocol:
- gRPC Foundation - Protocol Buffers for efficient serialization, HTTP/2 for multiplexed communication
- Handshake Process - Multi-phase negotiation including magic cookie authentication, protocol negotiation, and service discovery
- Foundation Integration - Seamless integration with provide.foundation for logging, configuration, and cryptography
Learn more: RPC Architecture & Handshake
๐ Transport Layer¶
Communication happens over different transport mechanisms:
- Best for: Local IPC, high performance, security
- Platforms: Linux, macOS
- Performance: ~45,000 msg/sec, ~0.02ms latency
- Best for: Network communication, Windows compatibility
- Platforms: Linux, macOS, Windows
- Performance: ~35,000 msg/sec (localhost)
Learn more: Transports
๐ Protocol Definition¶
RPCPluginProtocol defines the interface between host and plugin using Protocol Buffers:
class MyProtocol(RPCPluginProtocol):
async def get_grpc_descriptors(self):
"""Return Protocol Buffer descriptors and service name"""
return my_pb2.DESCRIPTOR, "MyService"
async def add_to_server(self, server, handler):
"""Add your service implementation to the gRPC server"""
my_pb2_grpc.add_MyServiceServicer_to_server(handler, server)
Learn more: Protocols
๐ Security Model¶
Multi-layered security approach:
- Process Isolation - Memory isolation, resource limits, crash resilience
- Magic Cookie Authentication - Shared secret passed via environment variable
- Mutual TLS (mTLS) - Certificate-based authentication and encrypted communication
Learn more: Security Model
Configuration Architecture¶
Pyvider RPC Plugin uses provide.foundation for configuration:
from pyvider.rpcplugin.config import rpcplugin_config
# Access configuration
timeout = rpcplugin_config.plugin_handshake_timeout
transports = rpcplugin_config.plugin_server_transports
mtls_enabled = rpcplugin_config.plugin_auto_mtls
Configuration sources (in priority order):
- Environment variables (highest priority)
- Configuration files (YAML, JSON, TOML)
- Programmatic settings
- Default values (lowest priority)
Error Handling¶
Structured exception hierarchy provides predictable error handling:
from pyvider.rpcplugin.exception import (
RPCPluginError, # Base exception
TransportError, # Network/transport issues
HandshakeError, # Handshake failures
SecurityError, # Authentication/authorization
ConfigError, # Configuration problems
)
Async/Await Integration¶
All APIs are async-first for maximum performance:
# Server
async def main():
server = plugin_server(protocol=MyProtocol(), handler=MyHandler())
await server.serve()
# Client
async def main():
async with plugin_client() as client:
result = await client.call_method("my_method", param="value")
What's Next?¶
Dive deeper into specific concepts:
-
RPC Architecture & Handshake
Complete RPC architecture with secure handshake protocol
-
Transports
Understanding Unix sockets vs TCP and when to use each
-
Protocols
How to define and implement RPC protocols with gRPC
-
Security Model
Comprehensive security including mTLS, magic cookies, and isolation
Or jump to practical implementation:
- Server Development - Build your first plugin server
- Client Development - Connect to and manage plugins