On This Page (6)
Projects & Design
KiCadProject, KiCadDesign, variants, sidecar metadata, and multi-sheet compilation.
6 public symbols.
KiCadDesign
classfrom kicad_monkey import KiCadDesign
class KiCadDesign(project: 'Optional[KiCadProject]' = None, schematics: "list['KiCadSchematic']" = <factory>, pcb_path: 'Optional[Path]' = None, project_path: 'Optional[Path]' = None, _pcb: "Optional['KiCadPcb']" = None, _netlist: "Optional['KiCadNetlist']" = None) -> 'None'
Composed KiCad design: project + schematics + (lazy) PCB.
Construct via the ``from_*`` classmethods; direct construction is
supported for tests but won't auto-populate adjacent files.
Members (35)
| Member | Kind | Signature | Summary |
|---|---|---|---|
add_schematic | method | (self, schematic: "'KiCadSchematic'") -> "'KiCadSchematic'" | Append a schematic to this design. |
child_schematic_instances | method | (self, instance_or_sheet_path: 'KiCadSchematicInstance | str') -> 'list[KiCadSchematicInstance]' | Return immediate child schematic instances for a hierarchy instance. |
find_schematic_instances | method | (self, *, schematic: "Optional['KiCadSchematic']" = None, source_path: 'Path | str | None' = None, sheet_path: 'str | None' = None, sheet_instance_path: 'str | None' = None, sheet_name: 'str | None' = None) -> 'list[KiCadSchematicInstance]' | Find hierarchy instances by schematic object, source path, or sheet path. |
from_file | classmethod | (cls, path: 'Path | str') -> "'KiCadDesign'" | Load a design from a `.kicad_pro`, `.kicad_sch`, or `.kicad_pcb` path. |
from_pcb_file | classmethod | (cls, path: 'Path | str') -> "'KiCadDesign'" | Load a `.kicad_pcb` (lazily) and any adjacent `.kicad_pro` |
from_project_file | classmethod | (cls, path: 'Path | str') -> "'KiCadDesign'" | Load `.kicad_pro` and any adjacent top-level `.kicad_sch` / |
from_schematic_file | classmethod | (cls, path: 'Path | str') -> "'KiCadDesign'" | Load a `.kicad_sch` (with recursive sub-sheets) and any |
get_component | method | (self, reference: 'str') -> "Optional['KiCadNetlistComponent']" | Look up a component by reference designator. |
get_net | method | (self, name: 'str') -> "Optional['KiCadNet']" | Look up a compiled net by name. |
iter_objects | method | (self, *, include_pcb: 'bool' = True) -> 'Iterator[object]' | Iterate over project, schematic, and optional PCB documents. |
iter_schematic_instances | method | (self) -> 'Iterator[KiCadSchematicInstance]' | Iterate concrete schematic placements in hierarchy order. |
iter_schematics | method | (self) -> "Iterator['KiCadSchematic']" | Iterate over schematics owned by this design. |
netlist_diagnostics | method | (self) -> 'list' | Info diagnostics for what KiCad's netlist does with multi-unit parts. |
objects | property | | Live read-only query view over design-owned documents. |
parent_schematic_instance | method | (self, instance_or_sheet_path: 'KiCadSchematicInstance | str') -> 'KiCadSchematicInstance | None' | Return the parent hierarchy instance for a schematic instance. |
pcb | property | -> "Optional['KiCadPcb']" | Loaded :class:`KiCadPcb`, parsing on first access. |
refresh_netlist | method | (self) -> "'KiCadNetlist'" | Discard the cached netlist and recompile from scratch. |
remove_schematic | method | (self, schematic: "'KiCadSchematic'") -> 'bool' | Remove a schematic by identity. |
root_sheet_name | property | -> 'str' | The root sheet's name as KiCad 10.0.8 loads the design. |
save_json | method | (self, path: 'Path | str', *, include_indexes: 'bool' = True, include_pcb: 'bool' = True, indent: 'int' = 2) -> 'None' | Write :meth:`to_json_text` to disk. |
schematic_diagnostics | method | (self) -> 'list' | What loading repaired instead of stopping, for every loaded file. |
schematic_instances | method | (self) -> 'list[KiCadSchematicInstance]' | Return concrete schematic placements in hierarchy order. |
schematic_instances_for | method | (self, schematic_or_path: "'KiCadSchematic | Path | str'") -> 'list[KiCadSchematicInstance]' | Return every hierarchy use of a schematic object or source file. |
text_variables | property | -> 'dict[str, str]' | Project-scoped ``${VAR}`` substitutions. |
to_json | method | (self, include_indexes: 'bool' = True, *, include_pcb: 'bool' = True) -> 'dict' | Render a KiCad-native design JSON payload. |
to_json_text | method | (self, *, include_indexes: 'bool' = True, include_pcb: 'bool' = True, indent: 'int' = 2) -> 'str' | Render :meth:`to_json` as formatted JSON text. |
to_kicad_netlist_json | method | (self) -> 'dict' | Render the internal netlist as a KiCad-native raw JSON payload. |
to_kicad_netlist_sexpr | method | (self, *, tool: 'str' = 'kicad_monkey', date: 'Optional[str]' = None) -> 'str' | Render the design as a kicad-cli–style ``(export ...)`` netlist. |
to_netlist | method | (self) -> "'KiCadNetlist'" | Compile (and cache) the unified design netlist. |
to_netlist_json | method | (self) -> 'dict' | Render the design as a KiCad-native netlist JSON payload. |
to_pcb_ir | method | (self, *, document_id: 'Optional[str]' = None) -> "'KiCadPlotterDocument'" | Convert the associated PCB to plotter IR. |
to_pcb_svg | method | (self, **kwargs) -> 'str' | Render the associated PCB to SVG. |
to_schematic_instance_ir | method | (self, instance: 'KiCadSchematicInstance', *, document_id: 'str | None' = None, extra_vars: 'Optional[dict]' = None, diagnostics: 'Optional[list]' = None) -> "'KiCadPlotterDocument'" | Convert one concrete schematic hierarchy instance to plotter IR. |
to_schematic_ir | method | (self, schematic: "Optional['KiCadSchematic']" = None, *, sheet_index: 'int' = 1, sheet_count: 'int' = 1, sheet_path: 'str' = '/', sheet_instance_path: 'Optional[str]' = None, sheet_name: 'str' = '', document_id: 'Optional[str]' = None, extra_vars: 'Optional[dict]' = None, diagnostics: 'Optional[list]' = None) -> "'KiCadPlotterDocument'" | Convert a schematic to a :class:`KiCadPlotterDocument` with |
top_schematic | property | -> "Optional['KiCadSchematic']" | First-loaded entry-point schematic, if any. |
KiCadProject
classfrom kicad_monkey import KiCadProject
class KiCadProject(project_path: 'Path | None' = None, text_variables: 'dict[str, str]' = <factory>, net_settings: 'KiCadProjectNetSettings | None' = None, board_design_settings: 'KiCadProjectBoardDesignSettings | None' = None, variants: 'list[ProjectVariant]' = <factory>, raw: 'dict[str, Any]' = <factory>, name: 'str' = '', directory: 'Path | None' = None, schematic: "'KiCadSchematic | None'" = None, pcb: "'KiCadPcb | None'" = None, symbol_library_table: "'KiCadLibraryTable | None'" = None, footprint_library_table: "'KiCadLibraryTable | None'" = None, worksheet_path: 'Path | None' = None) -> 'None'
Typed `.kicad_pro` project view and project-creation aggregate.
This is the canonical reader for KiCad project files. The full
parsed JSON is preserved verbatim in :attr:`raw` so the write/save path
can round-trip without loss; typed views like :attr:`variants` and
:attr:`net_settings` and :attr:`bus_aliases` are derived from it.
For scaffolding new project folders, use :meth:`create`. It starts a blank
project bound to an on-disk directory; :meth:`add_schematic`,
:meth:`add_pcb`, :meth:`add_symbol_library`, and
:meth:`add_footprint_library` attach the pieces through the object model;
:meth:`write_project` writes the folder. Higher layers drive these methods
from their own input, so this class holds no knowledge of how inputs are
gathered.
Members (29)
| Member | Kind | Signature | Summary |
|---|---|---|---|
add_footprint_library | method | (self, nickname: 'str', uri: 'str', *, library_type: 'str' = 'KiCad') -> 'Any' | Seed the project footprint library table with a referenced library. |
add_pcb | method | (self, *, page_size: 'str' = 'A4') -> "'KiCadPcb'" | Attach a blank board with KiCad's default layer stack and return it. |
add_schematic | method | (self, *, sheet_name: 'str | None' = None, page_size: 'str' = 'A4', revision: 'str' = '', company: 'str' = '', date: 'str' = '', comments: 'list[str] | None' = None) -> "'KiCadSchematic'" | Attach a blank top-level schematic and return it. |
add_symbol_library | method | (self, nickname: 'str', uri: 'str', *, library_type: 'str' = 'KiCad') -> 'Any' | Seed the project symbol library table with a referenced library. |
add_variant | method | (self, name: 'str', description: 'str | None' = None) -> 'ProjectVariant' | Append a variant to the catalog. |
bus_aliases | property | -> 'dict[str, list[str]]' | Return a fresh normalized view of KiCad 10 project bus aliases. |
create | classmethod | (cls, name: 'str', directory: 'Path | str', *, project_path: 'Path | str | None' = None) -> "'KiCadProject'" | Start a blank, writable project bound to an on-disk directory. |
ensure_library_tables | method | (self) -> 'None' | Attach empty symbol and footprint library tables if not present. |
exact_source_text_variables | method | (self) -> 'tuple[tuple[str, str], ...]' | Read exact supported string variables from the acquired raw snapshot. |
from_file | classmethod | (cls, path: 'Path | str') -> "'KiCadProject'" | |
from_json_dict | classmethod | (cls, data: 'dict[str, Any]', *, project_path: 'Path | str | None' = None) -> "'KiCadProject'" | Build a project view from a parsed `.kicad_pro` JSON dict. |
from_text | classmethod | (cls, text: 'str', *, project_path: 'Path | str | None' = None) -> "'KiCadProject'" | |
get_path | method | (self, dotted_key: 'str', default: 'Any' = None) -> 'Any' | Read a value out of :attr:`raw` by dotted JSON path. |
get_text_variable | method | (self, name: 'str', default: 'str' = '') -> 'str' | Return a project text variable value. |
get_variant | method | (self, name: 'str') -> 'ProjectVariant | None' | Return a project variant by name. |
iter_variants | method | (self) -> 'Iterator[ProjectVariant]' | Iterate over project variants. |
remove_text_variable | method | (self, name: 'str') -> 'bool' | Remove a project text variable by name. |
remove_variant | method | (self, name: 'str') -> 'ProjectVariant | None' | Remove a variant by name; return the removed entry or None. |
rename_variant | method | (self, old_name: 'str', new_name: 'str') -> 'bool' | Rename a variant in the catalog. |
root_sheet_name | method | (self, root_schematic_file: 'str', *, project_name: 'str | None' = None, file_exists: 'Callable[[str], bool] | None' = None) -> 'str' | The name KiCad 10.0.8 gives the root sheet, as ``${SHEETNAME}`` shows it. |
save | method | (self, path: 'Path | str | None' = None) -> 'None' | Write :meth:`to_text` to disk. |
set_path | method | (self, dotted_key: 'str', value: 'Any') -> 'None' | Set a value in :attr:`raw` by dotted JSON path. |
set_text_variable | method | (self, name: 'str', value: 'str') -> 'None' | Set a project text variable in both typed state and raw JSON. |
set_worksheet | method | (self, path: 'Path | str', *, embed: 'bool' = True) -> 'None' | Reference (or embed) a ``.wks`` drawing sheet for the schematic. |
to_file | method | (self, path: 'Path | str | None' = None) -> 'None' | Deprecated alias for :meth:`save`. |
to_json | method | (self) -> 'dict[str, Any]' | Return the project JSON object preserved for round-trip writes. |
to_text | method | (self) -> 'str' | Serialize :attr:`raw` back to JSON, byte-equal with KiCad. |
top_level_sheets | method | (self) -> 'list[tuple[str, str]]' | ``schematic.top_level_sheets``: each entry's ``(filename, name)``. |
write_project | method | (self, directory: 'Path | str | None' = None) -> 'KiCadProjectFiles' | Write the whole project folder and return the written paths. |
KiCadProjectSidecar
classfrom kicad_monkey import KiCadProjectSidecar
class KiCadProjectSidecar(project_path: 'Path | None' = None, text_variables: 'dict[str, str]' = <factory>, net_settings: 'KiCadProjectNetSettings | None' = None, board_design_settings: 'KiCadProjectBoardDesignSettings | None' = None, variants: 'list[ProjectVariant]' = <factory>, raw: 'dict[str, Any]' = <factory>, name: 'str' = '', directory: 'Path | None' = None, schematic: "'KiCadSchematic | None'" = None, pcb: "'KiCadPcb | None'" = None, symbol_library_table: "'KiCadLibraryTable | None'" = None, footprint_library_table: "'KiCadLibraryTable | None'" = None, worksheet_path: 'Path | None' = None) -> 'None'
Typed `.kicad_pro` project view and project-creation aggregate.
This is the canonical reader for KiCad project files. The full
parsed JSON is preserved verbatim in :attr:`raw` so the write/save path
can round-trip without loss; typed views like :attr:`variants` and
:attr:`net_settings` and :attr:`bus_aliases` are derived from it.
For scaffolding new project folders, use :meth:`create`. It starts a blank
project bound to an on-disk directory; :meth:`add_schematic`,
:meth:`add_pcb`, :meth:`add_symbol_library`, and
:meth:`add_footprint_library` attach the pieces through the object model;
:meth:`write_project` writes the folder. Higher layers drive these methods
from their own input, so this class holds no knowledge of how inputs are
gathered.
Members (29)
| Member | Kind | Signature | Summary |
|---|---|---|---|
add_footprint_library | method | (self, nickname: 'str', uri: 'str', *, library_type: 'str' = 'KiCad') -> 'Any' | Seed the project footprint library table with a referenced library. |
add_pcb | method | (self, *, page_size: 'str' = 'A4') -> "'KiCadPcb'" | Attach a blank board with KiCad's default layer stack and return it. |
add_schematic | method | (self, *, sheet_name: 'str | None' = None, page_size: 'str' = 'A4', revision: 'str' = '', company: 'str' = '', date: 'str' = '', comments: 'list[str] | None' = None) -> "'KiCadSchematic'" | Attach a blank top-level schematic and return it. |
add_symbol_library | method | (self, nickname: 'str', uri: 'str', *, library_type: 'str' = 'KiCad') -> 'Any' | Seed the project symbol library table with a referenced library. |
add_variant | method | (self, name: 'str', description: 'str | None' = None) -> 'ProjectVariant' | Append a variant to the catalog. |
bus_aliases | property | -> 'dict[str, list[str]]' | Return a fresh normalized view of KiCad 10 project bus aliases. |
create | classmethod | (cls, name: 'str', directory: 'Path | str', *, project_path: 'Path | str | None' = None) -> "'KiCadProject'" | Start a blank, writable project bound to an on-disk directory. |
ensure_library_tables | method | (self) -> 'None' | Attach empty symbol and footprint library tables if not present. |
exact_source_text_variables | method | (self) -> 'tuple[tuple[str, str], ...]' | Read exact supported string variables from the acquired raw snapshot. |
from_file | classmethod | (cls, path: 'Path | str') -> "'KiCadProject'" | |
from_json_dict | classmethod | (cls, data: 'dict[str, Any]', *, project_path: 'Path | str | None' = None) -> "'KiCadProject'" | Build a project view from a parsed `.kicad_pro` JSON dict. |
from_text | classmethod | (cls, text: 'str', *, project_path: 'Path | str | None' = None) -> "'KiCadProject'" | |
get_path | method | (self, dotted_key: 'str', default: 'Any' = None) -> 'Any' | Read a value out of :attr:`raw` by dotted JSON path. |
get_text_variable | method | (self, name: 'str', default: 'str' = '') -> 'str' | Return a project text variable value. |
get_variant | method | (self, name: 'str') -> 'ProjectVariant | None' | Return a project variant by name. |
iter_variants | method | (self) -> 'Iterator[ProjectVariant]' | Iterate over project variants. |
remove_text_variable | method | (self, name: 'str') -> 'bool' | Remove a project text variable by name. |
remove_variant | method | (self, name: 'str') -> 'ProjectVariant | None' | Remove a variant by name; return the removed entry or None. |
rename_variant | method | (self, old_name: 'str', new_name: 'str') -> 'bool' | Rename a variant in the catalog. |
root_sheet_name | method | (self, root_schematic_file: 'str', *, project_name: 'str | None' = None, file_exists: 'Callable[[str], bool] | None' = None) -> 'str' | The name KiCad 10.0.8 gives the root sheet, as ``${SHEETNAME}`` shows it. |
save | method | (self, path: 'Path | str | None' = None) -> 'None' | Write :meth:`to_text` to disk. |
set_path | method | (self, dotted_key: 'str', value: 'Any') -> 'None' | Set a value in :attr:`raw` by dotted JSON path. |
set_text_variable | method | (self, name: 'str', value: 'str') -> 'None' | Set a project text variable in both typed state and raw JSON. |
set_worksheet | method | (self, path: 'Path | str', *, embed: 'bool' = True) -> 'None' | Reference (or embed) a ``.wks`` drawing sheet for the schematic. |
to_file | method | (self, path: 'Path | str | None' = None) -> 'None' | Deprecated alias for :meth:`save`. |
to_json | method | (self) -> 'dict[str, Any]' | Return the project JSON object preserved for round-trip writes. |
to_text | method | (self) -> 'str' | Serialize :attr:`raw` back to JSON, byte-equal with KiCad. |
top_level_sheets | method | (self) -> 'list[tuple[str, str]]' | ``schematic.top_level_sheets``: each entry's ``(filename, name)``. |
write_project | method | (self, directory: 'Path | str | None' = None) -> 'KiCadProjectFiles' | Write the whole project folder and return the written paths. |
KiCadSchematicInstance
classfrom kicad_monkey import KiCadSchematicInstance
class KiCadSchematicInstance(instance_index: 'int', sheet_number: 'int', sheet_count: 'int', schematic: "'KiCadSchematic'", source_path: 'Path | None', sheet_name: 'str', sheet_path: 'str', sheet_path_uuids: 'str', sheet_instance_path: 'str | None' = None, sheet_symbol: "Optional['SchSheet']" = None, sheet_symbol_uid: 'str' = '', sheet_file: 'str' = '', parent_sheet_path: 'str | None' = None, parent_sheet_path_uuids: 'str | None' = None, parent_sheet_instance_path: 'str | None' = None, is_top_level: 'bool' = False) -> 'None'
One concrete placement of a schematic in a KiCad hierarchy.
A single `.kicad_sch` file can appear more than once through repeated
hierarchical sheets. This record keeps the source schematic together with
the human sheet path, the KiCad UUID instance path, the parent sheet link,
and the sheet numbering needed for rendering.
Members (2)
| Member | Kind | Signature | Summary |
|---|---|---|---|
ir_kwargs | method | (self, *, document_id: 'str | None' = None) -> 'dict[str, object]' | Return keyword arguments for :meth:`KiCadDesign.to_schematic_ir`. |
source_key | property | -> 'str' | Stable source-file key, falling back to object identity. |
ProjectVariant
classfrom kicad_monkey import ProjectVariant
class ProjectVariant(name: 'str', description: 'str | None' = None) -> 'None'
One entry in `.kicad_pro` `schematic.variants` — the canonical
project-side variant catalog.
KiCad emits the catalog as a JSON list of ``{name, description}``
objects; ``description`` is optional in the schema (KiCad omits it
when blank). We surface it as ``None`` in that case so callers can
distinguish "no description set" from "empty string".
Members (1)
| Member | Kind | Signature | Summary |
|---|---|---|---|
from_json_dict | classmethod | (cls, data: 'dict[str, Any]') -> "'ProjectVariant'" |
find_adjacent_kicad_project_path
functionfrom kicad_monkey import find_adjacent_kicad_project_path
def find_adjacent_kicad_project_path(pcb_path: 'Path | str') -> 'Path | None'
Locate the most likely `.kicad_pro` sidecar for a PCB file.