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.3.0.tar.gz (45.1 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.3.0-cp39-abi3-win_amd64.whl (231.9 kB view details)

Uploaded CPython 3.9+Windows x86-64

zmk_studio_api-0.3.0-cp39-abi3-win32.whl (222.7 kB view details)

Uploaded CPython 3.9+Windows x86

zmk_studio_api-0.3.0-cp39-abi3-manylinux_2_34_x86_64.whl (404.2 kB view details)

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

zmk_studio_api-0.3.0-cp39-abi3-macosx_11_0_arm64.whl (354.9 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

zmk_studio_api-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl (359.1 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for zmk_studio_api-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0bba8879964fa7e4c012894a3b3aecab3865b1a1e4825f67f4e644b617c5efd5
MD5 f8edc0354fde73494beab34d72c8e94a
BLAKE2b-256 12b9d10d23fbdef5b9dd9fd31d7bdf69246095cccd8fff15fe72da19f450a24f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zmk_studio_api-0.3.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 883184c1afd967313b2e558b67d6957c54b1487f7dca4d91e67b8e0224184069
MD5 dc4242510f976ea6c6d36649bb9dfbb6
BLAKE2b-256 7c3e094663acb96691fe3a8b47a41f112cc34923c6171f3cda3f71f74414cbe1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zmk_studio_api-0.3.0-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 34d53d4dd58892692f6babc61b5a9582d417bb0a09b550f0b3f06ddbbad46453
MD5 08e080b237956cc3de321d1a8060def1
BLAKE2b-256 9d5e5f94cb68bca1556fe3e761d666e4bf4d0392b1a06f97e1ab221295fc10db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zmk_studio_api-0.3.0-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6a6b23b5d6a038ed5f0f2b37dd9126caf064766be255f16c7046283c4ee22d57
MD5 054e648d2c0f9300500bb58474250d91
BLAKE2b-256 c5d3045b16275410ddbd7dcff0bb85b1846b97dda4ffca6701a9eb503dc387e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zmk_studio_api-0.3.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 88ab9fbdc7797c720829f4a73587e2f432fc3b69ae19691a9a19686fdbe49ce4
MD5 ace2d315c377db509e00058a5fb737c0
BLAKE2b-256 f9729ae3b13adbf7e635f280bcd9e39bc47a20880eea4adf8e8552365f062cff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zmk_studio_api-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 90370ff55909b36c70905a42028df9fd02a4ba50ceca260264dbd0c13c8cd214
MD5 b2aab6902e3d05be481e5193bf782d14
BLAKE2b-256 12ba23169987ee975357a533d04e040c04bc23e2a28dbcd903ec9dc0835c6bf9

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