Skip to content

Server Development

Learn how to build robust plugin servers with Pyvider RPC Plugin. This section covers everything from basic server setup to advanced patterns for production deployments.

๐Ÿค– 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

Plugin servers provide gRPC services to host applications through secure, high-performance communication channels. The Pyvider RPC Plugin framework handles the complexity of transport management, security, and service registration, allowing you to focus on business logic.

Quick Server Example

Here's a minimal plugin server to get you started:

import asyncio
from pyvider.rpcplugin import plugin_server
from pyvider.rpcplugin.protocol.base import RPCPluginProtocol
from example_pb2_grpc import add_CalculatorServicer_to_server
from example_pb2 import CalculationResponse

class CalculatorProtocol(RPCPluginProtocol):
    service_name = "calculator.Calculator"

    async def get_grpc_descriptors(self):
        import example_pb2_grpc
        return example_pb2_grpc, "calculator.Calculator"

    async def add_to_server(self, server, handler):
        add_CalculatorServicer_to_server(handler, server)

class CalculatorHandler:
    async def Add(self, request, context):
        result = request.a + request.b
        return CalculationResponse(result=result)

    async def Subtract(self, request, context):
        result = request.a - request.b
        return CalculationResponse(result=result)

async def main():
    server = plugin_server(
        protocol=CalculatorProtocol(),
        handler=CalculatorHandler()
    )

    await server.serve()

if __name__ == "__main__":
    asyncio.run(main())

Server Development Sections

๐Ÿ“ Basic Server Setup

Learn the fundamentals of creating and configuring plugin servers: - Server initialization and configuration - Environment setup and validation - Basic error handling patterns - Development vs production setup

โš™๏ธ Service Implementation

Implement robust gRPC service handlers: - Service method patterns (unary, streaming) - Error handling and status codes - Input validation and sanitization - Business logic organization

๐ŸŒ Transport Configuration

Configure transport layers for optimal performance: - Unix socket vs TCP selection - mTLS configuration and certificates - Performance optimization - Security considerations

๐Ÿ”„ Async Patterns

Master asynchronous programming patterns: - Concurrent request handling - Background task management - Resource pooling - Async context management

๐Ÿฅ Health Checks

Implement comprehensive health monitoring: - gRPC health check protocol - Custom health indicators - Resource monitoring - Graceful degradation

Next Steps

Ready to dive deeper into server development? Choose your path:

  1. New to Plugin Servers? Start with Basic Server Setup
  2. Need Service Implementation Help? Check out Service Implementation
  3. Working on Performance? Explore Async Patterns
  4. Production Deployment? Review Transport Configuration

Each section builds upon the concepts introduced here, providing practical examples and advanced patterns for building production-ready plugin servers.