API

SKiDL: A Python-Based Schematic Design Language

This module extends Python with the ability to design electronic circuits. It provides classes for working with 1) electronic parts (Part), 2) collections of part terminals (Pin) connected via wires (Net), and 3) groups of related nets (Bus). Using these classes, you can concisely describe the interconnection of components using a linear and/or hierarchical structure. It also provides the capability to check the resulting circuitry for the violation of electrical rules. The output of a SKiDL-enabled Python script is a netlist that can be imported into a PCB layout tool.

class skidl.skidl.Alias(name, id_tag=None)[source]

An alias can be added to another object to give it another name. Since an object might have several aliases, each alias can be tagged with an identifier to discriminate between them.

Parameters:
  • name – The alias name.
  • id_tag – The identifier tag.
__eq__(search)[source]

Return true if one alias is equal to another.

The aliases are equal if the following conditions are both true:

1. The ids must match or one or both ids must be something
    that evaluates to False (i.e., None, empty string or list, etc.).

2. The names must match based on using one name as a
    regular expression to compare to the other.
Parameters:search – The Alias object which self will be compared to.
class skidl.skidl.Bus(name, *args, **attribs)[source]

This class collects one or more nets into a group that can be indexed.

Parameters:
  • name – A string with the name of the bus.
  • args – A list of ints, pins, nets, buses to attach to the net.
Keyword Arguments:
 

attribs – A dictionary of attributes and values to attach to the Net object.

Example

n = Net()
led1 = Part('device', 'LED')
b = Bus('B', 8, n, led1['K'])
__call__(num_copies=1, **attribs)

Make zero or more copies of this bus.

Parameters:num_copies – Number of copies to make of this bus.
Keyword Arguments:
 attribs – Name/value pairs for setting attributes for the copy.
Returns:A list of Bus copies or a Bus if num_copies==1.
Raises:Exception if the requested number of copies is a non-integer or negative.

Notes

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

b = Bus('A', 8)  # Create a bus.
b_copy = b(2)   # Get two copies of the bus.

You can also use the multiplication operator to make copies:

b = 10 * Bus('A', 8)  # Create an array of buses.
__getitem__(*ids)[source]

Return a bus made up of the nets at the given indices.

Parameters:ids – A list of indices of bus lines. These can be individual numbers, net names, nested lists, or slices.
Returns:A bus if the indices are valid, otherwise None.
__iadd__(*pins_nets_buses)

Return the bus after connecting one or more nets, pins, or buses.

Parameters:pins_nets_buses – One or more Pin, Net or Bus objects or lists/tuples of them.
Returns:The updated bus with the new connections.

Notes

You can connect nets or pins to a bus like so:

p = Pin()       # Create a pin.
n = Net()       # Create a net.
b = Bus('B', 2) # Create a two-wire bus.
b += p,n        # Connect pin and net to B[0] and B[1].
__len__()[source]

Return the number of nets in this bus.

__mul__(num_copies=1, **attribs)

Make zero or more copies of this bus.

Parameters:num_copies – Number of copies to make of this bus.
Keyword Arguments:
 attribs – Name/value pairs for setting attributes for the copy.
Returns:A list of Bus copies or a Bus if num_copies==1.
Raises:Exception if the requested number of copies is a non-integer or negative.

Notes

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

b = Bus('A', 8)  # Create a bus.
b_copy = b(2)   # Get two copies of the bus.

You can also use the multiplication operator to make copies:

b = 10 * Bus('A', 8)  # Create an array of buses.
__repr__()

Return a list of the nets in this bus as a string.

__rmul__(num_copies=1, **attribs)

Make zero or more copies of this bus.

Parameters:num_copies – Number of copies to make of this bus.
Keyword Arguments:
 attribs – Name/value pairs for setting attributes for the copy.
Returns:A list of Bus copies or a Bus if num_copies==1.
Raises:Exception if the requested number of copies is a non-integer or negative.

Notes

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

b = Bus('A', 8)  # Create a bus.
b_copy = b(2)   # Get two copies of the bus.

You can also use the multiplication operator to make copies:

