gRPC Connection¶
TongSIM Lite uses gRPC to connect Python to Unreal. The SDK wraps grpc.aio and auto-instantiates all service stubs for you.
In most code you don’t need to build channels manually—use WorldContext.conn and call the service helpers (for example UnaryAPI / CaptureAPI).
Key building blocks¶
| Component | Location | What it does |
|---|---|---|
GrpcConnection |
src/tongsim/connection/grpc/core.py |
Creates the gRPC channel and instantiates all stubs |
| Stub discovery | src/tongsim/connection/grpc/utils.py |
Auto-finds *_pb2_grpc.py stubs via reflection |
| Safe wrappers | src/tongsim/connection/grpc/utils.py |
Error-handling decorators for async RPC calls |
| SDK↔Proto conversion | src/tongsim/connection/grpc/utils.py |
Converts Vector3/Transform to protobuf messages |
Message size
The Python channel is configured with a 100MB send/receive limit in GrpcConnection to support image and voxel payloads.
API References¶
tongsim.connection.grpc.core.GrpcConnection ¶
Lazily instantiate gRPC stubs and provide unified access plus teardown.
Source code in src/tongsim/connection/grpc/core.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
get_stub ¶
get_stub(stub_cls: type[T]) -> T
Retrieve the stub instance for the requested service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stub_cls
|
type[T]
|
Stub class generated by |
required |
Returns:
| Name | Type | Description |
|---|---|---|
T |
T
|
Stub instance typed to |
Source code in src/tongsim/connection/grpc/core.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
aclose
async
¶
aclose()
Close the gRPC channel and release all cached stubs.
Source code in src/tongsim/connection/grpc/core.py
84 85 86 87 88 89 90 | |
tongsim.connection.grpc.utils.iter_all_grpc_stubs ¶
iter_all_grpc_stubs() -> (
Generator[tuple[str, type], None, None]
)
Iterate through all gRPC service stubs defined in the protocol package.
Yields:
| Type | Description |
|---|---|
tuple[str, type]
|
tuple[str, type]: Stub class name and the class itself. |
Source code in src/tongsim/connection/grpc/utils.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
tongsim.connection.grpc.utils.iter_all_proto_messages ¶
iter_all_proto_messages() -> (
Generator[tuple[str, type[Message]], None, None]
)
Iterate over all protobuf Message types defined in _PACKAGE.
Yields:
| Type | Description |
|---|---|
tuple[str, type[Message]]
|
tuple[str, type[ProtoMessage]]: Fully qualified name and class object. |
Source code in src/tongsim/connection/grpc/utils.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
tongsim.connection.grpc.utils.safe_async_rpc ¶
safe_async_rpc(
default: T | None = None, raise_on_error: bool = False
) -> Callable[
[Callable[P, Awaitable[T]]],
Callable[P, Awaitable[T]],
]
Decorator that wraps async RPC invocations with safety guards.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default
|
T | None
|
Value (or awaitable factory) returned when an exception occurs. |
None
|
raise_on_error
|
bool
|
When |
False
|
Usage::
@safe_async_rpc(default={}, raise_on_error=False)
async def my_method(...):
...
Source code in src/tongsim/connection/grpc/utils.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
tongsim.connection.grpc.utils.safe_unary_stream ¶
safe_unary_stream(
raise_on_error: bool = False,
) -> Callable[
[Callable[P, AsyncIterator[T]]],
Callable[P, AsyncIterator[T]],
]
Decorator that guards async unary-stream RPC generators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raise_on_error
|
bool
|
Re-raise exceptions instead of silently stopping iteration. |
False
|
Source code in src/tongsim/connection/grpc/utils.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
tongsim.connection.grpc.utils.sdk_to_proto ¶
sdk_to_proto(obj: Any) -> Message
Source code in src/tongsim/connection/grpc/utils.py
164 165 166 167 168 | |
tongsim.connection.grpc.utils.proto_to_sdk ¶
proto_to_sdk(message: Message) -> Any
Source code in src/tongsim/connection/grpc/utils.py
195 196 197 198 199 | |