Skip to content

Basic Server Example

Complexity: 🟢 Beginner | Lines: ~15 | Source Code: examples/short/basic_server.py

A minimal plugin server demonstrating the absolute basics - just 15 lines to create a working RPC plugin server.

#!/usr/bin/env python3
"""
Minimal plugin server example (15 lines).

Shows the absolute basics of creating a plugin server.
"""
import asyncio
from pyvider.rpcplugin import plugin_protocol, plugin_server
from provide.foundation import logger


async def main():
    """Run minimal plugin server."""
    protocol = plugin_protocol()  # Basic protocol
    handler = object()  # Dummy handler
    server = plugin_server(protocol=protocol, handler=handler)

    logger.info("Starting minimal server...")
    await server.serve()


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

Key Points

  • plugin_protocol() creates a basic protocol implementation (no custom RPC methods)
  • plugin_server() factory creates a fully configured server with sensible defaults
  • object() as handler - For this minimal example, no custom handler is needed
  • Foundation logger provides structured logging (not print())
  • server.serve() handles the entire server lifecycle: transport setup, handshake, and request serving

Learning Path

Next Steps for Development

Understanding the Framework

Complete Examples

What's Next?

Next Steps

  1. Add Custom Logic - Replace object() handler with your service implementation
  2. Try Basic Client - Connect to this server with Basic Client Example
  3. Enable Features - Add Health Checks or Rate Limiting
  4. Go Production - Learn about Security Configuration

Learning Path