Python lspci parser

Index - Module Index - Search Page

A Python parser for the lspci command from the pciutils package.

Command-line interface

An executable script named pylspci is available, and acts as a wrapper around lspci that can produce JSON output.

$ pylspci -nn
  "slot": {"domain": 0, "bus": 0, "device": 1, "function": 3},
  "device": {"id": 9248, "name": "Name A"},

See pylspci --help and the CLI docs to learn more.

Parsing in Python

To parse lspci -nnmm, use the SimpleParser. To parse lspci -nnmmvvvk, use the VerboseParser.

>>> from pylspci.parsers import SimpleParser
>>> SimpleParser().run()
[Device(slot=Slot('0000:00:01.3'), name=NameWithID('Name A [2420]'), ...),
 Device(slot=Slot('0000:00:01.4'), name=NameWithID('Name B [0e54]'), ...)]

Custom arguments

>>> from pylspci.command import IDResolveOption
>>> from pylspci.parsers import VerboseParser
>>> VerboseParser().run(
...     hide_single_domain=False,
...     id_resolve_option=IDResolveOption.NameOnly,
... )
[Device(slot=Slot('0000:00:01.3'), name=NameWithID('Name A'), ...),
 Device(slot=Slot('0000:00:01.4'), name=NameWithID('Name B'), ...)]

Learn more