{"library":"pylspci","title":"pylspci - PCI Device Parser","description":"pylspci is a Python library that provides a convenient interface to parse the output of the `lspci -mmnn` command, transforming it into Python objects. It can be used to query PCI devices on local or remote UNIX machines. The current version is 0.4.3, with an infrequent release cadence, though a 0.5.0 release candidate was published in January 2025.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install pylspci"],"cli":null},"imports":["from pylspci import ScannerPCI"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom pylspci import ScannerPCI\n\n# Example for a remote connection, using environment variables for credentials\n# For local scan, if current user can run lspci without sudo, password can be omitted.\n# If local scan requires sudo, provide password or ensure user has sudo access without password.\n\n# Replace with your target IP, username, and ensure PCI_PASSWORD is set in your environment\ntarget_ip = os.environ.get('PCI_HOST_IP', '127.0.0.1')\nusername = os.environ.get('PCI_USERNAME', 'root')\npassword = os.environ.get('PCI_PASSWORD', '')\n\ntry:\n    # Connect to the target machine\n    # For local machine requiring sudo, you'd typically pass ip='127.0.0.1', password=password\n    # For remote, provide IP, username, and password.\n    if target_ip == '127.0.0.1' and not password: # Attempt local without password if not explicitly set\n        scanner = ScannerPCI(ip=target_ip)\n    elif target_ip == '127.0.0.1': # Local with password\n        scanner = ScannerPCI(ip=target_ip, password=password)\n    else: # Remote connection\n        scanner = ScannerPCI(ip=target_ip, username=username, password=password)\n\n    # Select all PCI devices\n    devices = scanner.select()\n\n    print(f\"Found {len(devices)} PCI devices:\")\n    for device in devices:\n        print(f\"  - {device.slot}: {device.vendor_name} {device.device_name} ({device.device_class_name})\")\n\n    # Example: Find all network controllers\n    network_controllers = scanner.select(device_class_name='*Ethernet*')\n    if network_controllers:\n        print(\"\\nNetwork Controllers:\")\n        for nc in network_controllers:\n            print(f\"  - {nc.slot}: {nc.vendor_name} {nc.device_name}\")\n    else:\n        print(\"\\nNo network controllers found.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to connect to a target (local or remote) using `pylspci.ScannerPCI` and then retrieve and filter PCI devices. It uses environment variables for sensitive credentials in remote connection examples. Ensure the target machine has `pciutils` installed and appropriate network access and authentication are configured.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}