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 defaultsobject()as handler - For this minimal example, no custom handler is needed- Foundation
loggerprovides structured logging (notprint()) server.serve()handles the entire server lifecycle: transport setup, handshake, and request serving
Learning Path¶
Next Steps for Development¶
- Server Development Guide - Complete guide to building production-ready plugin servers
- Configuration Guide - Environment-driven configuration setup and best practices
- Security Implementation - Add mTLS, authentication, and secure communication
Understanding the Framework¶
- Transport Concepts - Learn about Unix sockets, TCP, and transport selection
- Security Model - Understand the plugin security architecture
Complete Examples¶
- Echo Service Examples - Full-featured service examples from basic to advanced
- Configuration Examples - Environment-specific configuration patterns
Related Examples¶
What's Next?¶
Next Steps¶
- Add Custom Logic - Replace
object()handler with your service implementation - Try Basic Client - Connect to this server with Basic Client Example
- Enable Features - Add Health Checks or Rate Limiting
- Go Production - Learn about Security Configuration
Learning Path¶
- Beginner: Health Check Example → Add monitoring
- Intermediate: Custom Protocol Example → Add your RPC methods
- Advanced: Complete Echo Service → Full service example