Skip to content

Python SDK (pyvergeos)

The pyvergeos SDK provides a Pythonic, type-annotated interface for the entire VergeOS REST API. Rather than crafting raw HTTP requests, you work with resource managersclient.vms, client.networks, client.tenants — that map directly to VergeOS objects. The SDK handles authentication, pagination, retries, and async task polling so your automation scripts stay clean and focused on business logic.

Prerequisites:

  • Python 3.9 or later
  • VergeOS 26.0 or later
  • Works on Windows, macOS, and Linux

Install from PyPI (recommended):

Terminal window
pip install pyvergeos

Or with uv (faster alternative):

Terminal window
uv add pyvergeos

From source (development):

Terminal window
git clone https://github.com/verge-io/pyvergeos.git
cd pyvergeos
pip install .

The SDK supports three authentication methods, each suited to different environments.

The simplest approach for interactive scripts and development:

from pyvergeos import VergeClient
client = VergeClient(
host="192.168.1.100",
username="admin",
password="secret",
verify_ssl=False # Only for self-signed certificates
)

For production automation where you have a pre-generated API key:

client = VergeClient(
host="192.168.1.100",
token="your-api-token"
)

The recommended approach for production — keeps credentials out of source code:

Terminal window
export VERGE_HOST=192.168.1.100
export VERGE_USERNAME=admin
export VERGE_PASSWORD=secret
export VERGE_VERIFY_SSL=false # Optional
export VERGE_TIMEOUT=30 # Optional
export VERGE_RETRY_TOTAL=3 # Optional
export VERGE_RETRY_BACKOFF=1 # Optional
client = VergeClient.from_env()

Always use the context manager in production code to ensure connections are properly closed, even when exceptions occur:

with VergeClient(host="192.168.1.100", token="api-token") as client:
vms = client.vms.list()
for vm in vms:
print(f"{vm.name}: {vm.ram}MB RAM")
# Connection automatically closed here

Every VergeOS resource type is exposed through a resource manager on the client object. Each manager provides consistent list(), get(), create(), and action methods.

Virtual Machines

client.vms — Create, configure, power control, clone, snapshot, and manage drives/NICs for VMs.

Networks

client.networks — Virtual networks, firewall rules, DHCP, DNS, and network power management.

Tenants

client.tenants — Multi-tenant provisioning, resource isolation, snapshots, storage and network blocks.

NAS & Storage

client.nas — NAS services, volumes, CIFS/NFS shares, and volume synchronization.

Disaster Recovery

client.dr — Cloud snapshots, site synchronization, and recovery workflows.

Users & Groups

client.users — User accounts, groups, permissions, and API key management.

Tasks & Monitoring

client.tasks — Async task tracking, waiting, timeouts. Also: alarms and logs.

System & GPU

client.clusters, client.nodes, client.gpu — Cluster/node info, storage tiers, GPU device management.

CategoryResources Available
Virtual MachinesVMs, drives, NICs, snapshots
NetworkingNetworks, firewall rules, DNS, DHCP, aliases, hosts
VPNIPSec connections, WireGuard interfaces and peers
NAS/StorageNAS services, volumes, CIFS/NFS shares, volume syncs
TenantsTenant management, snapshots, storage blocks, network blocks
Users & GroupsUsers, groups, permissions, API keys
SystemClusters, nodes, storage tiers, certificates
MonitoringAlarms, logs, tasks
Backup & DRSnapshot profiles, cloud snapshots, sites, site syncs

The SDK provides three approaches for filtering resources, from simple keyword arguments to a full OData filter builder.

The simplest approach for basic filters — pass field names directly:

# Find all running Linux VMs
vms = client.vms.list(status="running", os_family="linux")
# Wildcard matching
vms = client.vms.list(name="prod-*")

For complex queries, pass raw OData filter expressions:

# Combine conditions with operators
vms = client.vms.list(filter="os_family eq 'linux' and ram gt 2048")

Build filters programmatically with type safety and auto-completion:

from pyvergeos import Filter
# Fluent chaining with operator methods
f = Filter().eq("os_family", "linux").and_().gt("ram", 2048)
vms = client.vms.list(filter=str(f))

Available filter operators:

MethodOData OperatorExample
.eq()eqFilter().eq("status", "running")
.ne()neFilter().ne("os_family", "windows")
.gt()gtFilter().gt("ram", 4096)
.lt()ltFilter().lt("cpu_cores", 8)
.ge()geFilter().ge("ram", 2048)
.le()leFilter().le("ram", 8192)
.and_()andChain multiple conditions

Many VergeOS operations — snapshots, clones, migrations — run asynchronously and return a task ID immediately. The SDK provides a task manager to poll for completion:

# Snapshot returns a task reference
result = vm.snapshot(retention=86400, quiesce=True)
# Wait for the snapshot to complete (blocks up to 300 seconds)
task = client.tasks.wait(result["task"], timeout=300)
print(f"Snapshot completed: {task}")

If the task does not complete within the timeout, a TaskTimeoutError is raised with the task_id property so you can check status later:

from pyvergeos import TaskTimeoutError
try:
task = client.tasks.wait(task_id, timeout=60)
except TaskTimeoutError as e:
print(f"Task {e.task_id} still running — check back later")

The SDK provides a structured exception hierarchy so you can catch specific failure modes:

ExceptionDescription
VergeErrorBase exception for all SDK errors
AuthenticationErrorInvalid credentials or expired token
NotFoundErrorRequested resource does not exist
ConflictErrorResource state conflict (e.g., VM already running)
ValidationErrorInvalid parameter values
TaskTimeoutErrorTask did not complete within timeout
TaskErrorTask failed during execution
from pyvergeos import NotFoundError, AuthenticationError
try:
vm = client.vms.get(name="nonexistent-vm")
except NotFoundError:
print("VM not found — check the name")
except AuthenticationError:
print("Authentication failed — verify credentials")

The SDK automatically retries transient errors (HTTP 429, 500, 502, 503, 504) with exponential backoff:

client = VergeClient(
host="192.168.1.100",
token="api-token",
retry_total=5, # Max retry attempts (default: 3)
retry_backoff_factor=2, # Backoff multiplier (default: 1)
)

Set retry_total=0 to disable retries entirely for time-sensitive operations.

One of pyvergeos’s most powerful features is the ability to connect into tenant contexts from the host system. This enables centralized automation scripts that manage resources across multiple tenants:

# Get a tenant from the host system
tenant = client.tenants.get(name="customer-a")
# Connect into the tenant's context
tenant_client = tenant.connect()
# Now manage resources INSIDE the tenant
tenant_vms = tenant_client.vms.list()
for vm in tenant_vms:
print(f"Tenant VM: {vm.name}")
# Create a network inside the tenant
tenant_client.networks.create(
name="tenant-app-net",
network_address="10.50.1.0/24",
ip_address="10.50.1.1",
dhcp_enabled=True
)

This is particularly valuable for MSPs and service providers who need to automate provisioning across dozens or hundreds of tenant environments from a single script.

with VergeClient.from_env() as client:
# Create a new VM
vm = client.vms.create(
name="web-server-01",
ram=4096,
cpu_cores=2,
os_family="linux"
)
# Add a 50 GB data drive
vm.drives.add(name="data", size=50 * 1024 * 1024 * 1024)
# Attach to a network
network = client.networks.get(name="app-network")
vm.nics.add(network=network.key)
# Power on
vm.power_on()
print(f"VM {vm.name} is running")
with VergeClient.from_env() as client:
# Create a network
network = client.networks.create(
name="web-tier",
network_address="10.20.1.0/24",
ip_address="10.20.1.1",
dhcp_enabled=True
)
network.power_on()
# Add firewall rules
network.rules.create(
name="Allow HTTPS",
action="accept",
protocol="tcp",
dest_port=443
)
network.rules.create(
name="Allow SSH",
action="accept",
protocol="tcp",
dest_port=22
)
network.apply_rules()
with VergeClient.from_env() as client:
# Snapshot all running production VMs
prod_vms = client.vms.list(name="prod-*", status="running")
for vm in prod_vms:
result = vm.snapshot(retention=86400, quiesce=True)
task = client.tasks.wait(result["task"], timeout=300)
print(f"Snapshotted {vm.name}")
with VergeClient.from_env() as client:
for tenant in client.tenants.list():
tenant_client = tenant.connect()
vms = tenant_client.vms.list()
print(f"\n--- {tenant.name} ---")
for vm in vms:
print(f" {vm.name}: {vm.ram}MB RAM, {vm.cpu_cores} cores")