On This Page (11)
SchLib
AltiumSchLib is the public container for schematic libraries. Each library contains one or more AltiumSymbol objects.
Use it when you need to:
- create schematic symbols
- mutate existing symbols
- split or merge schematic libraries
- extract symbols from schematic documents
- render symbols and multipart symbols to SVG
- inventory symbols and extract one selected symbol
Object Model
AltiumSymbol uses the same ObjectCollection pattern as AltiumSchDoc. Symbol properties such as symbol.pins, symbol.parameters, symbol.rectangles, symbol.lines, and symbol.arcs are typed query views. AltiumSchLib.symbols, AltiumSymbol.objects, and these typed accessors are read-only live views. Use AltiumSchLib.add_symbol() / remove_symbol() and AltiumSymbol.add_object() / remove_object() for structural changes instead of appending to or replacing a returned view.
Rename a library-owned symbol with schlib.rename_symbol(symbol_or_storage_name, storage_name, original_name=None). String selection is exact and case-sensitive and uses the current OLE storage key, not the semantic library reference. Omitting original_name preserves that semantic reference. The operation validates and serializes a candidate before changing live state, moves the complete symbol storage subtree, and returns the same owned symbol object.
Add symbol records with symbol.add_object(...) or symbol helper methods. Keep visual ordering in mind: body graphics should usually be behind pins and text. That order is preserved when a symbol is inserted into a SchDoc through AltiumSchDoc.add_component_from_library(...) and when placed symbols are extracted back to SchLib.
Designator vs. Parameters
In Altium .SchLib files, a symbol's default designator (such as R? or U?) is stored in a dedicated AltiumSchDesignator record, not as a normal AltiumSchParameter. Read or mutate it through symbol.designators (or add one with symbol.add_designator("U?", ...)) rather than adding a Parameter named "Designator" (which creates a separate custom parameter instead of changing the symbol's default designator).
Note that AltiumSchDesignator subclasses AltiumSchParameter in Python, so symbol.parameters includes designator records alongside regular parameters. To iterate only regular parameters, filter out designators:
from altium_monkey import AltiumSchDesignator
regular_params = [
p for p in symbol.parameters if not isinstance(p, AltiumSchDesignator)
]Multi-Function Pin Authoring
make_sch_pin(...) and AltiumSchPin(...) accept optional defined_functions: Sequence[str] = () and selected_functions: Sequence[str] = () keyword arguments for Altium's PinFunctionData (multi-function / pin-swap function lists):
pin = make_sch_pin(
name="PA0",
designator="1",
location=(0, 0),
defined_functions=["GPIO_A0", "SPI1_MOSI", "TIM2_CH1"],
selected_functions=["SPI1_MOSI"],
)
symbol.add_object(pin)Pass a sequence of function name strings (for example list[str] or tuple[str, ...]); passing a bare str or bytes raises TypeError to avoid iterating single characters. Existing library reads remain Altium-tolerant and preserve whatever function lists are authored in source .SchLib files.
Units
Public SchLib authoring APIs use mils for geometry. Use public helpers and enums for pins, fonts, and drawing styles. Avoid raw pin binary fields unless you are doing serializer-level preservation work.
Public Pattern
Create or load a library, add or find a symbol, mutate the symbol, then save:
schlib = AltiumSchLib()
symbol = schlib.add_symbol("MY_SYMBOL")
symbol.add_object(make_sch_pin(...))
schlib.save("my_symbols.SchLib")Pass show_comments_designators=True when creating a library if Altium should open the SchLib editor with symbol comments and designators visible:
schlib = AltiumSchLib(show_comments_designators=True)You can also set schlib.show_comments_designators = True before saving.
For parsed libraries, prefer AltiumSchLib.get_symbol(...) and symbol views over scanning raw streams.
Legacy Auxiliary-Stream Compatibility
AltiumSchLib accepts bounded legacy PinTextData and embedded-image Storage streams that Altium itself imports even when their header termination, row names, or declared count is noncanonical. Selected rows are still checked for valid framing, compression, and payload shape; unrelated corruption remains an error. PinTextData aliases apply in source order, including later default rows that clear earlier custom settings. Storage validates and budgets every selected row, then retains the first case-insensitive name for image lookup. An unchanged PinTextData stream is preserved exactly. A semantic PinTextData synchronization writes the current canonical zero-based form and does not retain source rows that Altium ignored.
Extraction From SchDoc
AltiumSchDoc.extract_schlib(...) returns an in-memory AltiumSchLib built from the placed component symbols in a schematic. Use it when another API wants to inspect, render, merge, or save the extracted library without first writing split files.
AltiumSchDoc.extract_symbols(...) remains the file-oriented helper for split or combined .SchLib output. It uses the same extraction model as extract_schlib(...).
Extractable Assets
AltiumSchLib.asset_inventory() lists library symbols with typed SchSymbolAssetDetails. Use the returned ref with extract_asset(...) when a tool needs exactly one symbol as a new single-symbol AltiumSchLib.
inventory = schlib.asset_inventory()
symbol = next(
(item for item in inventory.by_kind("sch_symbol") if item.can_extract),
None,
)
if symbol is None:
raise RuntimeError("no extractable schematic symbol found")
selected = schlib.extract_asset(symbol.ref)
selected.schlib.save("selected_symbol.SchLib")For the shared reference and JSON contract, see Asset & Library Extraction.
SVG & Paint IR Rendering
AltiumSchLib.symbol_to_svg(...), to_svg(...), symbol_to_paint_ir(...), and symbol_to_paint_png(...) render library symbols through Schematic Paint IR A0:
from altium_monkey import AltiumSchLib, SchPaintSvgOptions
schlib = AltiumSchLib("parts.SchLib")
svg = schlib.symbol_to_svg(
"OPAMP_DUAL",
part_id=1,
display_mode=0,
options=SchPaintSvgOptions(text_mode="paths"),
)
scene = schlib.symbol_to_paint_ir("OPAMP_DUAL", part_id=1, display_mode=0)
png_bytes = schlib.symbol_to_paint_png("OPAMP_DUAL", part_id=1, display_mode=0)Key rules:
- Normal output includes a root
viewBox; setinclude_view_box=Falseto omit only that attribute. embed_bundled_fallback_fonts=Trueis not supported and raisesSchPaintRenderError; usetext_mode="paths"for portable self-contained SVGs that do not depend on viewer fonts.to_svg(output_dir=...)renders every symbol/part in the library using safe, collision-resolved filenames. Pass explicitpart_idanddisplay_modetosymbol_to_svg(...)orsymbol_to_paint_ir(...)to target a specific view.
See the Schematic Rendering & Paint IR guide (including legacy GOTIR migration).
Guarantees & Stability Boundaries
- Child draw order: Symbol child order is part of the visible contract;
AltiumSchDoc.add_component_from_library(...)preserves symbol order andextract_schlib(...)writes children back in placed order. - Editor display option:
AltiumSchLib(show_comments_designators=True)writesAlwaysShowCD=TinFileHeader; the default remainsFalse. - Auxiliary streams:
PinTextDataand embedded-imageStorageuse bounded declared-prefix semantics; cleanPinTextDatasaves preserve source bytes unless explicitly synchronized.
Examples
Start with:
hello_schlibschlib_find_symbolschlib_splitschlib_mergeschlib_svgschdoc_extract_schlibextractable_asset_inventory
See API patterns for the shared ObjectCollection rules used by SchDoc and SchLib.