b = 10 * Bus('A', 8)  # Create an array of buses.
__setitem__(ids, *pins_nets_buses)[source]

You can’t assign to bus lines. You must use the += operator.

This method is a work-around that allows the use of the += for making connections to bus lines while prohibiting direct assignment. Python processes something like my_bus[7:0] += 8 * Pin() as follows:

1. Part.__getitem__ is called with '7:0' as the index. This
   returns a NetPinList of eight nets from my_bus.
2. The NetPinList.__iadd__ method is passed the NetPinList and
   the thing to connect to the it (eight pins in this case). This
   method makes the actual connection to the part pin or pins. Then
   it creates an iadd_flag attribute in the object it returns.
3. Finally, Bus.__setitem__ is called. If the iadd_flag attribute
   is true in the passed argument, then __setitem__ was entered
   as part of processing the += operator. If there is no
   iadd_flag attribute, then __setitem__ was entered as a result
   of using a direct assignment, which is not allowed.
__str__()[source]

Return a list of the nets in this bus as a string.

connect(*pins_nets_buses)[source]

Return the bus after connecting one or more nets, pins, or buses.

Parameters:pins_nets_buses – One or more Pin, Net or Bus objects or lists/tuples of them.
Returns:The updated bus with the new connections.

Notes

You can connect nets or pins to a bus like so:

p = Pin()       # Create a pin.
n = Net()       # Create a net.
b = Bus('B', 2) # Create a two-wire bus.
b += p,n        # Connect pin and net to B[0] and B[1].
copy(num_copies=1, **attribs)[source]

Make zero or more copies of this bus.

Parameters:num_copies – Number of copies to make of this bus.
Keyword Arguments:
 attribs – Name/value pairs for setting attributes for the copy.
Returns:A list of Bus copies or a Bus if num_copies==1.
Raises:Exception if the requested number of copies is a non-integer or negative.

Notes

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

b = Bus('A', 8)  # Create a bus.
b_copy = b(2)   # Get two copies of the bus.

You can also use the multiplication operator to make copies:

b = 10 * Bus('A', 8)  # Create an array of buses.
name

Get, set and delete the name of the bus.

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

skidl.skidl.Circuit

alias of SubCircuit

class skidl.skidl.Net(name=None, *pins_nets_buses, **attribs)[source]

Lists of connected pins are stored as nets using this class.

Parameters:
  • name – A string with the name of the net. If None or ‘’, then a unique net name will be assigned.
  • *pins_nets_buses – One or more Pin, Net, or Bus objects or lists/tuples of them to be connected to this net.
Keyword Arguments:
 

attribs – A dictionary of attributes and values to attach to the Net object.

__call__(num_copies=1, **attribs)

Make zero or more copies of this net.

Parameters:num_copies – Number of copies to make of this net.
Keyword Arguments:
 attribs – Name/value pairs for setting attributes for the copy.
Returns:A list of Net copies or a Net if num_copies==1.
Raises:Exception if the requested number of copies is a non-integer or negative.

Notes

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

n = Net('A')    # Create a net.
n_copy = n()    # Copy the net.

You can also use the multiplication operator to make copies:

n = 10 * Net('A')  # Create an array of nets.
__iadd__(*pins_nets_buses)

Return the net after connecting other pins, nets, and buses to it.

Parameters:*pins_nets_buses – One or more Pin, Net, or Bus objects or lists/tuples of them to be connected to this net.
Returns:The updated net with the new connections.

Notes

Connections to nets can also be made using the += operator like so:

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

Return the number of pins attached to this net.

__mul__(num_copies=1, **attribs)

Make zero or more copies of this net.

Parameters:num_copies – Number of copies to make of this net.
Keyword Arguments:
 attribs – Name/value pairs for setting attributes for the copy.
Returns:A list of Net copies or a Net if num_copies==1.
Raises:Exception if the requested number of copies is a non-integer or negative.

Notes

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

n = Net('A')    # Create a net.
n_copy = n()    # Copy the net.

You can also use the multiplication operator to make copies:

n = 10 * Net('A')  # Create an array of nets.
__repr__()

Return a list of the pins on this net as a string.

__rmul__(num_copies=1, **attribs)

