skidl.part module

Handles parts.

class skidl.part.Part(lib=None, name=None, dest=NETLIST, tool=None, connections=None, part_defn=None, circuit=None, ref_prefix='U', ref=None, tag=None, pin_splitters=None, tool_version=None, **kwargs)[source]

Bases: skidl.skidlbaseobj.SkidlBaseObject

A class for storing a definition of a schematic part.

Parameters
  • lib – Either a SchLib object or a schematic part library file name.

  • name – A string with name of the part to find in the library, or to assign to the part defined by the part definition.

  • dest – String that indicates where the part is destined for (e.g., LIBRARY).

  • tool – The format for the library file or part definition (e.g., KICAD).

  • connections – A dictionary with part pin names/numbers as keys and the nets to which they will be connected as values. For example: { ‘IN-‘:a_in, ‘IN+’:gnd, ‘1’:AMPED_OUTPUT, ‘14’:vcc, ‘7’:gnd }

  • part_defn – A list of strings that define the part (usually read from a schematic library file).

  • circuit – The Circuit object this Part belongs to.

  • ref_prefix – Prefix for part references such as ‘U’ or ‘J’.

  • ref – A specific part reference to be assigned.

  • tag – A specific tag to tie the part to its footprint in the PCB.

  • pin_splitters – String of characters that split long pin names into shorter aliases.

  • tool_version – Select between KiCad V5 and V6.

Keyword Arguments

kwargs – Name/value pairs for setting attributes for the part. For example, manf_num=’LM4808MP-8’ would create an attribute named ‘manf_num’ for the part and assign it the value ‘LM4808MP-8’.

Raises
  • * Exception if the part library and definition are both missing.

  • * Exception if an unknown file format is requested.

add_pins(*pins)[source]

Add one or more pins to a part.

add_xspice_io(io)[source]

Add XSPICE I/O to the pins of a part.

associate_pins()[source]

Make sure all the pins in a part have valid references to the part.

attached_to(nets=None)[source]

Return True if any part pin is connected to a net in the list.

copy(num_copies=None, dest=NETLIST, circuit=None, io=None, **attribs)[source]

Make zero or more copies of this part while maintaining all pin/net connections.

Parameters
  • num_copies – Number of copies to make of this part.

  • dest – Indicates where the copy is destined for (e.g., NETLIST).

  • circuit – The circuit this part should be added to.

  • io – XSPICE I/O names.

Keyword Arguments

attribs – Name/value pairs for setting attributes for the copy.

Returns

A list of Part copies or a single Part if num_copies==1.

Raises

Exception if the requested number of copies is a non-integer or negative.

Notes

An instance of a part can be copied just by calling it like so:

res = Part("Device",'R')    # Get a resistor.
res_copy = res(value='1K')  # Copy the resistor and set resistance value.

You can also use the multiplication operator to make copies:

cap = Part("Device", 'C')   # Get a capacitor
caps = 10 * cap             # Make an array with 10 copies of it.
copy_units(src)[source]

Make copies of the units from the source part.

create_network()[source]

Create a network from the pins of a part.

erc_desc()[source]

Create description of part for ERC and other error reporting.

erc_list = [<function dflt_part_erc>]
export()[source]

Return a string to recreate a Part object.

property foot

Get, set and delete the part footprint.

generate_netlist_component(tool=None)[source]

Generate the part information for inclusion in a netlist.

Parameters

tool – The format for the netlist file (e.g., KICAD).

generate_pinboxes(tool=None)[source]

Generate the pinboxes for arranging parts in a schematic.

generate_svg_component(symtx='', tool=None, net_stubs=None)[source]

Generate the SVG for displaying a part in an SVG schematic.

generate_xml_component(tool=None)[source]

Generate the part information for inclusion in an XML file.

Parameters

tool – The format for the XML file (e.g., KICAD).

classmethod get(text, circuit=None)[source]

Get the part with the given text from a circuit, or return None.

Parameters

text – A text string that will be searched for in the list of parts.

Keyword Arguments

circuit – The circuit whose parts will be searched. If set to None, then the parts in the default_circuit will be searched.

Returns

A list of parts or a single part that match the text string with either their reference, name, alias, or their description.

get_pins(*pin_ids, **criteria)[source]

Return list of part pins selected by pin numbers or names.

Parameters

pin_ids – A list of strings containing pin names, numbers, regular expressions, slices, lists or tuples. If empty, then it will select all pins.

Keyword Arguments

criteria – Key/value pairs that specify attribute values the pins must have in order to be selected.

Returns

A list of pins matching the given IDs and satisfying all the criteria, or just a single Pin object if only a single match was found. Or None if no match was found.

Notes

Pins can be selected from a part by using brackets like so:

atmega = Part('atmel', 'ATMEGA16U2')
net = Net()
atmega[1] += net  # Connects pin 1 of chip to the net.
net += atmega['RESET']  # Connects reset pin to the net.
property hierarchical_name
is_connected()[source]

Return T/F depending upon whether a part is connected in a netlist.

If a part has pins but none of them are connected to nets, then this method will return False. Otherwise, it will return True even if the part has no pins (which can be the case for mechanical parts, silkscreen logos, or other non-electrical schematic elements).

is_movable()[source]

Return T/F if the part can be moved from one circuit into another.

This method returns true if:
  1. the part is not in a circuit, or

  2. the part has pins but none of them are connected to nets, or

  3. the part has no pins (which can be the case for mechanical parts, silkscreen logos, or other non-electrical schematic elements).

make_unit(label, *pin_ids, **criteria)[source]

Create a PartUnit from a set of pins in a Part object.

Parts can be organized into smaller pieces called PartUnits. A PartUnit acts like a Part but contains only a subset of the pins of the Part.

Parameters
  • label – The label used to identify the PartUnit.

  • pin_ids – A list of strings containing pin names, numbers, regular expressions, slices, lists or tuples.

Keyword Arguments

criteria – Key/value pairs that specify attribute values the pin must have in order to be selected.

Returns

The PartUnit.

property match_pin_regex

Get, set and delete the enable/disable of pin regular-expression matching.

parse(get_name_only=False)[source]

Create a part from its stored part definition.

Parameters

get_name_only – When true, just get the name and aliases for the part. Leave the rest unparsed.

pin_aliases_to_attributes()[source]

Make each pin alias into an attribute of the part.

property ref

Get, set and delete the part reference.

When setting the part reference, if another part with the same reference is found, the reference for this part is adjusted to make it unique.

rename_pin(pin_id, new_pin_name)[source]

Assign a new name to a pin of a part.

renumber_pin(pin_id, new_pin_num)[source]

Assign a new number to a pin of a part.

rmv_pins(*pin_ids)[source]

Remove one or more pins from a part.

set_pin_alias(alias, *pin_ids, **criteria)[source]

Set the alias for a part pin.

Parameters
  • alias – The alias for the pin.

  • pin_ids – A list of strings containing pin names, numbers, regular expressions, slices, lists or tuples.

Keyword Arguments

criteria – Key/value pairs that specify attribute values the pin must have in order to be selected.

Returns

Nothing.

split_pin_names(delimiters)[source]

Use chars in delimiters to split pin names and add as aliases to each pin.

swap_pins(pin_id1, pin_id2)[source]

Swap pin name/number between two pins of a part.

property tag

Return the part’s tag.

validate()[source]

Check that pins and units reference the correct part that owns them.

property value

Get, set and delete the part value.

class skidl.part.PartUnit(parent, label, *pin_ids, **criteria)[source]

Bases: skidl.part.Part

Create a PartUnit from a set of pins in a Part object.

Parts can be organized into smaller pieces called PartUnits. A PartUnit acts like a Part but contains only a subset of the pins of the Part.

Parameters
  • part – This is the parent Part whose pins the PartUnit is built from.

  • pin_ids – A list of strings containing pin names, numbers, regular expressions, slices, lists or tuples. If empty, it will match every pin of the part.

Keyword Arguments

criteria – Key/value pairs that specify attribute values the pin must have in order to be selected.

Examples

This will return unit 1 from a part:

lm358 = Part('linear','lm358')
lm358a = PartUnit(lm358, unit=1)

Or you can specify the pins directly:

lm358a = PartUnit(lm358, 1, 2, 3)
add_pins_from_parent(*pin_ids, **criteria)[source]

Add selected pins from the parent to the part unit.

property ref

Get, set and delete the part reference.

When setting the part reference, if another part with the same reference is found, the reference for this part is adjusted to make it unique.

validate()[source]

Check that unit pins point to the parent part.

class skidl.part.PinNameSearch(part)[source]

Bases: object

A class for restricting part pin indexing to only pin names while ignoring pin numbers.

get_pins(*pin_ids, **criteria)[source]
class skidl.part.PinNumberSearch(part)[source]

Bases: object

A class for restricting part pin indexing to only pin numbers while ignoring pin names.

get_pins(*pin_ids, **criteria)[source]
class skidl.part.SkidlPart(lib=None, name=None, dest=TEMPLATE, tool=None, connections=None, **attribs)[source]

Bases: skidl.part.Part

A class for storing a SKiDL definition of a schematic part. It’s identical to its Part superclass except:

  • The tool defaults to SKIDL.

  • The destination defaults to TEMPLATE so that it’s easier to start

    a part and then add pins to it without it being added to the netlist.