Package: pySMART
pySMARTCopyright (C) 2021-2023Rafael LeiraCopyright (C) 2021Truenas teamCopyright (C) 2015 Marc HerndonpySMART is a simple Python wrapper for thesmartctlcomponent ofsmartmontools. It is officially compatible with Linux, Windows and FreeBSD,
as long as smartctl is on the system path. Running with administrative rights
is strongly recommended, as smartctl cannot accurately detect all device types
or parse all SMART information without these permissions.With only a device's name (ie: /dev/sda, pd0), the package will create aDeviceobject, populated with all relevant information about that
device. The documented API can then be used to query this object for
information, initiate self-tests, and perform other functions.UsageThe most common way to use pySMART is to create a logical representation of the
physical storage device that you would like to work with, as shown::>>>frompySMARTimportDevice>>>sda=Device('/dev/sda')>>>sda<SATAdeviceon/dev/sdamod:WDCWD5000AAKS-60Z1A0sn:WD-WCAWFxxxxxxx>Deviceclass members can be accessed directly, and a number of helper methods
are provided to retrieve information in bulk.  Some examples are shown below::>>>sda.assessment# Query the SMART self-assessment'PASS'>>>sda.attributes[9]# Query a single SMART attribute<SMARTAttribute'Power_On_Hours'068/000raw:23644>>>>sda.all_attributes()# Print the entire SMART attribute tableID# ATTRIBUTE_NAME          CUR WST THR TYPE     UPDATED WHEN_FAIL    RAW1Raw_Read_Error_Rate200200051Pre-failAlways-03Spin_Up_Time141140021Pre-failAlways-39084Start_Stop_Count098098000Old_ageAlways-26905Reallocated_Sector_Ct200200140Pre-failAlways-0...# Edited for brevity199UDMA_CRC_Error_Count200200000Old_ageAlways-0200Multi_Zone_Error_Rate200200000Old_ageOffline-0>>>sda.tests[0]# Query the most recent self-test result<SMARTSelf-test[Shortoffline|Completedwithouterror]hrs:23734LBA:->>>>sda.all_selftests()# Print the entire self-test logIDTest_DescriptionStatusLeftHours1st_Error@LBA1ShortofflineCompletedwithouterror00%23734-2ShortofflineCompletedwithouterror00%23734-...# Edited for brevity7ShortofflineCompletedwithouterror00%23726-8ShortofflineCompletedwithouterror00%1-Alternatively, the package provides aDeviceListclass. When instantiated,
this will auto-detect all local storage devices and create a list containing
oneDeviceobject for each detected storage device::>>>frompySMARTimportDeviceList>>>devlist=DeviceList()>>>devlist<DeviceListcontents:<SATdeviceon/dev/sdbmod:WDCWD20EADS-00R6B0sn:WD-WCAVYxxxxxxx><SATdeviceon/dev/sdcmod:WDCWD20EADS-00S2B0sn:WD-WCAVYxxxxxxx><CSMIdeviceon/dev/csmi0,0mod:WDCWD5000AAKS-60Z1A0sn:WD-WCAWFxxxxxxx>>>>>devlist.devices[0].attributes[5]# Access Device data as above<SMARTAttribute'Reallocated_Sector_Ct'173/140raw:214>In the above cases if a new DeviceList is empty or a specific Device reports an
"UNKNOWN INTERFACE", you are likely running without administrative privileges.
On POSIX systems, you can request smartctl is run as a superuser by setting the
sudo attribute of the global SMARTCTL object to True. Note this may cause you
to be prompted for a password.>>>frompySMARTimportDeviceList>>>frompySMARTimportDevice>>>sda=Device('/dev/sda')>>>sda<UNKNOWNINTERFACEdeviceon/dev/sdamod:Nonesn:None>>>>devlist=DeviceList()>>>devlist<DeviceListcontents:>>>>frompySMARTimportSMARTCTL>>>SMARTCTL.sudo=True>>>sda=Device('/dev/sda')>>>sda[sudo]passwordforuser:<SATdeviceon/dev/sdamod:ST10000DM0004-1ZC101sn:ZA20VNPT>>>>devlist=DeviceList()>>>devlist<DeviceListcontents:<NVMEdeviceon/dev/nvme0mod:SabrentRocket4.01TBsn:03850709185D88300410><NVMEdeviceon/dev/nvme1mod:SamsungSSD970EVOPlus2TBsn:S59CNM0RB05028D><NVMEdeviceon/dev/nvme2mod:SamsungSSD970EVOPlus2TBsn:S59CNM0RB05113H><SATdeviceon/dev/sdamod:ST10000DM0004-1ZC101sn:ZA20VNPT><SATdeviceon/dev/sdbmod:ST10000DM0004-1ZC101sn:ZA22W366><SATdeviceon/dev/sdcmod:ST10000DM0004-1ZC101sn:ZA22SPLG><SATdeviceon/dev/sddmod:ST10000DM0004-1ZC101sn:ZA2215HL>>In general, it is recommended to run the base script with enough privileges to
execute smartctl, but this is not possible in all cases, so this workaround is
provided as a convenience. However, note that using sudo inside other
non-terminal projects may cause dev-bugs/issues.Using the pySMART wrapper, Python applications be be rapidly developed to take
advantage of the powerful features of smartmontools.InstallationpySMARTis available on PyPI and installable viapip::python-mpipinstallpySMARTThe only external (non-python) dependency is thesmartctlcomponent of the smartmontools
package.  This should be pre-installed in most Linux distributions, or it
can be obtained through your package manager.  Likely one of the following::apt-getinstallsmartmontools#    oryuminstallsmartmontoolsOn Windows PC's, smartmontools must be downloaded and installed.  The latest
version can be obtained from the project's homepage,http://www.smartmontools.org/.Note that after installing smartmontools on Windows, the directory containingsmartctl.exemust be added to the system path, if it is not already.DocumentationAPI documentation forpySMARTwas generated usingpdocand can be
found in the /docs folder within the package archive.DevelopmentTests are run usingpytest.  Underfolder tests, there is a
readme with instructions on how to run the tests.AcknowledgementsI would like to thank the entire team behind smartmontools for creating and
maintaining such a fantastic product.In particular I want to thank Christian Franke, who maintains the Windows port
of the software.  For several years I have written Windows batch files that
rely on smartctl.exe to automate evaluation and testing of large pools of
storage devices.  Without his work, my job would have been significantly
more miserable. :)Additionally I would like to thank iXsystems, Inc., the team behind the amazing
FreeNAS and TrueNAS products.  Several years ago that team approached me with an
interest in pySMART, though I have no other affiliation with the company.  At
their request I made a simple change to allow pySMART to run on FreeBSD and
changed the license from GPL to LGPL to allow them to build upon my work and
incorporate it into their products.  They began hosting the code on their github,
and in the intervening years they've taken the project to all new heights.
Because of their work the code is now Python 3 compatible, supports NVME hardware
devices, and has several other improvements and bug fixes.Final Note on LicensingAt the request of several companies seeking to use this code in their products,
the license has been changed from GPL to the slightly more permissive LGPL.
This should allow you to call into pySMART as a library as use it as-is in your
own project without fear of "GPL contamination".  If you are reading this and
thinking that the license is still too restrictive, please contact me. I am very
willing to make the code available privately under a more permissive license,
including for some corporate or commercial uses. I'd just like for you to say hello
first, and tell me a bit about your project and how pySMART could fit into it.