or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

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

0

# KLayout

1

2

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.

3

4

## Package Information

5

6

- **Package Name**: klayout

7

- **Language**: Python (with C++ extensions)

8

- **Installation**: `pip install klayout`

9

- **Version**: 0.30.3

10

- **License**: GPL-3.0-or-later

11

12

## Core Imports

13

14

```python

15

import klayout.db as db # Core database and geometric operations

16

import klayout.tl as tl # Template library utilities

17

import klayout.lay as lay # Layout viewer and GUI components

18

import klayout.rdb as rdb # Results database for DRC/LVS

19

import klayout.pya as pya # Unified API (all modules combined)

20

```

21

22

Alternative unified import:

23

```python

24

import pya # Legacy namespace providing all functionality

25

```

26

27

## Basic Usage

28

29

```python

30

import klayout.db as db

31

32

# Create a new layout

33

layout = db.Layout()

34

35

# Create a top cell

36

top_cell = layout.create_cell("TOP")

37

38

# Define a layer (layer 1, datatype 0)

39

layer_info = db.LayerInfo(1, 0)

40

layer = layout.layer(layer_info)

41

42

# Create geometric shapes

43

box = db.Box(0, 0, 1000, 1000) # coordinates in database units

44

polygon = db.Polygon([db.Point(0, 0), db.Point(1000, 0),

45

db.Point(1000, 1000), db.Point(0, 1000)])

46

47

# Add shapes to the cell

48

top_cell.shapes(layer).insert(box)

49

top_cell.shapes(layer).insert(polygon)

50

51

# Save to GDS file

52

layout.write("output.gds")

53

54

# Read from GDS file

55

input_layout = db.Layout()

56

input_layout.read("input.gds")

57

```

58

59

## Architecture

60

61

KLayout's modular architecture provides comprehensive EDA functionality:

62

63

- **Database Core (klayout.db)**: Layout storage, geometric primitives, transformations, and file I/O

64

- **Template Library (klayout.tl)**: Core utilities, progress reporting, and system integration

65

- **Layout Viewer (klayout.lay)**: GUI components for visualization and user interaction

66

- **Results Database (klayout.rdb)**: Storage and management of verification results

67

- **Unified API (klayout.pya)**: Complete API combining all modules for backward compatibility

68

69

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.

70

71

## Capabilities

72

73

### Database and Geometric Operations

74

75

Core layout database functionality including geometric primitives, transformations, hierarchical cell management, and comprehensive shape manipulation operations for IC layout design.

76

77

```python { .api }

78

class Layout:

79

def create_cell(self, name: str) -> Cell: ...

80

def read(self, filename: str) -> None: ...

81

def write(self, filename: str) -> None: ...

82

def layer(self, layer_info: LayerInfo) -> int: ...

83

84

class Cell:

85

def shapes(self, layer: int) -> Shapes: ...

86

def insert(self, instance: CellInstArray) -> CellInstArray: ...

87

88

class Box:

89

def __init__(self, left: int, bottom: int, right: int, top: int): ...

90

91

class Polygon:

92

def __init__(self, points: list[Point]): ...

93

```

94

95

[Database and Geometric Operations](./database-operations.md)

96

97

### File I/O and Format Support

98

99

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.

100

101

```python { .api }

102

class LoadLayoutOptions:

103

def __init__(self): ...

104

def select_cell(self, cell_name: str) -> None: ...

105

106

class SaveLayoutOptions:

107

def __init__(self): ...

108

def set_format(self, format: str) -> None: ...

109

```

110

111

[File I/O and Formats](./file-io.md)

112

113

### Layout Transformations and Coordinates

114

115

Geometric transformations including rotation, mirroring, scaling, and translation operations for precise layout manipulation and coordinate system conversions.

116

117

```python { .api }

118

class Trans:

119

def __init__(self, rotation: int, mirror: bool, displacement: Point): ...

120

121

class CplxTrans:

122

def __init__(self, mag: float, rotation: float, mirror: bool, displacement: DPoint): ...

123

124

class Matrix3d:

125

def __init__(self): ...

126

def rotate(self, angle: float) -> Matrix3d: ...

127

```

128

129

[Transformations and Coordinates](./transformations.md)

130

131

### Shape Collections and Boolean Operations

132

133

Advanced geometric operations including boolean operations (AND, OR, XOR, NOT), sizing, merging, and comprehensive region analysis for layout verification and processing.

134

135

```python { .api }

136

class Region:

137

def __init__(self, shapes=None): ...

138

def __and__(self, other: Region) -> Region: ...

139

def __or__(self, other: Region) -> Region: ...

140

def sized(self, dx: int, dy: int = None) -> Region: ...

141

def merged(self) -> Region: ...

142

```

143

144

[Shape Collections and Boolean Operations](./shape-operations.md)

145

146

### Hierarchical Design and Cell Management

147

148

Cell hierarchy management, instance creation and manipulation, library organization, and parametric cell (PCell) support for reusable design components.

149

150

```python { .api }

151

class CellInstArray:

152

def __init__(self, cell_index: int, trans: Trans): ...

153

154

class PCellDeclarationHelper:

155

def __init__(self, name: str): ...

156

def param(self, name: str, type: type, description: str): ...

157

def produce_impl(self) -> None: ...

158

```

159

160

[Hierarchical Design](./hierarchical-design.md)

161

162

### Layout Viewer and GUI Components

163

164

GUI components for layout visualization, user interaction, layer management, and display customization when running in GUI mode.

165

166

```python { .api }

167

class LayoutView:

168

def __init__(self): ...

169

def load_layout(self, layout: Layout) -> int: ...

170

def zoom_fit(self) -> None: ...

171

172

class LayerPropertiesNode:

173

def __init__(self): ...

174

def source_layer_info(self) -> LayerInfo: ...

175

```

176

177

[Layout Viewer and GUI](./layout-viewer.md)

178

179

### Verification and Results Management

180

181

Design rule checking (DRC), layout versus schematic (LVS) capabilities, and results database management for storing and analyzing verification reports.

182

183

```python { .api }

184

class ReportDatabase:

185

def __init__(self, name: str): ...

186

def create_category(self, name: str) -> Category: ...

187

188

class Category:

189

def create_item(self, polygon: Polygon) -> Item: ...

190

```

191

192

[Verification and Results](./verification.md)

193

194

## Types

195

196

```python { .api }

197

class Point:

198

def __init__(self, x: int, y: int): ...

199

x: int

200

y: int

201

202

class DPoint:

203

def __init__(self, x: float, y: float): ...

204

x: float

205

y: float

206

207

class LayerInfo:

208

def __init__(self, layer: int, datatype: int = 0): ...

209

layer: int

210

datatype: int

211

212

class Shapes:

213

def insert(self, shape) -> None: ...

214

def each(self) -> Iterator: ...

215

```