Quick Start
Quick Start
Introduction
This SDK provides a simple and efficient way to communicate with the GM Desktop service. It is based on the JSON-RPC 2.0 protocol and exchanges data over a Unix socket file with high performance.
Core features
- High-performance communication over Unix Socket
- Follows the JSON-RPC 2.0 standard
- Supports Python 3.10+ async programming
- Simple, easy-to-use API design
Platform compatibility
This SDK communicates over Unix sockets and only supports Linux and macOS. Windows is not supported.
Environment Setup
Python Requirements
Version requirement
The SDK currently requires Python 3.10 or later.
Install Python 3.10+
Download and install the Python version for your operating system from python.org.
Verify the installation
python3 --version
# Example output: Python 3.10.0Install the SDK
Install the latest version with pip:
pip3 install simplejrpcVerify the installation:
python3 -c "import simplejrpc; print('SDK installed successfully!')"Quick Start
Create a Minimal App
Create a file named main.py:
# main.py
import asyncio
from simplejrpc.app import ServerApplication
from simplejrpc.response import jsonify
# Create the app instance with the socket file path
app = ServerApplication("app.socket")
@app.route(name="echo")
async def echo(message: str,lang: str):
"""Echo endpoint with validation"""
return jsonify(data=f"收到消息: {message}", msg="消息已处理")
@app.route(name="hello")
async def hello():
"""Simple greeting endpoint"""
return jsonify(data="Hello, GMSSH!", msg="请求成功")
if __name__ == "__main__":
asyncio.run(app.run())Tips
The name passed to @app.route(name="hello") must match the decorated function name, here hello.jsonify adds a 200 status code by default. To return a different code, add a code field to the return value.
Start the Service
python3 main.pySuccess
After the service starts, an app.socket file is created in the current directory for communication with the GM Desktop main process.
