blkinfo

0.2.0 · active · verified Fri Apr 17

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

from blkinfo import BlkInfo

# Instantiate BlkInfo
blk_info = BlkInfo()

# Get information about all available block devices
all_block_devices_info = blk_info.get_all_blkdev_info()
print("\n--- All Block Devices ---")
for dev in all_block_devices_info:
    print(f"  Device: {dev['NAME']}, Size: {dev['SIZE']}, Type: {dev['TYPE']}")

# To get information about a specified block device (e.g., '/dev/sda')
# Note: Device paths vary by system. Use an existing path on your system.
# Permissions might be required (e.g., sudo) for full details.
import os
if os.path.exists('/dev/sda'):
    try:
        specified_block_device_info = blk_info.get_blkdev_info("/dev/sda")
        print("\n--- Specific Block Device (/dev/sda) ---")
        for key, value in specified_block_device_info.items():
            print(f"  {key}: {value}")
    except Exception as e:
        print(f"Could not get info for /dev/sda: {e}. (Often due to permissions or device not existing)")
else:
    print("\n--- Specific Block Device (/dev/sda) ---")
    print("  /dev/sda not found. Skipping specific device example.")
    print("  Try with an existing path like '/dev/nvme0n1' or '/dev/vda' on your system.")

view raw JSON →