Python » ROOM » Lib

Lib

Named library of cells inside a Database. In Python there is no separate Lib type — the same data is accessed on Database (C++: room::Lib). More…

Import:import room
Access:via db = room.open(...) — library API is on db
C++:room::Lib (db.lib())

Notation: name() = method (call it). lib_name = attribute (read/assign, no call).

Public API (on Database)

lib_nameAttribute — library name (str, read/write).
cells()Method — all cells as list[Cell].
cell_names()Method — list of cell name strings.
layers()Method — shared layer table as list[Layer].
add_layer(layer_num, data_type=0, name="", purpose=...)Method — append a layer; returns its index.
find_cell(name)Method — lookup cell by name, or None.
get_or_create_cell(name)Method — return existing cell or create an empty one.

Detailed Description

A ROOM file contains exactly one library (default name "default"). The library holds the cell inventory and a shared layer table. Shape layer_id values index into that table (not raw GDS layer numbers).

In C++ you write db.lib().cells(). In Python the same operations are on Database:

C++ (db.lib())Python (db)
name()lib_name (attribute)
cells()cells() / cell_names()
layers()layers() / add_layer(...)
findCell(name)find_cell(name)
getOrCreateCell(name)get_or_create_cell(name)
properties() / refreshIndex()not yet exposed in Python

Member documentation

lib_name: str

Attribute (no parentheses). Name of the library stored in the .room file (C++ Lib::name()). Readable and writable: db.lib_name = "stdcells". Default for a new database is "default".

cells() → list[Cell]

Method. All cells in this library (C++ Lib::cells()). Each element is a Cell handle into the same database.

Returns: list of Cell objects (may be empty).

cell_names() → list[str]

Method. Convenience helper: returns only the cell names. Equivalent to [c.name() for c in db.cells()].

Returns: list of cell name strings.

layers() → list[Layer]

Method. Shared layer catalog for the library (C++ Lib::layers() / LayerSpec). Each Layer has layer_num, data_type, name, and purpose. Shape layer_id values refer to indices in this list.

add_layer(layer_num, data_type=0, name="", purpose=LayerPurpose.DRAWING) → int

Appends a layer to the library table and returns its index (usable as layer_id in add_rect).

ParameterDescription
layer_numGDS layer number.
data_typeGDS datatype (default 0).
nameOptional human-readable name (e.g. "Metal1").
purposeLayerPurpose enum (default DRAWING).

Returns: zero-based index of the new layer.

find_cell(name: str) → Cell | None

Exact-name lookup (C++ Lib::findCell). Returns None if no cell with that name exists.

ParameterDescription
nameCell name to find.

get_or_create_cell(name: str) → Cell

Returns the existing cell with this name, or appends a new empty cell (C++ Lib::getOrCreateCell).

ParameterDescription
nameCell name. Created cells start with no view contents until ensure_content.

Returns: Cell handle.

Example

import room
from room import LayerPurpose

db = room.create()
db.lib_name = "stdcells"
idx = db.add_layer(1, 0, "Metal1", LayerPurpose.DRAWING)

cell = db.get_or_create_cell("INVX1")
layout = cell.ensure_content("layout")
layout.add_rect(idx, 0, 0, 100, 200)

print(db.cell_names())          # ['INVX1']
print(db.find_cell("INVX1").name())
for layer in db.layers():
    print(layer.layer_num, layer.data_type, layer.name)