netlist¶
Netlist module encapsulating electrical netlist into following structure:
Netlist module simplifies electrical netlist processing in larger systems by providing basic operations: simple netlist iterators, to dict and json converters. It also simplifies operations used in netlist file readers by providing append methods and add operators.
Netlist object shown above was exported by Altium Designer to a RINF Netlist using following schematic diagram:
Usage¶
Recreating netlist manually based on Altium Designer’s schematic shown above, then performing some simple operations:
>>> from netbom.netlist import Netlist
>>> # Creating Netlist object
>>> netlist = Netlist()
>>> # Recreating Altium Designer's schematic shown above by appending pins one-by-one
>>> netlist.append_pin('NetD1_1', 'D1', '1')
>>> netlist.append_pin('NetD1_1', 'R1', '2')
>>> netlist.append_pin('GND', 'J1', '2')
>>> netlist.append_pin('GND', 'R1', '1')
>>> netlist.append_pin('+3.3V', 'D1', '2')
>>> netlist.append_pin('+3.3V', 'J1', '1')
>>> print(netlist)
{'NetD1_1': {'D1': ['1'], 'R1': ['2']}, 'GND': {'J1': ['2'], 'R1': ['1']}, '+3.3V': {'D1': ['2'], 'J1': ['1']}}
>>> # Netlist length
>>> print(len(netlist))
3
>>> # Filtering designators starting with 'R' string
>>> print(netlist.filter_designator(startswith='R'))
{'R1': {'1': 'GND', '2': 'NetD1_1'}}
>>> # List of nets in Netlist object
>>> print(netlist.nets())
['NetD1_1', 'GND', '+3.3V']
>>> # Iterating over Netlist structure
>>> for netline in netlist:
... for connection in netline.connections:
... for pin in connection.pins:
... print([netline.net, connection.designator, pin])
['NetD1_1', 'D1', '1']
['NetD1_1', 'R1', '2']
['GND', 'J1', '2']
['GND', 'R1', '1']
['+3.3V', 'D1', '2']
['+3.3V', 'J1', '1']
>>> # Converting Netlist object to dict
>>> print(netlist.to_dict())
{'NetD1_1': {'D1': ['1'], 'R1': ['2']}, 'GND': {'J1': ['2'], 'R1': ['1']}, '+3.3V': {'D1': ['2'], 'J1': ['1']}}
>>> # Converting Netlist object to a serialized json
>>> print(netlist.to_json())
[{"net": "NetD1_1", "connections": [{"designator": "D1", "pins": ["1"]}, {"designator": "R1", "pins": ["2"]}]}, {"net": "GND", "connections": [{"designator": "J1", "pins": ["2"]}, {"designator": "R1", "pins": ["1"]}]}, {"net": "+3.3V", "connections": [{"designator": "D1", "pins": ["2"]}, {"designator": "J1", "pins": ["1"]}]}]
>>> # Adding orphaned net which has only one component and only one pin connected
>>> netlist.append_pin('NetR2_1', 'R2', '1')
>>> print(netlist)
{'NetD1_1': {'D1': ['1'], 'R1': ['2']}, 'GND': {'J1': ['2'], 'R1': ['1']}, '+3.3V': {'D1': ['2'], 'J1': ['1']}, 'NetR2_1': {'R2': ['1']}}
>>> # Removing orphaned net
>>> netlist.remove_orphans()
>>> print(netlist)
{'NetD1_1': {'D1': ['1'], 'R1': ['2']}, 'GND': {'J1': ['2'], 'R1': ['1']}, '+3.3V': {'D1': ['2'], 'J1': ['1']}}
>>> # Two pins of the same component connected to the same net do not orphan the net
>>> netlist.append_pin('NetR2_1', 'R2', '1')
>>> netlist.append_pin('NetR2_1', 'R2', '2')
>>> netlist.remove_orphans()
>>> print(netlist)
{'NetD1_1': {'D1': ['1'], 'R1': ['2']}, 'GND': {'J1': ['2'], 'R1': ['1']}, '+3.3V': {'D1': ['2'], 'J1': ['1']}, 'NetR2_1': {'R2': ['1', '2']}}
Reference¶
- class netbom.netlist.Netlist(netline=<netbom.netlist.NetlistNetline object>)¶
NetlistNetlist class providing electrical netlist operations: appending Netline with automatic deduplication of nets, designators and pins.
- append(netline=<netbom.netlist.NetlistNetline object>)¶
Method appending one Netline. Appended net, designator and pins are concated and deduplicated with existing ones.
- Parameters:
netline (Netline, optional) – Netline to be appended, defaults to Netline()
- append_pin(net: str, designator: str, pin: str)¶
Method appending one pin to the Netlist. Appended net, designator and pins are deduplicated with existing ones. If there is no net, designator or pin: they are created sequentially.
- Parameters:
net (str) – net name (i.e. ‘NetR1_1’)
designator (str) – component designator (i.e. ‘R1’)
pin (str) – component pin (i.e. ‘1’)
- append_pins(net: str, designator: str, pins: list)¶
Method appending a list of pins to the Netlist. Appended net, designator and pins are deduplicated with existing ones. If there is no net, designator or pins: they are created sequentially.
- Parameters:
net (str) – net name (i.e. ‘NetR1_1’)
designator (str) – component designator (i.e. ‘R1’)
pins (list of strings) – component pin list (i.e. [‘1’, ‘2’])
- filter_designator(startswith: str) NetlistDesignators¶
Method which filters designators in Netlist with startswith pattern, returning NetlistDesignators object with filtered designators.
- Parameters:
startswith (str) – Startswith pattern in designators
- Returns:
NetlistDesignators object
- Return type:
NetlistDesignators
- nets() list¶
Method returning a list of net names.
- Returns:
List of net names
- Return type:
list
- remove_orphans() None¶
Method which removes orphaned nets that have only one connection and one pin. Orphaned net is simply connected to only one component and only one pin.
- to_dict() dict¶
Method converting Netlist to dict.
- Returns:
Converted Netlist to dict.
- Return type:
dict
- to_json() str¶
Method converting Netlist to valid RFC 8259 serialized JSON string.
- Returns:
serialized JSON string
- Return type:
str