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.1.1.tar.gz (42.3 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.1.1-cp39-abi3-win_amd64.whl (234.1 kB view details)

Uploaded CPython 3.9+Windows x86-64

zmk_studio_api-0.1.1-cp39-abi3-win32.whl (224.5 kB view details)

Uploaded CPython 3.9+Windows x86

zmk_studio_api-0.1.1-cp39-abi3-manylinux_2_34_x86_64.whl (403.5 kB view details)

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

zmk_studio_api-0.1.1-cp39-abi3-macosx_11_0_arm64.whl (356.9 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

zmk_studio_api-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl (361.0 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for zmk_studio_api-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2f980249920bcb713dc3d57a039e1d2ccce032af54833613c07e4e2e98770ad5
MD5 581bbe03c6ce4295b27367b05ab6ec6a
BLAKE2b-256 84d416abbdf3a0eb4d9139bdf7acbc7f11023d983e140d2ea25c47d765977282

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zmk_studio_api-0.1.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ebf6ae70bca24ab1b545b2611d474566ac8a938d4b2492dccb5f92d41674f95f
MD5 0df8fe74eade24f6fecbf34c21ef58ed
BLAKE2b-256 89f1aec4f90ab809a8c0c411e4bb2ad1db6a0e3826016a8486cc96b00b452fb1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zmk_studio_api-0.1.1-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 c4bd41c183c387b67304eb56ec0a4996f29dd2fa88325c2cb135f820ee557ca2
MD5 62e4a50034d2babf9be58ac507480285
BLAKE2b-256 ee5a0ec62def49e38af6a29f88491a9271add8dbcc2f0b1ee0b8d2b974a01c77

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zmk_studio_api-0.1.1-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d6f6b83a515b2ffb2f3b0ed7edb69adff11e32c53457c85c83ed73e99608bba6
MD5 141e746efbd1a60cafcff47d7cf0aa22
BLAKE2b-256 2be7dd6be38e668fba5d993716a29bb95d0e171acc0ac621a8ca822fc629e5da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zmk_studio_api-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 29fc540ef63ef6c9112dfffac595e38df01dfc0b322606f3bb9afc88c2d5a053
MD5 d8e07ece83cdfa263fccd97da28a5967
BLAKE2b-256 67570082724b7425a4c3c0739459a17fd1fa7098bb74d3ad6c20b38f37b07761

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zmk_studio_api-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c28ccd34a3d70c859003e92750e34e735b446d55de8700504dbc74f1596a3e85
MD5 9f5af5656185e27303d56c8ec78e0346
BLAKE2b-256 ad2d3f79e457b0dd52bb6df8e83f1d861eff4678952aae0c5be63ebf1987a5b8

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