api¶
- class recad.BomItem¶
Bases:
objectRepresents a single line item in a Bill of Materials (BOM).
This class encapsulates all relevant information about a specific component or part extracted from a schematic design. It includes quantity, reference designators, electrical properties, and supplier information.
- Attributes:
amount (int): The total quantity of this component required. references (list[str]): A list of reference designators (e.g., [“R1”, “R2”]). value (str): The electrical value of the component (e.g., “10kΩ”, “100nF”). footprint (str): The PCB footprint package name (e.g., “0805”, “SOIC-8”). datasheet (str): URL or file path to the component datasheet. description (str): A human-readable description of the component. mouser_nr (str): The manufacturer or supplier part number (e.g., Mouser catalog number).
- amount¶
- datasheet¶
- description¶
- footprint¶
- mouser_nr¶
- references¶
- value¶
- class recad.C(reference, capacitance)¶
Bases:
objectA C utility function for creating a Capacitor
- at(reference, pin=None)¶
Place the Capacitor
- label(pos)¶
Place property
- rotate(angle)¶
Rotate the Capacitor
- tox(reference, pin=None)¶
Set the x coordinate of the capacitor.
- toy(reference, pin=None)¶
Set the y coordinate of the capacitor.
- class recad.Circuit¶
Bases:
object- __repr__()¶
Return repr(self).
- __str__()¶
Return str(self).
- bjt(reference, n0, n1, n2, value)¶
- capacitor(reference, n0, n1, value)¶
- circuit(reference, n, value)¶
- control(control)¶
- diode(reference, n0, n1, value)¶
- jfet(reference, n0, n1, n2, value)¶
- option(option, value)¶
- resistor(reference, n0, n1, value)¶
- save(filename)¶
- set_value(reference, value)¶
- voltage(reference, n1, n2, value)¶
- class recad.DrcLevel¶
Bases:
object- Error = DrcLevel.Error¶
- Warning = DrcLevel.Warning¶
- __repr__()¶
Return repr(self).
- class recad.DrcViolation¶
Bases:
object- __repr__()¶
Return repr(self).
- __str__()¶
Return str(self).
- description¶
- level¶
- markers¶
- position¶
- title¶
- class recad.ErcLevel¶
Bases:
objectEnumeration representing the severity level of an Electrical Rule Check (ERC) violation.
This enum is used to classify ERC issues by their impact on the design. It allows users to filter, prioritize, or handle violations differently based on whether they are critical errors or non-blocking warnings.
- Values:
- Error: A critical violation that indicates a definite problem in the schematic.
Errors typically prevent successful netlist generation or PCB export and should be resolved before proceeding. Examples: unconnected power pins, shorted nets with different voltages, missing required properties.
- Warning: A potential issue that may not break functionality but warrants review.
Warnings do not block processing but should be evaluated for design quality. Examples: unused input pins, ambiguous net labels, non-standard component values.
- Error = ErcLevel.Error¶
- Warning = ErcLevel.Warning¶
- __repr__()¶
Return repr(self).
- class recad.ErcViolation¶
Bases:
objectRepresents a single Electrical Rule Check (ERC) violation found during schematic analysis.
This class encapsulates details about a specific ERC issue, including its severity, description, and location information within the schematic. It is used to report potential design problems such as unconnected pins, conflicting net labels, or power symbol mismatches.
- Attributes:
- level (ErcLevel): The severity of the violation, either ErcLevel.Error or
ErcLevel.Warning. Errors typically block further processing, while warnings indicate potential issues that should be reviewed.
- title (str): A concise, human-readable title summarizing the violation
(e.g., “Unconnected input pin”, “Conflicting net labels”).
- description (str): A detailed explanation of the violation, including
context about why it occurred and suggestions for resolution.
- position (tuple[float, float]): The (x, y) coordinates in schematic space
where the violation is located. Useful for highlighting the issue in a graphical viewer.
- markers (list[tuple[float, float]]): A list of (x, y) coordinate tuples
marking additional points of interest related to this violation, such as connected pins or net segments involved in the conflict.
- Example:
>>> import recad >>> >>> # Load a schematic and run ERC checks (hypothetical API) >>> schema = recad.Schema.load("design.kicad_sch") >>> violations = schema.run_erc() >>> >>> # Process and display violations >>> for violation in violations: ... if violation.level == recad.ErcLevel.Error: ... print(f"❌ ERROR: {violation.title}") ... else: ... print(f"⚠️ WARNING: {violation.title}") ... print(f" Location: {violation.position}") ... print(f" {violation.description}") ... if violation.markers: ... print(f" Related points: {violation.markers}")
- __repr__()¶
Return repr(self).
- __str__()¶
Return str(self).
- description¶
- level¶
- markers¶
- position¶
- title¶
- class recad.Feedback¶
Bases:
object- component(component)¶
Add a component into the feedback loop (e.g., R, C, Symbol)
- dot(position)¶
Draw a dot at the start or end of the line
- end(reference, pin)¶
- height(h)¶
- start(reference, pin)¶
- class recad.GlobalLabel(name)¶
Bases:
objectA GlobalLabel is a custom identifier that can be assigned to multiple objects or components across the entire design.
- at(reference, pin=None)¶
- rotate(angle)¶
- class recad.Gnd¶
Bases:
objectA GND utility function for creating GND reference
- at(reference, pin=None)¶
Place the GND symbol
- rotate(angle)¶
Rotate the Gnd symbol
- class recad.Junction¶
Bases:
objectA junction represents a connection point where multiple wires or components intersect, allowing electrical current to flow between them.
- __repr__()¶
Return repr(self).
- __str__()¶
Return str(self).
- at(reference, pin=None)¶
Place the junction.
- push()¶
- class recad.LocalLabel(name)¶
Bases:
objectA LocalLabel refers to an identifier assigned to individual Components or objects within a specific grouping on the same schema page.
- at(reference, pin=None)¶
place the label.
- rotate(angle)¶
Rotate the label
- Parameters:
angle – rotation angle in degrees
- class recad.NoConnect¶
Bases:
objectNoConnect, used to satisfy the ERC check.
- at(reference, pin=None)¶
- class recad.Pcb(_project, _library_path=None)¶
Bases:
objectThe Pcb
- drc(schema)¶
Run Design Rule Check (DRC) on the PCB and return any violations found.
- static load(path)¶
Load a new Pcb from a file.
- Parameters:
path – the file path
- plot(**kwargs)¶
Plot a PCB
- Parameters:
**kwargs – see below
- Keyword Arguments:
theme – the color theme.
scale – Adjusts the size of the final image, considering only the image area without the border.
border – draw a border or crop the image.
- class recad.Power(voltage)¶
Bases:
objectA Power utility function for creating a power source
- at(reference, pin=None)¶
Place the Power source
- rotate(angle)¶
Rotate the Power source
- class recad.R(reference, resistance)¶
Bases:
objectA R utility function for creating a Resistor
- at(reference, pin=None)¶
Place the Resistor
- label(pos)¶
Place property, possible values are offset tuple or position by name: north, n, northeast, ne…
- rotate(angle)¶
Rotate the Resistor
- tox(reference, pin=None)¶
Set the x coordinate of the resistor.
- toy(reference, pin=None)¶
Set the y coordinate of the resistor.
- class recad.Schema(project, library_path=None)¶
Bases:
objectThe Schema
- __repr__()¶
Return repr(self).
- __str__()¶
Return str(self).
- bom(group=True)¶
Generate a Bill of Materials (BOM) from a KiCad schematic file.
- circuit(name, spice)¶
- draw(item)¶
Draw a element to the Schema.
Instead of using draw on a schema, you can also add the element using the + function.
- erc()¶
Run Electrical Rule Check (ERC) on the schematic and return any violations found.
- last_reference(prefix)¶
- static load(path)¶
Load a new Schema from a file.
- Parameters:
path – the file path
- move_to(item)¶
- next_reference(prefix)¶
- open(**kwargs)¶
- peek()¶
- plot(**kwargs)¶
Plot a schema
- Parameters:
**kwargs – see below
- Keyword Arguments:
theme – the color theme.
scale – Adjusts the size of the final image, considering only the image area without the border.
border – draw a border or crop the image.
- pop()¶
- write(path)¶
Write a new Schema from to file.
- Parameters:
path – the file path
- class recad.Simulation(circuit)¶
Bases:
object- ac(stop_frequency, number_of_points, variation)¶
Small-Signal AC Analysis.
- Args:
start_frequency (str): The starting frequency (e.g., “1k”). stop_frequency (str): The final frequency (e.g., “100Meg”). number_of_points (int): Number of points. variation (str): The sweep variation type, one of [“dec”, “oct”, “lin”].
- Returns:
dict[str, list[float]]: A dictionary of AC analysis results.
Reference in the ngspice Documentation in chapter 15.3.1.
- op()¶
Operating Point Analysis.
Computes the DC operating point of the circuit.
- Returns:
dict[str, list[float]]: A dictionary of operating point values.
- run()¶
Run the stored commands.
- Returns:
dict[str, dict[str, list[float]]]: A dictionary of plot results.
- tran(stop, start)¶
Transient analysis.
- Args:
step (str): The time step. stop (str): The final time. start (str): The start time.
- Returns:
dict[str, list[float]]: A dictionary of transient analysis results.
Reference in the ngspice Documentation in chapter 15.3.10.
- class recad.Symbol(reference, value, lib_id)¶
Bases:
objectA schematic Symbol representing an instance from the [symbols] library.
- anchor(pin)¶
Set an anchor Pin.
- Parameters:
pin – the anchor pin, can be a string or an integer.
- at(reference, pin=None)¶
place the symbol.
- label(pos)¶
Place property, possible values are offset tuple or position by name: north, n, northeast, ne…
- mirror(axis)¶
Mirror the symbol
- Parameters:
axis – the mirror axis [‘x’, ‘y’, ‘xy’]
- property(key, val)¶
Set a property for the symbol
- Parameters:
key – the property key
value – the property value
- rotate(angle)¶
Rotate the symbol
- Parameters:
angle – rotation angle in degrees
- tox(reference, pin=None)¶
Set the x coordinate of the symbol.
- toy(reference, pin=None)¶
Set the y coordinate of the symbol.
- unit(unit)¶
Select the unit of a symbol
- Parameters:
unit – the Symbol unit number.
- class recad.Wire¶
Bases:
object- at(reference, pin=None)¶
Draw the line from the position.
- dot(dots)¶
Add dots to the wire
- down()¶
Draw a line downwards.
- left()¶
Draw wire to the left.
- length(length)¶
The length of the wire
- right()¶
Draw wire to the right.
- tox(element, pin=None)¶
Draw the line to the X position.
- toy(element, pin=None)¶
Draw the line to the Y position.
- up()¶
Draw wire upward.
- recad.bom(input, group=True)¶
Generate a Bill of Materials (BOM) from a KiCad schematic file.
This function parses a KiCad schematic file and extracts component information into a structured BOM format. It can optionally group components by their properties to consolidate identical parts.
- Args:
input_path (str): Path to the KiCad schematic file (.kicad_sch). group (bool, optional): Whether to group identical components together.
Defaults to True. When enabled, components with the same value, footprint, and other properties are merged into a single BOM entry with combined references.
- Returns:
- tuple: A tuple containing two elements:
list[BomItem]: The primary BOM list (ungrouped or grouped based on parameter).
list[BomItem] | None: Additional grouped BOM data if available, otherwise None.
- Raises:
ValueError: If the file extension is not supported or file type cannot be determined. RuntimeError: If the schematic file cannot be loaded or BOM generation fails.
- Example:
>>> import your_module >>> >>> # Generate grouped BOM (default) >>> items, grouped = your_module.bom("design.kicad_sch") >>> >>> # Generate ungrouped BOM >>> items, grouped = your_module.bom("design.kicad_sch", group=False) >>> >>> # Access BOM item properties >>> for item in items: ... print(f"{item.amount}x {item.value} - {item.description}")
- Note:
Only .kicad_sch files are currently supported. Other file extensions will raise a ValueError.
- recad.main()¶
recad main function.
- recad.plot(input, output)¶