Skip to main content

Async client for NanoKVM devices.

Project description

python-nanokvm

Async Python client for NanoKVM.

Usage

from nanokvm.client import NanoKVMClient
from nanokvm.models import GpioType, MouseButton

# NanoKVM (auto-detects password mode)
async with NanoKVMClient("https://kvm.local/api/") as client:
    await client.authenticate("username", "password")

    # Get device information
    dev = await client.get_info()
    hw = await client.get_hardware()
    gpio = await client.get_gpio()

    # List available images
    images = await client.get_images()

    # Keyboard input
    await client.paste_text("Hello\nworld!")

    # Mouse control
    await client.mouse_click(MouseButton.LEFT, 0.5, 0.5)
    await client.mouse_move_abs(0.25, 0.75)
    await client.mouse_scroll(0, -3)

    # Stream video
    async for frame in client.mjpeg_stream():
        print(frame)

    # Control GPIO
    await client.push_button(GpioType.POWER, duration_ms=1000)

SSH Usage

from nanokvm.ssh_client import NanoKVMSSH

# Create SSH client
ssh = NanoKVMSSH("kvm-8b76.local")
await ssh.authenticate("password")

# Run commands
uptime = await ssh.run_command("cat /proc/uptime")
disk = await ssh.run_command("df -h /")

await ssh.disconnect()

Password Obfuscation Modes

By default, the client auto-detects the correct password mode. It tries obfuscated password first, and falls back to plain text if authentication fails. You can also force a specific mode:

# Auto-detect (default) — recommended
async with NanoKVMClient("https://kvm.local/api/") as client:
    await client.authenticate("username", "password")

# Force plain text (newer NanoKVM with HTTPS)
async with NanoKVMClient(
    "https://kvm.local/api/",
    use_password_obfuscation=False
) as client:
    await client.authenticate("username", "password")

# Force obfuscation (older NanoKVM with HTTP)
async with NanoKVMClient(
    "http://kvm.local/api/",
    use_password_obfuscation=True
) as client:
    await client.authenticate("username", "password")

HTTPS/SSL Configuration

The client supports HTTPS connections with flexible SSL/TLS configuration options.

Standard HTTPS (Let's Encrypt, Public CA)

For modern NanoKVM devices with HTTPS and valid certificates:

async with NanoKVMClient("https://kvm.local/api/") as client:
    await client.authenticate("username", "password")

Self-Signed Certificates

For self-signed certificates, you have two options:

Option 1: Disable verification (testing only)

Warning: This is insecure and should only be used for testing!

async with NanoKVMClient(
    "https://kvm.local/api/",
    verify_ssl=False,
) as client:
    await client.authenticate("username", "password")

Option 2: Certificate pinning (recommended for self-signed)

NanoKVM devices generate self-signed certificates for localhost with no CA to verify against. Certificate pinning verifies the server's certificate fingerprint directly instead of relying on CA-based trust.

from nanokvm.utils import async_fetch_remote_fingerprint

# First, fetch the fingerprint (trust-on-first-use)
fingerprint = await async_fetch_remote_fingerprint("https://kvm.local/api/")

# Then connect with the pinned fingerprint
async with NanoKVMClient(
    "https://kvm.local/api/",
    ssl_fingerprint=fingerprint,
) as client:
    await client.authenticate("username", "password")

Option 3: Use custom CA certificate

async with NanoKVMClient(
    "https://kvm.local/api/",
    ssl_ca_cert="/path/to/ca.pem",
) as client:
    await client.authenticate("username", "password")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nanokvm-1.2.0.tar.gz (33.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nanokvm-1.2.0-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

File details

Details for the file nanokvm-1.2.0.tar.gz.

File metadata

  • Download URL: nanokvm-1.2.0.tar.gz
  • Upload date:
  • Size: 33.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nanokvm-1.2.0.tar.gz
Algorithm Hash digest
SHA256 0c46f6cee567c9d4befb583b589845369357810f19d6387f829a3aee8ae7bc4b
MD5 2ad85740421fca3d1e5f9ad81bf4f5ed
BLAKE2b-256 e3c6b24a67188cf78da1496273dbbda07d64b42c1be990618fdf4ff9c7952757

See more details on using hashes here.

Provenance

The following attestation bundles were made for nanokvm-1.2.0.tar.gz:

Publisher: publish-to-pypi.yml on puddly/python-nanokvm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nanokvm-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: nanokvm-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 26.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nanokvm-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7022d56a8a987128294b482a8fe41ea587b8da267c1a25bc868dd2117946882e
MD5 a0ddba456e8438ed43a684a9bcd23dbf
BLAKE2b-256 c450da58a069f403b2a770c06923eacbb9180d0e3df3b65b02f029fe67e0fc5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for nanokvm-1.2.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on puddly/python-nanokvm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page