KLayout is a high performance layout viewer and editor that supports GDS and OASIS files and more formats
npx @tessl/cli install tessl/pypi-klayout@0.30.0KLayout is a comprehensive Electronic Design Automation (EDA) tool for integrated circuit layout viewing, editing, and verification. It serves as both a high-performance GUI application and a Python library for programmatic access to layout databases, supporting industry-standard formats like GDS-II and OASIS.
pip install klayoutimport klayout.db as db # Core database and geometric operations
import klayout.tl as tl # Template library utilities
import klayout.lay as lay # Layout viewer and GUI components
import klayout.rdb as rdb # Results database for DRC/LVS
import klayout.pya as pya # Unified API (all modules combined)Alternative unified import:
import pya # Legacy namespace providing all functionalityimport klayout.db as db
# Create a new layout
layout = db.Layout()
# Create a top cell
top_cell = layout.create_cell("TOP")
# Define a layer (layer 1, datatype 0)
layer_info = db.LayerInfo(1, 0)
layer = layout.layer(layer_info)
# Create geometric shapes
box = db.Box(0, 0, 1000, 1000) # coordinates in database units
polygon = db.Polygon([db.Point(0, 0), db.Point(1000, 0),
db.Point(1000, 1000), db.Point(0, 1000)])
# Add shapes to the cell
top_cell.shapes(layer).insert(box)
top_cell.shapes(layer).insert(polygon)
# Save to GDS file
layout.write("output.gds")
# Read from GDS file
input_layout = db.Layout()
input_layout.read("input.gds")KLayout's modular architecture provides comprehensive EDA functionality:
The design supports both interactive GUI usage and programmatic automation, making it suitable for mask layout viewing, editing, design rule checking (DRC), layout versus schematic (LVS) verification, and custom EDA tool development.
Core layout database functionality including geometric primitives, transformations, hierarchical cell management, and comprehensive shape manipulation operations for IC layout design.
class Layout:
def create_cell(self, name: str) -> Cell: ...
def read(self, filename: str) -> None: ...
def write(self, filename: str) -> None: ...
def layer(self, layer_info: LayerInfo) -> int: ...
class Cell:
def shapes(self, layer: int) -> Shapes: ...
def insert(self, instance: CellInstArray) -> CellInstArray: ...
class Box:
def __init__(self, left: int, bottom: int, right: int, top: int): ...
class Polygon:
def __init__(self, points: list[Point]): ...Database and Geometric Operations
Comprehensive support for reading and writing various EDA file formats including GDS-II, OASIS, CIF, DXF, LEF/DEF, and more, with configurable import/export options.
class LoadLayoutOptions:
def __init__(self): ...
def select_cell(self, cell_name: str) -> None: ...
class SaveLayoutOptions:
def __init__(self): ...
def set_format(self, format: str) -> None: ...Geometric transformations including rotation, mirroring, scaling, and translation operations for precise layout manipulation and coordinate system conversions.
class Trans:
def __init__(self, rotation: int, mirror: bool, displacement: Point): ...
class CplxTrans:
def __init__(self, mag: float, rotation: float, mirror: bool, displacement: DPoint): ...
class Matrix3d:
def __init__(self): ...
def rotate(self, angle: float) -> Matrix3d: ...Transformations and Coordinates
Advanced geometric operations including boolean operations (AND, OR, XOR, NOT), sizing, merging, and comprehensive region analysis for layout verification and processing.
class Region:
def __init__(self, shapes=None): ...
def __and__(self, other: Region) -> Region: ...
def __or__(self, other: Region) -> Region: ...
def sized(self, dx: int, dy: int = None) -> Region: ...
def merged(self) -> Region: ...Shape Collections and Boolean Operations
Cell hierarchy management, instance creation and manipulation, library organization, and parametric cell (PCell) support for reusable design components.
class CellInstArray:
def __init__(self, cell_index: int, trans: Trans): ...
class PCellDeclarationHelper:
def __init__(self, name: str): ...
def param(self, name: str, type: type, description: str): ...
def produce_impl(self) -> None: ...GUI components for layout visualization, user interaction, layer management, and display customization when running in GUI mode.
class LayoutView:
def __init__(self): ...
def load_layout(self, layout: Layout) -> int: ...
def zoom_fit(self) -> None: ...
class LayerPropertiesNode:
def __init__(self): ...
def source_layer_info(self) -> LayerInfo: ...Design rule checking (DRC), layout versus schematic (LVS) capabilities, and results database management for storing and analyzing verification reports.
class ReportDatabase:
def __init__(self, name: str): ...
def create_category(self, name: str) -> Category: ...
class Category:
def create_item(self, polygon: Polygon) -> Item: ...class Point:
def __init__(self, x: int, y: int): ...
x: int
y: int
class DPoint:
def __init__(self, x: float, y: float): ...
x: float
y: float
class LayerInfo:
def __init__(self, layer: int, datatype: int = 0): ...
layer: int
datatype: int
class Shapes:
def insert(self, shape) -> None: ...
def each(self) -> Iterator: ...