KLayout-klink: feedback on external KLayout API coverage

Hi Matthias and everyone,

I'd like to share KLayout-klink, an open-source external control layer for a running KLayout GUI, and ask for some feedback on its KLayout API coverage. (https://github.com/klinkdev2026/klayout-klink)

While developing it, I found some older discussions on this forum about controlling an already-running KLayout instance from an external application. In particular, Matthias suggested using socket-based IPC while keeping KLayout itself as the host application.

https://www.klayout.de/forum/discussion/1001/how-to-send-a-ruby-script-for-execution-to-already-open-klayout-editor-instance?utm_source=chatgpt.com

https://www.klayout.de/forum/discussion/254/call-reload-from-command-line?utm_source=chatgpt.com

klink essentially follows this direction, but tries to turn the task-specific socket "glue code" into a reusable control interface.

Rather than simply providing a remote eval, I went through the KLayout pya and GUI APIs and tried to organize the operations useful for external control into stable, typed APIs.

Currently, the KLayout-facing control surface mainly covers:

  1. Layout & Cell — open/save layouts, cell creation/deletion, hierarchy, bbox, etc.
  2. Layers — layers/datatypes, layer properties and .lyp
  3. Shapes & Geometry — boxes, polygons, paths, text, batch insertion, transforms, boolean/fill
  4. Instances / PCells / Libraries — instances, arrays, PCell discovery/creation, libraries and flattening
  5. LayoutView / GUI — CellViews, tabs, active cell, viewport, zoom, hierarchy display, highlights and 2.5D view
  6. Selection — read/set selection, plus persistent "SEND" selections for external interaction
  7. Rulers / Annotations — access and manipulate native KLayout annotations and measurements
  8. Editing — grouped transactions, undo/redo
  9. DRC / LVS — DRC scripts, netlist extraction/comparison and LVS databases
  10. Events / Recording / Sessions — observe GUI/layout changes, record operations and control multiple running KLayout sessions

For things that are not yet covered, exec.python remains an escape hatch to the native pya API.

My own layout background is mainly custom research devices and nanodevices. Although I have tried to systematically go through the KLayout APIs, I do not know all the important workflows in IC layout, mask preparation, MEMS, photonics, PDK-based design and other fields.

So my main question is:

Which KLayout APIs or concepts am I still missing that you think are important enough to deserve a stable external control API?

I do not intend to wrap every pya method individually. I am mainly trying to identify the common, high-value operations that are useful when KLayout is controlled by an external Python program, automation system or MCP/AI client.

Matthias, I would especially appreciate your opinion, since you have seen KLayout used across many more application domains than I have.

Any suggestions or criticism would be very welcome.

Best regards,
Yanming

Sign In or Register to comment.