KLayout Python Module

0.30.7 · active · verified Thu Apr 16

KLayout is a layout viewer and editor primarily for integrated circuit layouts (GDSII, OASIS). The `klayout` Python package (v0.30.7) provides a standalone scripting interface to KLayout's powerful database and geometry manipulation functionalities, allowing users to programmatically create, modify, and analyze layouts without requiring the full graphical application. It maintains an active release cadence, with minor updates released frequently to address issues and enhance features, often multiple times a month.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a new GDSII layout, define a cell and layer, add a simple rectangular shape, and save the result using the `klayout.db` module.

import klayout.db as db

# Create a new layout object
layout = db.Layout()

# Set the database unit (DBU) to 1 nanometer (0.001 micrometers)
layout.dbu = 0.001

# Create a top cell named 'TOP'
top_cell = layout.create_cell("TOP")

# Define a layer (e.g., GDS layer 1, datatype 0)
layer_info = db.LayerInfo(1, 0)
layer_idx = layout.layer(layer_info)

# Add a box to the layer in the top cell
# Coordinates are in micrometers if DBU is 0.001 (e.g., 100x200 um)
box = db.DBox(0, 0, 100, 200)
top_cell.shapes(layer_idx).insert(box)

# Save the layout to a GDSII file
output_filename = "my_first_layout.gds"
layout.write(output_filename)

print(f"Layout '{output_filename}' created successfully.")

view raw JSON →