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 — 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 cellsAttributes
attributenamestrLibrary name.
Methods
func__init__(name) -> NoneCreate a new empty library.
paramnamestrLibrary name.
Returns
Nonefuncadd_cell(cell) -> NoneAdd a cell to the library.
If a cell with the same name already exists, it is silently skipped.
paramcellCellThe cell to add.
Returns
Nonefuncadd_cell_recursive(cell, available_cells) -> NoneAdd 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.
paramcellCellThe cell to add (typically the top-level cell).
paramavailable_cellslist[Cell]List of all cells that may be referenced.
Returns
Nonefunccell(name) -> Cell | NoneGet a cell by name, or None if not found.
paramnamestrCell name to look up.
Returns
Cell | Nonefunccells() -> list[Cell]Get all cells in the library.
Returns
list[Cell]functop_cell() -> Cell | NoneGet the top cell (last added), or None if the library is empty.
Returns
Cell | None