Python Extensions
Python extensions use the same gRPC protocol as Go extensions. The loader detects .py files and runs them with the configured Python interpreter, passing SHARUR_SOCKET_PATH as an environment variable. The extension is expected to listen on that Unix socket.
Prerequisites
Generate Python Stubs
This deposits extension_pb2.py and extension_pb2_grpc.py alongside your script.
Implement the Extension
Place the script in your extensions directory. sharur runs it as python ticket_context.py on startup.
Available RPC Methods
Implement any subset of the ExtensionServicer methods. Unimplemented methods should return a sensible empty response (see the template above). The full list mirrors the Go plugin interface — see Go Extensions for hook semantics.
| RPC | Purpose |
|---|---|
Name | Return extension identifier |
Tools | Return tool definitions |
ExecuteTool | Execute a registered tool |
SessionStart / SessionEnd | Session lifecycle |
AgentStart / AgentEnd | Per-prompt lifecycle |
TurnStart / TurnEnd | Per-LLM-turn lifecycle |
ModifyInput | Transform or consume user input |
ModifySystemPrompt | Augment the system prompt |
BeforePrompt | Mutate model/provider/thinking |
ModifyContext | Filter or inject LLM-bound messages |
BeforeProviderRequest | Modify the raw completion request |
AfterProviderResponse | Observe LLM output |
BeforeToolCall | Intercept or block tool calls |
AfterToolCall | Observe or modify tool results |
BeforeCompact / AfterCompact | Compaction lifecycle |
Tips
- Logs go to stderr. Python’s
print()goes to stdout, which is not read by the host. Usesys.stderr.write()orloggingfor debugging output. - Keep proto stubs in the same directory as your script, or adjust
sys.pathbefore importing them. - Thread safety:
grpc.serverwithThreadPoolExecutorhandles concurrent RPC calls. If you maintain per-session state, use a lock or session-keyed dict.