SDK overview
The Python, Node.js and Rust clients: how to install them, how their names map to each other, and how a call returns.
VirtX has one client in three languages: virtx for Python, @brekkylab/virtx for Node.js and the virtx crate for Rust.
All three make their requests through the same library, libvirtx_core, so they send the same requests and return the same values.
Installation covers what each needs.
pip install virtxnpm install @brekkylab/virtxcargo add virtxcargo add tokio --features macros,rt-multi-threadNames
Python’s names are the reference’s own.
Node.js uses the same names in camelCase, such as createSandbox for create_sandbox, and fields in camelCase, such as memoryMib.
Rust uses the same names as Python, and passes a call’s options in one struct, such as SandboxCreateArgs.
Each entry in this reference shows all three.
How a call returns
A call is a coroutine: await it for its value.
A call that starts a job returns a StartedJob: awaited, it is the job; iterated with async for, it yields the job’s log, a LogEntry at a time; complete() follows it to its end.
download_image and upload_image are async iterators of Progress events, then one Output.
A call returns a Promise.
A call that starts a job returns a StartedJob, a Promise of the job that is also an async iterable of its log, read with for await; complete() follows it to its end.
downloadImage and uploadImage are async generators of { progress } events, then one { output }.
A call returns a Call<T>, a Future of Result<T, Error> that any async runtime awaits; on a thread without one, .wait() blocks for it.
A call that returns items one by one is an Events<T>, a Stream, or .wait_next() without a runtime.
A call that starts a job returns a StartedJob: awaited, it is the job; .log() is its JobLog, a Stream of log entries; .complete(print) is a JobEnd, what the job ended with.
When a request is sent differs by language, and in each it is sent once, however its value is used:
- Python: the calls are
async def, so nothing is sent until the value is awaited, or, for aStartedJob, first awaited or iterated. - Node.js and Rust: the request is sent when the method is called.
Calls that fail raise, throw or return the same error in each language: see Errors.