Make zero or more copies of this net.

Parameters:num_copies – Number of copies to make of this net.
Keyword Arguments:
 attribs – Name/value pairs for setting attributes for the copy.
Returns:A list of Net copies or a Net if num_copies==1.
Raises:Exception if the requested number of copies is a non-integer or negative.

Notes

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

n = Net('A')    # Create a net.
n_copy = n()    # Copy the net.

You can also use the multiplication operator to make copies:

n = 10 * Net('A')  # Create an array of nets.
__str__()[source]

Return a list of the pins on this net as a string.

connect(*pins_nets_buses)[source]

Return the net after connecting other pins, nets, and buses to it.

Parameters:*pins_nets_buses – One or more Pin, Net, or Bus objects or lists/tuples of them to be connected to this net.
Returns:The updated net with the new connections.

Notes

Connections to nets can also be made using the += operator like so:

atmega = Part('atmel', 'ATMEGA16U2')
net = Net()
net += atmega[1]  # Connects pin 1 of chip to the net.
copy(num_copies=1, **attribs)[source]

Make zero or more copies of this net.

Parameters:num_copies – Number of copies to make of this net.
Keyword Arguments:
 attribs – Name/value pairs for setting attributes for the copy.
Returns:A list of Net copies or a Net if num_copies==1.
Raises:Exception if the requested number of copies is a non-integer or negative.

Notes

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

n = Net('A')    # Create a net.
n_copy = n()    # Copy the net.

You can also use the multiplication operator to make copies:

n = 10 * Net('A')  # Create an array of nets.
drive

Get, set and delete the drive strength of this net.

The drive strength cannot be set to a value less than its current value. So as pins are added to a net, the drive strength reflects the maximum drive value of the pins currently on the net.

name

Get, set and delete the name of this net.

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

class skidl.skidl.Part(lib=None, name=None, dest='NETLIST', tool='kicad', connections=None, part_defn=None, **attribs)[source]

A class for storing a definition of a schematic part.

ref

String storing the reference of a part within a schematic (e.g., ‘R5’).

value

String storing the part value (e.g., ‘3K3’).

footprint

String storing the PCB footprint associated with a part (e.g., SOIC-8).

pins

List of Pin objects for this 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.
  • part_defn – A list of strings that define the part (usually read from a schematic library file).
  • tool – The format for the library file or part definition (e.g., KICAD).
  • dest – String that indicates where the part is destined for (e.g., LIBRARY).
  • connections – A dictionary with part pin names/numbers as keys and the names of nets to which they will be connected as values. For example: { ‘IN-‘:’a_in’, ‘IN+’:’GND’, ‘1’:’AMPED_OUTPUT’, ‘14’:’VCC’, ‘7’:’GND’ }
Keyword Arguments:
 

attribs – 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.
__call__(num_copies=1, dest='NETLIST', **attribs)

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).
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.
__getitem__(*pin_ids, **criteria)

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.
__mul__(num_copies=1, dest='NETLIST', **attribs)

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).
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.
__repr__()

Return a description of the pins on this part as a string.

__rmul__(num_copies=1, dest='NETLIST', **attribs)

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).
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.
__setitem__(ids, *pins_nets_buses)[source]

You can’t assign to the pins of parts. You must use the += operator.

This method is a work-around that allows the use of the += for making connections to pins while prohibiting direct assignment. Python processes something like my_part[‘GND’] += gnd as follows:

1. Part.__getitem__ is called with 'GND' as the index. This
   returns a single Pin or a NetPinList.
2. The Pin.__iadd__ or NetPinList.__iadd__ method is passed
   the thing to connect to the pin (gnd in this case). This method
   makes the actual connection to the part pin or pins. Then it
   creates an iadd_flag attribute in the object it returns.
3. Finally, Part.__setitem__ is called. If the iadd_flag attribute
   is true in the passed argument, then __setitem__ was entered
   as part of processing the += operator. If there is no
   iadd_flag attribute, then __setitem__ was entered as a result
   of using a direct assignment, which is not allowed.
__str__()[source]

Return a description of the pins on this part as a string.

