CLI¶
Command-line interface for introspecting and calling methods on vgi-rpc services. Requires pip install vgi-rpc[cli].
Registered as the vgi-rpc entry point. Provides describe, call, loggers, and launch commands. Connects over HTTP (--url), a subprocess (--cmd), or a Unix domain socket (--unix).
Usage¶
Describe a service¶
# Subprocess transport
vgi-rpc describe --cmd "python worker.py"
# HTTP transport
vgi-rpc describe --url http://localhost:8000
# Unix domain socket transport
vgi-rpc describe --unix /run/vgi/worker.sock
# JSON output
vgi-rpc describe --cmd "python worker.py" --format json
Call a method¶
# Unary call with key=value parameters
vgi-rpc call add --cmd "python worker.py" a=1.0 b=2.0
# JSON parameter input
vgi-rpc call add --url http://localhost:8000 --json '{"a": 1.0, "b": 2.0}'
# Producer stream (table output)
vgi-rpc call countdown --cmd "python worker.py" n=5 --format table
# Exchange stream (pipe JSON lines to stdin)
echo '{"value": 1.0}' | vgi-rpc call accumulate --url http://localhost:8000
List loggers¶
# Human-readable table
vgi-rpc loggers
# JSON (for scripting / LLM consumption)
vgi-rpc loggers --format json
Launch a worker pool¶
vgi-rpc launch spawns or reuses a long-running Unix-socket worker. Pass the worker command after --. The same (cmd, args, cwd, VGI_RPC_*-env) hashes to the same socket, so repeated launches reuse a warm worker; workers self-shut-down after --idle-timeout seconds idle. Concurrent first-callers serialise on a per-hash lock, so exactly one worker is spawned.
# Discover-or-spawn a worker and print its socket path (UNIX:<path>)
vgi-rpc launch -- python -m my_worker
# Custom idle timeout (seconds)
vgi-rpc launch --idle-timeout 600 -- python -m my_worker
# Explicit socket path (skips the per-hash machinery)
vgi-rpc launch --socket /run/vgi/my.sock -- python -m my_worker
# List tracked workers and their liveness, then exit
vgi-rpc launch --status
# Remove stale lock/socket/meta entries, then exit
vgi-rpc launch --gc
The printed UNIX:<path> can be fed straight to --unix on a subsequent describe/call.
| Option | Default | Description |
|---|---|---|
--socket |
(hash-derived) | Explicit socket path; skips the per-hash machinery |
--idle-timeout |
300 |
Worker self-shutdown after N seconds idle |
--connect-timeout |
30 |
Max seconds to wait for the per-hash lock |
--worker-startup-timeout |
60 |
Max seconds to wait for the worker's UNIX:<path> line (JVM-friendly) |
--worker-stderr |
(discard) | Append worker stderr to this file |
--state-dir |
(per-user) | Override the default state directory |
--status |
List known workers and exit (no spawning) | |
--gc |
Remove stale entries and exit |
--status and --gc are mutually exclusive.
Debug logging¶
# Enable DEBUG on all vgi_rpc loggers
vgi-rpc --debug describe --cmd "python worker.py"
# Set a specific level
vgi-rpc --log-level INFO describe --cmd "python worker.py"
# Target specific loggers
vgi-rpc --log-level DEBUG --log-logger vgi_rpc.wire.request call add --cmd "python worker.py" a=1 b=2
# JSON log format on stderr
vgi-rpc --debug --log-format json call add --cmd "python worker.py" a=1 b=2
Output format¶
Results are printed as one JSON object per row (NDJSON). When a method returns a batch with multiple rows, each row is emitted as its own line rather than a single object with array values. This applies to unary results, producer streams, and exchange responses.
# A stream that emits 2 batches of 3 rows each produces 6 lines:
$ vgi-rpc call generate_rows --cmd "python worker.py" count=6 rows_per_batch=3
{"i": 0, "value": 0}
{"i": 1, "value": 10}
{"i": 2, "value": 20}
{"i": 3, "value": 30}
{"i": 4, "value": 40}
{"i": 5, "value": 50}
With --format table, rows from all batches are collected and displayed as a single aligned table:
$ vgi-rpc call generate_rows --cmd "python worker.py" count=4 --format table
i value
-- -----
0 0
1 10
2 20
3 30
With --format auto (the default), the CLI uses pretty-printed JSON when stdout is a TTY and compact NDJSON when piped.
With --format arrow, raw Arrow IPC streaming data is written to the output. Use --output/-o to direct binary output to a file:
# Unary result as Arrow IPC
vgi-rpc call add --cmd "python worker.py" a=1.0 b=2.0 --format arrow -o result.arrow
# Producer stream as Arrow IPC
vgi-rpc call generate --cmd "python worker.py" count=100 --format arrow -o data.arrow
# Stream with header: two concatenated IPC streams (header + data)
vgi-rpc call generate_with_header --cmd "python worker.py" count=5 --format arrow -o stream.arrow
The output file contains standard Arrow IPC streaming format data. For unary calls and headerless streams, this is a single IPC stream (schema + batches + EOS). For streams with headers, the file contains two concatenated IPC streams: the header stream first, then the data stream.
Read back a unary or headerless stream result:
import pyarrow as pa
from pyarrow import ipc
with ipc.open_stream(pa.OSFile("result.arrow", "rb")) as reader:
for batch in reader:
print(batch.to_pandas())
Read back a stream with header (two concatenated IPC streams):
import pyarrow as pa
from pyarrow import ipc
with open("stream.arrow", "rb") as f:
# First IPC stream: header
header_reader = ipc.open_stream(f)
header_batch = header_reader.read_next_batch()
print("Header:", header_batch.to_pydict())
# Drain remaining batches to reach EOS
for _ in header_reader:
pass
# Second IPC stream: data
data_reader = ipc.open_stream(f)
for batch in data_reader:
print(batch.to_pandas())
Without --output, arrow data is written to stdout. A warning is printed to stderr if stdout is a TTY.
Stream headers¶
Stream methods that declare a header type (e.g. Stream[MyState, MyHeader]) emit a one-time header before the data rows. The CLI reads this header and surfaces it in all output formats.
JSON (--format json): a {"__header__": {...}} line before data rows:
$ vgi-rpc call generate_with_header --cmd "python worker.py" count=3 --format json
{"__header__": {"total_count": 3, "label": "generate"}}
{"i": 0, "value": 0}
{"i": 1, "value": 10}
{"i": 2, "value": 20}
Table (--format table): a Header: section with indented key-value pairs before the data table:
$ vgi-rpc call generate_with_header --cmd "python worker.py" count=3 --format table
Header:
total_count: 3
label: generate
i value
- -----
0 0
1 10
2 20
Arrow (--format arrow): the header is written as a separate IPC stream before the data IPC stream (see reading back concatenated streams above).
Streams without headers are unaffected — no __header__ line or Header: section appears.
Options¶
| Option | Short | Description |
|---|---|---|
--url |
-u |
HTTP base URL |
--cmd |
-c |
Subprocess command |
--unix |
Unix domain socket path | |
--prefix |
-p |
URL path prefix (default "") |
--format |
-f |
Output format: auto, json, table, or arrow |
--output |
-o |
Output file path (default: stdout) |
--verbose |
-v |
Show server log messages on stderr |
--debug |
Enable DEBUG on all vgi_rpc loggers to stderr |
|
--log-level |
Python logging level: DEBUG, INFO, WARNING, ERROR |
|
--log-logger |
Target specific logger(s), repeatable | |
--log-format |
Stderr log format: text (default) or json |
|
--json |
-j |
Pass parameters as a JSON string (for call) |
--debug is shorthand for --log-level DEBUG. When both are given, --debug wins. --verbose (server-to-client log messages) remains orthogonal to --debug/--log-level (Python logging).
Module Reference¶
cli
¶
Command-line interface for vgi-rpc services.
Provides describe, call, and loggers commands for introspecting
and invoking methods on any vgi-rpc service that has enable_describe=True.
Usage::
vgi-rpc describe --cmd "my-worker"
vgi-rpc call add --cmd "my-worker" a=1.0 b=2.0
vgi-rpc call generate --url http://localhost:8000 count=3
vgi-rpc loggers
OutputFormat
¶
Bases: StrEnum
Output format for CLI commands.
LogLevel
¶
Bases: StrEnum
Python logging level for --log-level.
LogFormat
¶
Bases: StrEnum
Stderr log format for --log-format.
mesh_doctor
¶
mesh_doctor(
endpoint: Annotated[
str,
Argument(
help="Worker endpoint, for example tcp://worker:9400"
),
],
proxy: Annotated[
str | None,
Option(
"--proxy",
help="Explicit socks5h://IP:PORT proxy",
),
] = None,
timeout: Annotated[
float,
Option(
"--timeout",
help="Per-stage deadline in seconds",
),
] = 5.0,
tailscale_issuer: Annotated[
str | None, Option("--tailscale-issuer")
] = None,
tailscale_source: Annotated[
str | None,
Option(
"--tailscale-source",
help="Source IP:port to query with LocalAPI WhoIs",
),
] = None,
tailscale_localapi: Annotated[
str | None,
Option(
"--tailscale-localapi",
help="Unix socket path or HTTP LocalAPI origin",
),
] = None,
tailscale_password: Annotated[
str | None,
Option("--tailscale-password", hidden=True),
] = None,
service_name: Annotated[
str | None,
Option(
"--service-name", help="Destination svc: name"
),
] = None,
json_output: Annotated[
bool, Option("--json", help="Emit JSON results")
] = False,
) -> None
Check TCP/SOCKS, the VGI describe handshake, and optional WhoIs.
Source code in vgi_rpc/cli.py
loggers
¶
List all known vgi-rpc logger names with descriptions.
Source code in vgi_rpc/cli.py
launch
¶
launch(
ctx: Context,
socket: Annotated[
str | None,
Option(
"--socket",
help="Explicit socket path; skips hash machinery",
),
] = None,
idle_timeout: Annotated[
float,
Option(
"--idle-timeout",
help="Worker self-shutdown after N seconds idle (default 300)",
),
] = 300.0,
connect_timeout: Annotated[
float,
Option(
"--connect-timeout",
help="Max seconds to wait for the per-hash flock (default 30)",
),
] = 30.0,
worker_startup_timeout: Annotated[
float,
Option(
"--worker-startup-timeout",
help="Max seconds to wait for worker UNIX:<path> line (default 60; JVM-friendly)",
),
] = 60.0,
worker_stderr: Annotated[
str | None,
Option(
"--worker-stderr",
help="Append worker stderr to this file (default: discard)",
),
] = None,
state_dir: Annotated[
str | None,
Option(
"--state-dir",
help="Override default state directory",
),
] = None,
status: Annotated[
bool,
Option(
"--status",
help="List known workers in the state dir and exit (no spawning)",
),
] = False,
gc: Annotated[
bool,
Option(
"--gc",
help="Remove stale lock/socket/meta entries from the state dir and exit",
),
] = False,
) -> None
Discover-or-spawn a Unix-socket worker.
The actual worker command (and its args) come after -- on the command
line — typer doesn't see them; they're collected from ctx.args.
Source code in vgi_rpc/cli.py
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 | |
describe
¶
Introspect a vgi-rpc service and show its methods.
Source code in vgi_rpc/cli.py
call
¶
call(
ctx: Context,
method: Annotated[
str, Argument(help="Method name to call")
],
args: Annotated[
list[str] | None,
Argument(help="key=value parameters"),
] = None,
json_input: Annotated[
str | None,
Option("--json", "-j", help="JSON params"),
] = None,
input_file: Annotated[
str | None,
Option(
"--input",
"-i",
help="Arrow IPC file for exchange input",
),
] = None,
no_stdin: Annotated[
bool,
Option(
"--no-stdin",
help="Force producer mode (ignore stdin)",
hidden=True,
),
] = False,
) -> None
Call a method on a vgi-rpc service.
Source code in vgi_rpc/cli.py
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 | |