Index
pyvider.rpcplugin.transport.unix
¶
Unix Domain Socket Transport Package.
This package provides Unix domain socket transport implementation and utilities for the Pyvider RPC Plugin system.
Classes¶
UnixSocketTransport
¶
Bases: RPCPluginTransport
Unix domain socket transport for local IPC communication.
This transport provides high-performance local inter-process communication using Unix domain sockets. It's the preferred transport for plugin communication on Linux and macOS systems, offering better security and performance than TCP for local connections.
The implementation is compatible with HashiCorp's go-plugin protocol, handling: - Automatic socket path generation when path is None - Path normalization for unix:, unix:/, unix:// prefixes - Proper file permissions (0660) for cross-process access - Socket lifecycle management with cleanup on close - Stale socket detection and removal
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str | None
|
Unix socket file path. If None, generates temporary path. |
endpoint |
str | None
|
The normalized endpoint string (e.g., "unix:/tmp/plugin.sock") |
Example
# Server with auto-generated path
transport = UnixSocketTransport()
endpoint = await transport.listen() # Returns "unix:/tmp/pyvider-xxx.sock"
# Server with specific path
transport = UnixSocketTransport(path="/var/run/myplugin.sock")
endpoint = await transport.listen() # Returns "unix:/var/run/myplugin.sock"
# Client connection
transport = UnixSocketTransport()
await transport.connect("unix:/tmp/server.sock")
# Cleanup (removes socket file)
await transport.close()
Platform Notes
- Linux/macOS: Full support with optimal performance
- Windows: Not supported (use TCPSocketTransport instead)
- Docker: Ensure socket paths are in shared volumes for cross-container IPC
Security Notes
- Socket files are created with 0660 permissions (user/group read/write)
- Consider socket file location for security (avoid world-writable directories)
- Socket files are automatically removed on close()
Note
This transport is typically created automatically by factory functions (plugin_server, plugin_client) when transport="unix" is specified.
Functions¶
__attrs_post_init__
¶
Post-initialization hook for UnixSocketTransport.
If a socket path is not provided, it generates an ephemeral path. Otherwise, it normalizes the provided path. Initializes locks and events.
Source code in pyvider/rpcplugin/transport/unix/transport.py
close
async
¶
Closes the Unix socket transport.
This involves closing any active client connections, stopping the server, and removing the socket file from the filesystem. It is designed to be idempotent.
Source code in pyvider/rpcplugin/transport/unix/transport.py
connect
async
¶
Connect to a remote Unix socket with robust path handling.
This method: 1. Normalizes the endpoint path to handle various formats 2. Verifies the socket file exists (with retries) 3. Establishes the connection with timeout handling
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The Unix socket path to connect to, which can be in various formats: - Absolute path: "/tmp/socket.sock" - With prefix: "unix:/tmp/socket.sock" |
required |
Raises:
| Type | Description |
|---|---|
TransportError
|
If the socket file doesn't exist or connection fails |
TimeoutError
|
If the connection attempt times out |
Source code in pyvider/rpcplugin/transport/unix/transport.py
listen
async
¶
Start listening on Unix socket with cross-platform compatibility.
Source code in pyvider/rpcplugin/transport/unix/transport.py
Functions¶
normalize_unix_path
¶
Standardized Unix socket path normalization, handling: - unix: prefix - unix:/ prefix - unix:// prefix - Multiple leading slashes
Returns a clean path suitable for socket operations.