or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

database-operations.mdfile-io.mdhierarchical-design.mdindex.mdlayout-viewer.mdshape-operations.mdtransformations.mdverification.md
tile.json

tessl/pypi-klayout

KLayout is a high performance layout viewer and editor that supports GDS and OASIS files and more formats

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/klayout@0.30.x

To install, run

npx @tessl/cli install tessl/pypi-klayout@0.30.0

index.mddocs/

KLayout

KLayout 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.

Package Information

  • Package Name: klayout
  • Language: Python (with C++ extensions)
  • Installation: pip install klayout
  • Version: 0.30.3
  • License: GPL-3.0-or-later

Core Imports

import 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 functionality

Basic Usage

import 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")

Architecture

KLayout's modular architecture provides comprehensive EDA functionality:

  • Database Core (klayout.db): Layout storage, geometric primitives, transformations, and file I/O
  • Template Library (klayout.tl): Core utilities, progress reporting, and system integration
  • Layout Viewer (klayout.lay): GUI components for visualization and user interaction
  • Results Database (klayout.rdb): Storage and management of verification results
  • Unified API (klayout.pya): Complete API combining all modules for backward compatibility

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.

Capabilities

Database and Geometric Operations

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

File I/O and Format Support

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: ...

File I/O and Formats

Layout Transformations and Coordinates

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

Shape Collections and Boolean Operations

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

Hierarchical Design and Cell Management

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: ...

Hierarchical Design

Layout Viewer and GUI Components

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: ...

Layout Viewer and GUI

Verification and Results Management

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: ...

Verification and Results

Types

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: ...