Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Usage Patterns

This chapter targets repeatable integration patterns for tool builders and code generators.

Pattern: Cheap Health Check

Use at process startup to validate socket + auth + server liveness.

use kicad_ipc_rs::KiCadClient;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), kicad_ipc_rs::KiCadError> {
    let client = KiCadClient::connect().await?;
    client.ping().await?;
    Ok(())
}

Pattern: Read-only Query Pipeline

Recommended order for board-aware reads:

  1. get_open_documents()
  2. get_nets()
  3. get_items_by_net(...) or get_items_by_type_codes(...)

Reason: fail fast on document state before expensive item traversal.

Pattern: Safe Write Session

Use begin/end commit around mutating commands.

  1. begin_commit(...)
  2. create_items(...) / update_items(...) / delete_items(...)
  3. end_commit(..., CommitAction::Commit, ...)

If errors mid-flight: close with CommitAction::Abort/Drop per flow.

Common Pitfalls

PitfallSymptomAvoidance
Assume KiCad always runningconnect errors at startupexplicit prereq check + ping()
Skip open-document checkdownstream command failurescall get_open_documents() first
Mix sync + async API unintentionallyduplicate runtime ownershippick one surface per process
Fire write commands without commit sessionpartial or rejected mutationsalways bracket writes with commit APIs
Hardcode unsupported commandsAS_UNHANDLED at runtimemap/handle RunActionStatus and runtime flags

Async vs Blocking Selection

RequirementPreferred API
Tokio app / async daemonKiCadClient
Existing sync binaryKiCadClientBlocking
Lowest integration friction for scriptsKiCadClientBlocking + CLI

Reliability Checklist

  • Set explicit client_name for traceability.
  • Keep request timeout defaults unless measured need.
  • Handle transport + protocol errors as recoverable boundary.
  • Use typed wrappers when available; drop to raw only when needed.