Skip to content

Python development

Joachim Metz edited this page Jul 15, 2022 · 1 revision

libsmdev comes with Python-bindings named pysmdev.

Below are examples how use pysmdev. They assume you have a working version of pysmdev on your system. To build pysmdev see Building.

Import

To be able to use pysmdev in your Python scripts add the following import:

import pysmdev

Get version

The get_version() module function can be used to retrieve the version of the pysmdev.

pysmdev.get_version()

This will return a textual string (Unicode) that contains the libsmdev version. Since pysmdev is a wrapper around libsmdev it does not have a separate version.

Open handle

Open a handle by path

smdev_handle = pysmdev.handle()

smdev_handle.open("/dev/sda")

...

smdev_handle.close()

The explicit call to smdev_handle.close() is not required. Close only must be called once all operations on the handle have been completed.

Open a handle using a file-like object

file_object = open("/dev/sda", "rb")

smdev_handle = pysmdev.handle()

smdev_handle.open_file_object(file_object)

...

smdev_handle.close()

The explicit call to smdev_handle.close() is not required. Close only must be called once all operations on the handle have been completed and will not close the file-like object itself.

Also see

import pysmdev

help(pysmdev)
help(pysmdev.handle)
Clone this wiki locally