{"id":9554,"library":"blkinfo","title":"blkinfo","description":"blkinfo is a Python package designed to retrieve and list detailed information about all available block devices on a system, or a specified block device. It provides a programmatic interface to access system-level block device data, typically parsing information found in `/sys/class/block`. The current version is 0.2.0, and releases are infrequent, reflecting its stable and specific functionality.","status":"active","version":"0.2.0","language":"en","source_language":"en","source_url":"https://github.com/grinrag/blkinfo","tags":["system","block-device","linux","hardware"],"install":[{"cmd":"pip install blkinfo","lang":"bash","label":"Install blkinfo"}],"dependencies":[],"imports":[{"symbol":"BlkInfo","correct":"from blkinfo import BlkInfo"}],"quickstart":{"code":"from blkinfo import BlkInfo\n\n# Instantiate BlkInfo\nblk_info = BlkInfo()\n\n# Get information about all available block devices\nall_block_devices_info = blk_info.get_all_blkdev_info()\nprint(\"\\n--- All Block Devices ---\")\nfor dev in all_block_devices_info:\n    print(f\"  Device: {dev['NAME']}, Size: {dev['SIZE']}, Type: {dev['TYPE']}\")\n\n# To get information about a specified block device (e.g., '/dev/sda')\n# Note: Device paths vary by system. Use an existing path on your system.\n# Permissions might be required (e.g., sudo) for full details.\nimport os\nif os.path.exists('/dev/sda'):\n    try:\n        specified_block_device_info = blk_info.get_blkdev_info(\"/dev/sda\")\n        print(\"\\n--- Specific Block Device (/dev/sda) ---\")\n        for key, value in specified_block_device_info.items():\n            print(f\"  {key}: {value}\")\n    except Exception as e:\n        print(f\"Could not get info for /dev/sda: {e}. (Often due to permissions or device not existing)\")\nelse:\n    print(\"\\n--- Specific Block Device (/dev/sda) ---\")\n    print(\"  /dev/sda not found. Skipping specific device example.\")\n    print(\"  Try with an existing path like '/dev/nvme0n1' or '/dev/vda' on your system.\")\n","lang":"python","description":"This quickstart demonstrates how to instantiate `BlkInfo` and use its primary methods `get_all_blkdev_info()` to retrieve information for all block devices and `get_blkdev_info()` for a specific device. It includes a check for `/dev/sda` and basic error handling, as permissions are often required."},"warnings":[{"fix":"Ensure your application runs in a Linux environment where `/sys/class/block` and device files are available.","message":"blkinfo is designed for Linux systems. Running it on other operating systems (e.g., Windows, macOS) will not yield correct results and may raise `FileNotFoundError` as it relies on Linux-specific paths like `/sys/class/block`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Execute your Python script with root privileges (e.g., `sudo python your_script.py`) or ensure the user has appropriate read permissions on `/dev/` and `/sys/class/block`.","message":"Accessing detailed block device information often requires root privileges. Running your Python script without `sudo` may result in partial or empty data for certain fields, or `PermissionError` when trying to access specific device paths.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always validate the structure of the returned dictionary against the current version's expected output or handle potentially missing/reordered keys gracefully.","message":"The JSON output schema for `get_all_blkdev_info()` and `get_blkdev_info()` received minor internal adjustments in version 0.2.0. While not a major API break, users who strictly parse the dictionary keys or rely on their exact ordering might need to adjust their code.","severity":"gotcha","affected_versions":"0.2.0 and later"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run your Python script in a Linux environment. If already on Linux, ensure the `/sys` filesystem is mounted correctly and accessible.","cause":"The `blkinfo` library is Linux-specific and depends on system paths like `/sys/class/block` which do not exist on other operating systems (e.g., Windows, macOS).","error":"FileNotFoundError: [Errno 2] No such file or directory: '/sys/class/block'"},{"fix":"Execute your Python script with root privileges (e.g., `sudo python your_script.py`) or adjust the user's permissions to read from `/dev/` and `/sys/class/block`.","cause":"The user executing the script lacks sufficient read permissions to access the specified block device or system files required by `blkinfo`.","error":"PermissionError: [Errno 13] Permission denied: '/dev/sda'"},{"fix":"Install the package using `pip install blkinfo`. If it's already installed, ensure your current working directory doesn't contain a file named `blkinfo.py` that might be shadowing the installed package.","cause":"The `blkinfo` package is either not installed in the current Python environment, or there's a conflict with another module named `blkinfo`.","error":"ImportError: cannot import name 'BlkInfo' from 'blkinfo' (unknown location)"}]}