GDS layout file reader/writer using Rust and Arrow
  • Rust 92.8%
  • Python 6.8%
  • C 0.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jan Petykiewicz e858ec83c9 fix(schema): allow paths without an explicit width
Make path width nullable to preserve absent WIDTH records separately from explicit zero or negative widths in full and selected reads.
2026-11-14 14:39:08 -08:00
klamath_rs_ext fixes for cffi approach 2024-12-21 16:38:56 -08:00
src fix(schema): allow paths without an explicit width 2026-11-14 14:39:08 -08:00
tests fix(schema): allow paths without an explicit width 2026-11-14 14:39:08 -08:00
.gitignore snapshot 2021-12-18 21:05:00.635887 2021-12-18 21:05:00 -08:00
ARROW_SCHEMA.md fix(schema): allow paths without an explicit width 2026-11-14 14:39:08 -08:00
Cargo.toml follow masque interface 2026-04-02 20:35:31 -07:00
pyproject.toml CFFI + maturin approach 2024-12-21 15:42:50 -08:00
README.md feat(parser): add hierarchy scans and selective cell reads 2026-11-14 14:27:09 -08:00
test.py fix(ffi): return parser status and isolate thread errors 2026-11-14 14:23:13 -08:00

klamath-rs

A fast GDSII parser and writer in Rust, with Apache Arrow integration for efficient data handling.

Overview

klamath-rs is designed to handle large GDSII files with high performance. It uses Apache Arrow as its primary in-memory data representation, allowing for efficient memory usage and easy integration with other tools in the Arrow ecosystem (like pandas, polars, or DuckDB via Python bindings).

Documentation

Features

  • Fast parsing of GDSII files.
  • Efficient memory representation using Apache Arrow.
  • Support for common GDSII elements: SREF, AREF, Boundary, Path, Text, etc.
  • Optimized "batch" representations for rectangles and boundaries sharing the same layer.
  • C-compatible FFI for integration with other languages (e.g., Python).

Usage

read_path exports a library through the Arrow C Data Interface. Allocate initialized ArrowArray and ArrowSchema output structures, then check the returned status: 0 means success and -1 means failure. Only import the Arrow outputs after success; the caller owns their release callbacks. Failed calls leave the outputs unchanged. See test.py for a Python CFFI example.

last_error_message() returns a UTF-8, null-terminated error string, or null after a successful parser call. Errors belong to the calling thread. Copy the message before making another parser call on that thread, and before the thread exits; calls on other threads do not invalidate it. Parser panics that unwind are converted into errors.

For partial reads, call scan_bytes with a borrowed GDSII byte buffer to obtain cell ranges and references without decoding geometry. Pass the desired ranges to read_cells_bytes to load their full contents. Both calls use the same Arrow outputs and status/error handling as read_path:

int scan_bytes(const uint8_t *data, size_t size,
               struct ArrowArray *array, struct ArrowSchema *schema);
int read_cells_bytes(const uint8_t *data, size_t size,
                     const uint64_t *ranges, size_t range_count,
                     struct ArrowArray *array, struct ArrowSchema *schema);

ranges contains alternating inclusive start and exclusive end offsets, with two native-endian uint64_t values per cell. Each range must cover one complete cell. A null ranges pointer is accepted when range_count is zero. Likewise, null data is accepted for zero bytes and produces an ordinary parse error for the empty input. Nonempty buffers must be readable for the duration of the call; range values must be aligned. Exported Arrow data owns its storage independently of the input. See Arrow Schema Documentation for the scan schema, offset definitions, and ID assignment.