Skip to main content

Rust + Python client for the ZMK Studio RPC API (Serial + BLE)

Project description

zmk-studio-api

Version image image

zmk-studio-api is a Rust client for the ZMK Studio RPC API on ZMK keyboards. It can read device and keymap state, and apply keymap changes over serial or BLE. Additionally, this library includes Python bindings for API access from Python applications and scripts.

Usage

Rust

Add dependency with Cargo:

cargo add zmk-studio-api [--features ble]

Usage example:

use zmk_studio_api::{Behavior, HidUsage, Keycode, StudioClient, transport::serial::SerialTransport};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut client = StudioClient::new(SerialTransport::open("COM3")?);
    let info = client.get_device_info()?;
    println!("Device: {}", info.name);
    println!("Lock: {:?}", client.get_lock_state()?);

    let before = client.get_key_at(0, 12)?;
    println!("Before: {before:?}");

    client.set_key_at(0, 12, Behavior::KeyPress(HidUsage::from_encoded(Keycode::A.to_hid_usage())))?;
    let after = client.get_key_at(0, 12)?;
    println!("After: {after:?}");

    if client.check_unsaved_changes()? {
        client.discard_changes()?;
    }
    Ok(())
}

For a complete runnable example, see examples/basic_example.rs.

Python

Install from PyPI:

pip install zmk-studio-api

Usage example:

import zmk_studio_api as zmk

client = zmk.StudioClient.open_serial("COM3")
print("Lock:", client.get_lock_state())

before = client.get_key_at(0, 12)
print("Before:", before)

client.set_key_at(0, 12, zmk.KeyPress(zmk.Keycode.A))
after = client.get_key_at(0, 12)
print("After:", after)

For a complete runnable example, see examples/basic_example.py.

License & Attribution

This project is licensed under the Apache 2.0 license. Parts of this project are based on code from the ZMK Studio (Apache 2.0) and its TypeScript client implementation (MIT).

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

zmk_studio_api-0.2.0.tar.gz (42.6 kB view details)

Uploaded Source

Built Distributions

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

zmk_studio_api-0.2.0-cp39-abi3-win_amd64.whl (230.6 kB view details)

Uploaded CPython 3.9+Windows x86-64

zmk_studio_api-0.2.0-cp39-abi3-win32.whl (221.5 kB view details)

Uploaded CPython 3.9+Windows x86

zmk_studio_api-0.2.0-cp39-abi3-manylinux_2_34_x86_64.whl (402.2 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.34+ x86-64

zmk_studio_api-0.2.0-cp39-abi3-macosx_11_0_arm64.whl (355.1 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

zmk_studio_api-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl (359.0 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file zmk_studio_api-0.2.0.tar.gz.

File metadata

  • Download URL: zmk_studio_api-0.2.0.tar.gz
  • Upload date:
  • Size: 42.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.12.4

File hashes

Hashes for zmk_studio_api-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c8e25c85779a0d5e54a57bfe9ac164fd4b1c15f76383f3421aa5aee1719b1eed
MD5 afa24bda952aad316324d6f3f78768c8
BLAKE2b-256 8cbe81a2a9ac2ed276936e015189eafc15a64fd6f8c1fe9bd855d701149cc920

See more details on using hashes here.

File details

Details for the file zmk_studio_api-0.2.0-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for zmk_studio_api-0.2.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 36dfd678b6c79e8ce80606e692358407fb5e5edf2e4b9ba40f0f2b6f3f9d6b2d
MD5 37fb770b3bff59f3c2cbb3171188cfd1
BLAKE2b-256 f94264224a173efab4b768c7e875ea6f094a97e4dedbb905e22864821c5831d7

See more details on using hashes here.

File details

Details for the file zmk_studio_api-0.2.0-cp39-abi3-win32.whl.

File metadata

File hashes

Hashes for zmk_studio_api-0.2.0-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 f48e45c3863bfc369180fca55d75ed18c0d2f8244a2e60781b686570d924393f
MD5 192ea01f38c506ce6399bf20e6bde27a
BLAKE2b-256 9232dfd3c0b9d6dc554864bff1908f2d8a6e9b2fa683edd89e8086d192230363

See more details on using hashes here.

File details

Details for the file zmk_studio_api-0.2.0-cp39-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for zmk_studio_api-0.2.0-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2fa5f69acb9638ac7a051ca3668de8a911c91ff8716a4ec23011aa7400eb78d4
MD5 8a28bfd259157d511e040068509f18e9
BLAKE2b-256 8d6ed3ad1230b9d00dff2c5c5b2d1a74f97a43ad2ff3270f6ae657fd341bd00b

See more details on using hashes here.

File details

Details for the file zmk_studio_api-0.2.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zmk_studio_api-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9c56b6b5340c26c9d639e8debb51baefa6ab1f72501ca9efa14d31fff64c6c9d
MD5 15ee8c869ef6636064b44a906b5571c7
BLAKE2b-256 e3e9b544ffb0b357222813c4bc4b7f4055dc1b91fc6b9b3763a1404457a5a4bc

See more details on using hashes here.

File details

Details for the file zmk_studio_api-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for zmk_studio_api-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 35daea1bb41cbb78ceeb835286b5a8c9928dde9ace147d7946729101fa996fe3
MD5 3fa3cd20635670be4b88ca0caf85ba9d
BLAKE2b-256 95abd38f6784082cc619eb2784d7e7fdbffe5434ea6c089fb23589bf00439370

See more details on using hashes here.

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