Skip to content

Reference for Client: spawn a server, or connect to one over HTTP, such as VirtX cloud.

A Client holds a session with one server: one it starts as a child process and talks to over stdio, or one it reaches over HTTP. Everything else in the SDK is reached through a client. See Quick start for the three ways to reach a server.

Member Does
spawn Starts a server as a child process and talks to it over its stdin and stdout.
connect Reaches a server over HTTP at its base url, sending auth with every request, every request in project.
set_auth Replaces the credentials every later request sends, such as a new token when the server’s are short-lived.
set_project Names the project of every later request.
clone Another hold of the same session.
close Lets go of this hold; the last one ends the session.
ensure_virtx A function of the package rather than of a client: fetches virtx-stdio into the cache ahead of spawn, without starting it, and returns its path.

spawn

Starts a server as a child process and talks to it over its stdin and stdout. Without program, it starts virtx-stdio of the library’s version, fetched into a cache the first time. Rust calls the no-program form Client::spawn_virtx, which returns an Opening to await.

@classmethod
def spawn(program: str | None = None, args: Iterable[str] = ()) -> Client

connect

Reaches a server over HTTP at its base url, sending auth with every request, every request in project. A token is sent over plain http only to this machine’s loopback. For VirtX cloud, the url is https://cloud.virtx.sh and auth is a BearerAuth with an API key from the console; see Hello world.

@classmethod
def connect(url: str, auth: Auth | None = None, project: str | None = None) -> Client

set_auth

Replaces the credentials every later request sends, such as a new token when the server’s are short-lived. A forwarder already open sends it with its next connection. Over stdio nothing changes.

def set_auth(auth: Auth | None) -> None

set_project

Names the project of every later request. Without a project, a request is in its user’s own, default.

def set_project(project: str | None) -> None

clone

Another hold of the same session.

def clone() -> Client

close

Lets go of this hold; the last one ends the session. Python’s aclose does it off the event loop; in Rust, dropping the client does the same.

def close() -> None
async def aclose() -> None

ensure_virtx

A function of the package rather than of a client: fetches virtx-stdio into the cache ahead of spawn, without starting it, and returns its path.

async def ensure_virtx() -> str

Auth

auth is one of:

  • None: no credentials.
  • A bearer token: sent as it is. It isn’t refreshed; replace it with set_auth before it expires.
  • A command: the client runs it to get a token, and runs it again when the token is about to expire or the server rejects it. On a rerun after a rejection, TOKEN_REFUSED is set in the command’s environment.
Python Node.js Rust
BearerAuth(token) { type: 'bearer', token } Auth::Bearer
CommandAuth(program, args) { type: 'command', program, args } Auth::Command
None null Auth::None

Errors

A call that fails raises a VirtxError in Python, throws one in Node.js, and returns one in Rust. Branch on its status and code, not its message. These are the errors the calls on this page return most often.

Error From Cause
401, unauthorized Any call, on a server reached with connect The credentials are missing, not ones the server knows, or expired. Sign in again, or pass new credentials with set_auth.
403, forbidden Any call The credentials don’t allow the request, or the project doesn’t exist or you aren’t a member of it. The server doesn’t say which.
The client refuses to send a token in the clear connect The URL is http:// to another machine. Put TLS in front of the server and use https://.
source transport Any call The request or its response didn’t get through: the connection failed, or the session ended.
no virtx-stdio release v… is published for … spawn, ensure_virtx No server is published for this platform, such as an Intel Mac. Use VirtX cloud or a server of your own.
fetching …/virtx/releases/… spawn, ensure_virtx Downloading the server failed, after a few tries if the failure looked brief. Check the network or proxy, set VIRTX_DIST_URL to a mirror, or point VIRTX_STDIO at a server you downloaded.
… does not match its SHA256SUMS spawn, ensure_virtx The download came back changed, as a proxy may do. Try again, or set VIRTX_STDIO.
another fetch of virtx-stdio v… has held … spawn, ensure_virtx Another program on this machine has been downloading the same server for five minutes. Wait for it, or stop it.