Library

A container for multiple cells.

Libraries group cells together for GDS I/O. When using write_gds() with a single Cell built using Instance references (via cell.at()), child cells are auto-collected, so you typically don't need to create a Library manually.

Libraries are primarily useful when reading GDS files with read_gds() or when you need explicit control over which cells are included.

# Reading: read_gds returns a Library
lib = read_gds("input.gds")
top = lib.top_cell()
for cell in lib.cells():
    print(cell.name)

# Writing: usually not needed (write_gds auto-collects)
write_gds("output.gds", top_cell)  # Auto-collects child cells

Attributes

attributenamestr

Library name.

Methods

func__init__(name) -> None

Create a new empty library.

paramnamestr

Library name.

Returns

None
funcadd_cell(cell) -> None

Add a cell to the library.

If a cell with the same name already exists, it is silently skipped.

paramcellCell

The cell to add.

Returns

None
funcadd_cell_recursive(cell, available_cells) -> None

Add a cell and all its referenced cells recursively.

This method automatically adds all cells that are referenced by the given cell, resolving the entire hierarchy. You must provide a list of all available cells that may be referenced. Cells that already exist in the library (by name) are skipped.

paramcellCell

The cell to add (typically the top-level cell).

paramavailable_cellslist[Cell]

List of all cells that may be referenced.

Returns

None
funccell(name) -> Cell | None

Get a cell by name, or None if not found.

paramnamestr

Cell name to look up.

Returns

Cell | None
funccells() -> list[Cell]

Get all cells in the library.

Returns

list[Cell]
functop_cell() -> Cell | None

Get the top cell (last added), or None if the library is empty.

Returns

Cell | None
funccell_bbox(name) -> BBox | None

Calculate the fully-resolved bounding box of a cell in this library.

Unlike Cell.bbox(), this recursively resolves every cell reference (SREF and AREF) and expands array repetitions, so the returned box covers everything that would appear when the cell is rendered or written to GDS.

lib = Library("design")
lib.add_cell(unit)
lib.add_cell(top)  # contains a 5x3 AREF of `unit`
bb = lib.cell_bbox("top")  # covers all 15 copies
paramnamestr

Name of the cell to measure.

Returns

BBox | None

Returns None if the cell does not exist or contains no geometry.

On this page