copy(num_copies=1, dest='NETLIST', **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).
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.
foot

Get, set and delete the part footprint.

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.
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.

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.

value

Get, set and delete the part value.

class skidl.skidl.PartUnit(part, *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:
  • 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.
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)
class skidl.skidl.Pin(**attribs)[source]

A class for storing data about pins for a part.

Parameters:attribs – Key/value pairs of attributes to add to the library.
nets

The electrical nets this pin is connected to (can be >1).

part

Link to the Part object this pin belongs to.

do_erc

When false, the pin is not checked for ERC violations.

__call__(num_copies=1, **attribs)

Return copy or list of copies of a pin including any net connection.

Parameters:num_copies – Number of copies to make of pin.
Keyword Arguments:
 attribs – Name/value pairs for setting attributes for the pin.

Notes

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

p = Pin()     # Create a pin.
p_copy = p()  # This is a copy of the pin.
__iadd__(*pins_nets_buses)

Return the pin after connecting it to one or more nets or pins.

Parameters:pins_nets_buses – One or more Pin, Net or Bus objects or lists/tuples of them.
Returns:The updated pin with the new connections.

Notes

You can connect nets or pins to a pin like so:

p = Pin()     # Create a pin.
n = Net()     # Create a net.
p += net      # Connect the net to the pin.
__mul__(num_copies=1, **attribs)

Return copy or list of copies of a pin including any net connection.

Parameters:num_copies – Number of copies to make of pin.
Keyword Arguments:
 attribs – Name/value pairs for setting attributes for the pin.

Notes

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

p = Pin()     # Create a pin.
p_copy = p()  # This is a copy of the pin.
__repr__()

Return a description of this pin as a string.

__rmul__(num_copies=1, **attribs)

Return copy or list of copies of a pin including any net connection.

Parameters:num_copies – Number of copies to make of pin.
Keyword Arguments:
 attribs – Name/value pairs for setting attributes for the pin.

Notes

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

p = Pin()     # Create a pin.
p_copy = p()  # This is a copy of the pin.
__str__()[source]

Return a description of this pin as a string.

connect(*pins_nets_buses)[source]

Return the pin after connecting it to one or more nets or pins.

Parameters:pins_nets_buses – One or more Pin, Net or Bus objects or lists/tuples of them.
Returns:The updated pin with the new connections.

Notes

You can connect nets or pins to a pin like so:

p = Pin()     # Create a pin.
n = Net()     # Create a net.
p += net      # Connect the net to the pin.
copy(num_copies=1, **attribs)[source]

Return copy or list of copies of a pin including any net connection.

Parameters:num_copies – Number of copies to make of pin.
Keyword Arguments:
 attribs – Name/value pairs for setting attributes for the pin.

Notes

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

p = Pin()     # Create a pin.
p_copy = p()  # This is a copy of the pin.
net

Return one of the nets the pin is connected to.

class skidl.skidl.SubCircuit(circuit_func)[source]

Class object that holds the entire netlist of parts and nets. This is initialized once when the module is first imported and then all parts and nets are added to its static members.

parts

List of all the schematic parts as Part objects.

nets

List of all the schematic nets as Net objects.

hierarchy

A ‘.’-separated concatenation of the names of nested SubCircuits at the current time it is read.

level

The current level in the schematic hierarchy.

context

Stack of contexts for each level in the hierarchy.

circuit_func

The function that creates a given subcircuit.

__call__(*args, **kwargs)[source]

This method is called when you invoke the SubCircuit object to create some schematic circuitry.

classmethod set_pin_conflict_rule(pin1_func, pin2_func, conflict_level)[source]

Set the level of conflict for two types of pins on the same net.

Parameters:
  • pin1_func – The function of the first pin (e.g., Pin.OUTPUT).
  • pin2_func – The function of the second pin (e.g., Pin.TRISTATE).
  • conflict_level – Severity of conflict (e.g., cls.OK, cls.WARNING, cls.ERROR).
skidl.skidl.search(term)[source]

Print a list of components with the regex term within their name, alias, description or keywords.

skidl.skidl.show(lib_name, part_name)[source]

Print the I/O pins for a given part in a library.