pySMART


NamepySMART JSON
Version 1.2.3 PyPI version JSON
download
home_pagehttps://github.com/truenas/py-SMART
SummaryWrapper for smartctl (smartmontools)
upload_time2023-01-25 10:22:42
maintainer
docs_urlNone
authorMarc Herndon
requires_python
licenseGNU LGPLv2.1
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            pySMART
===========

![](https://img.shields.io/pypi/v/pySMART?label=release)
![](https://img.shields.io/pypi/pyversions/pySMART)
[![Python Tests](https://github.com/truenas/py-SMART/actions/workflows/check.yml/badge.svg)](https://github.com/truenas/py-SMART/actions/workflows/check.yml)
![](https://img.shields.io/github/actions/workflow/status/truenas/py-smart/publish-to-test-pypi.yml)
![](https://img.shields.io/github/issues/truenas/py-smart)
![](https://img.shields.io/github/issues-pr/truenas/py-smart)
![](https://img.shields.io/pypi/dm/pysmart)

Copyright (C) 2021-2023 [Rafael Leira](https://github.com/ralequi)\
Copyright (C) 2021 [Truenas team](https://www.truenas.com/)\
Copyright (C) 2015 Marc Herndon

pySMART is a simple Python wrapper for the ``smartctl`` component of
``smartmontools``. 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 a
``Device`` object, 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.

Usage
=====
The 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::


```python
>>> from pySMART import Device
>>> sda = Device('/dev/sda')
>>> sda
<SATA device on /dev/sda mod:WDC WD5000AAKS-60Z1A0 sn:WD-WCAWFxxxxxxx>
```

``Device`` class members can be accessed directly, and a number of helper methods
are provided to retrieve information in bulk.  Some examples are shown below::

```python
>>> sda.assessment  # Query the SMART self-assessment
'PASS'
>>> sda.attributes[9]  # Query a single SMART attribute
<SMART Attribute 'Power_On_Hours' 068/000 raw:23644>
>>> sda.all_attributes()  # Print the entire SMART attribute table
ID# ATTRIBUTE_NAME          CUR WST THR TYPE     UPDATED WHEN_FAIL    RAW
  1 Raw_Read_Error_Rate     200 200 051 Pre-fail Always  -           0
  3 Spin_Up_Time            141 140 021 Pre-fail Always  -           3908
  4 Start_Stop_Count        098 098 000 Old_age  Always  -           2690
  5 Reallocated_Sector_Ct   200 200 140 Pre-fail Always  -           0
    ... # Edited for brevity
199 UDMA_CRC_Error_Count    200 200 000 Old_age  Always  -           0
200 Multi_Zone_Error_Rate   200 200 000 Old_age  Offline -           0
>>> sda.tests[0]  # Query the most recent self-test result
<SMART Self-test [Short offline|Completed without error] hrs:23734 LBA:->
>>> sda.all_selftests()  # Print the entire self-test log
ID Test_Description Status                        Left Hours  1st_Error@LBA
 1 Short offline    Completed without error       00%  23734  -
 2 Short offline    Completed without error       00%  23734  -
   ... # Edited for brevity
 7 Short offline    Completed without error       00%  23726  -
 8 Short offline    Completed without error       00%  1      -
```

Alternatively, the package provides a ``DeviceList`` class. When instantiated,
this will auto-detect all local storage devices and create a list containing
one ``Device`` object for each detected storage device::

```python
>>> from pySMART import DeviceList
>>> devlist = DeviceList()
>>> devlist
<DeviceList contents:
<SAT device on /dev/sdb mod:WDC WD20EADS-00R6B0 sn:WD-WCAVYxxxxxxx>
<SAT device on /dev/sdc mod:WDC WD20EADS-00S2B0 sn:WD-WCAVYxxxxxxx>
<CSMI device on /dev/csmi0,0 mod:WDC WD5000AAKS-60Z1A0 sn:WD-WCAWFxxxxxxx>
>
>>> devlist.devices[0].attributes[5]  # Access Device data as above
<SMART Attribute 'Reallocated_Sector_Ct' 173/140 raw: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.


```python
>>> from pySMART import DeviceList
>>> from pySMART import Device
>>> sda = Device('/dev/sda')
>>> sda
<UNKNOWN INTERFACE device on /dev/sda mod:None sn:None>
>>> devlist = DeviceList()
>>> devlist
<DeviceList contents:
>
>>> from pySMART import SMARTCTL
>>> SMARTCTL.sudo = True
>>> sda = Device('/dev/sda')
>>> sda
[sudo] password for user:
<SAT device on /dev/sda mod:ST10000DM0004-1ZC101 sn:ZA20VNPT>
>>> devlist = DeviceList()
>>> devlist
<DeviceList contents:
<NVME device on /dev/nvme0 mod:Sabrent Rocket 4.0 1TB sn:03850709185D88300410>
<NVME device on /dev/nvme1 mod:Samsung SSD 970 EVO Plus 2TB sn:S59CNM0RB05028D>
<NVME device on /dev/nvme2 mod:Samsung SSD 970 EVO Plus 2TB sn:S59CNM0RB05113H>
<SAT device on /dev/sda mod:ST10000DM0004-1ZC101 sn:ZA20VNPT>
<SAT device on /dev/sdb mod:ST10000DM0004-1ZC101 sn:ZA22W366>
<SAT device on /dev/sdc mod:ST10000DM0004-1ZC101 sn:ZA22SPLG>
<SAT device on /dev/sdd mod:ST10000DM0004-1ZC101 sn: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.

Installation
============
``pySMART`` is available on PyPI and installable via ``pip``::

```bash
python -m pip install pySMART
```

The only external (non-python) dependency is the ``smartctl`` component 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::

```bash
apt-get install smartmontools
#    or
yum install smartmontools
```

On 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 containing
``smartctl.exe`` must be added to the system path, if it is not already.

Documentation
=============
API documentation for ``pySMART`` was generated using ``pdoc`` and can be
found in the /docs folder within the package archive.

Acknowledgements
================
I 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 Licensing
=======================
At 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. 

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/truenas/py-SMART",
    "name": "pySMART",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Marc Herndon",
    "author_email": "Herndon.MarcT@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e9/f9/93f6fa6cd6035caf2cfb46358ebc5e639824690e00289f10c457fe692de7/pySMART-1.2.3.tar.gz",
    "platform": null,
    "description": "pySMART\n===========\n\n![](https://img.shields.io/pypi/v/pySMART?label=release)\n![](https://img.shields.io/pypi/pyversions/pySMART)\n[![Python Tests](https://github.com/truenas/py-SMART/actions/workflows/check.yml/badge.svg)](https://github.com/truenas/py-SMART/actions/workflows/check.yml)\n![](https://img.shields.io/github/actions/workflow/status/truenas/py-smart/publish-to-test-pypi.yml)\n![](https://img.shields.io/github/issues/truenas/py-smart)\n![](https://img.shields.io/github/issues-pr/truenas/py-smart)\n![](https://img.shields.io/pypi/dm/pysmart)\n\nCopyright (C) 2021-2023 [Rafael Leira](https://github.com/ralequi)\\\nCopyright (C) 2021 [Truenas team](https://www.truenas.com/)\\\nCopyright (C) 2015 Marc Herndon\n\npySMART is a simple Python wrapper for the ``smartctl`` component of\n``smartmontools``. It is officially compatible with Linux, Windows and FreeBSD,\nas long as smartctl is on the system path. Running with administrative rights\nis strongly recommended, as smartctl cannot accurately detect all device types\nor parse all SMART information without these permissions.\n\nWith only a device's name (ie: /dev/sda, pd0), the package will create a\n``Device`` object, populated with all relevant information about that\ndevice. The documented API can then be used to query this object for\ninformation, initiate self-tests, and perform other functions.\n\nUsage\n=====\nThe most common way to use pySMART is to create a logical representation of the\nphysical storage device that you would like to work with, as shown::\n\n\n```python\n>>> from pySMART import Device\n>>> sda = Device('/dev/sda')\n>>> sda\n<SATA device on /dev/sda mod:WDC WD5000AAKS-60Z1A0 sn:WD-WCAWFxxxxxxx>\n```\n\n``Device`` class members can be accessed directly, and a number of helper methods\nare provided to retrieve information in bulk.  Some examples are shown below::\n\n```python\n>>> sda.assessment  # Query the SMART self-assessment\n'PASS'\n>>> sda.attributes[9]  # Query a single SMART attribute\n<SMART Attribute 'Power_On_Hours' 068/000 raw:23644>\n>>> sda.all_attributes()  # Print the entire SMART attribute table\nID# ATTRIBUTE_NAME          CUR WST THR TYPE     UPDATED WHEN_FAIL    RAW\n  1 Raw_Read_Error_Rate     200 200 051 Pre-fail Always  -           0\n  3 Spin_Up_Time            141 140 021 Pre-fail Always  -           3908\n  4 Start_Stop_Count        098 098 000 Old_age  Always  -           2690\n  5 Reallocated_Sector_Ct   200 200 140 Pre-fail Always  -           0\n    ... # Edited for brevity\n199 UDMA_CRC_Error_Count    200 200 000 Old_age  Always  -           0\n200 Multi_Zone_Error_Rate   200 200 000 Old_age  Offline -           0\n>>> sda.tests[0]  # Query the most recent self-test result\n<SMART Self-test [Short offline|Completed without error] hrs:23734 LBA:->\n>>> sda.all_selftests()  # Print the entire self-test log\nID Test_Description Status                        Left Hours  1st_Error@LBA\n 1 Short offline    Completed without error       00%  23734  -\n 2 Short offline    Completed without error       00%  23734  -\n   ... # Edited for brevity\n 7 Short offline    Completed without error       00%  23726  -\n 8 Short offline    Completed without error       00%  1      -\n```\n\nAlternatively, the package provides a ``DeviceList`` class. When instantiated,\nthis will auto-detect all local storage devices and create a list containing\none ``Device`` object for each detected storage device::\n\n```python\n>>> from pySMART import DeviceList\n>>> devlist = DeviceList()\n>>> devlist\n<DeviceList contents:\n<SAT device on /dev/sdb mod:WDC WD20EADS-00R6B0 sn:WD-WCAVYxxxxxxx>\n<SAT device on /dev/sdc mod:WDC WD20EADS-00S2B0 sn:WD-WCAVYxxxxxxx>\n<CSMI device on /dev/csmi0,0 mod:WDC WD5000AAKS-60Z1A0 sn:WD-WCAWFxxxxxxx>\n>\n>>> devlist.devices[0].attributes[5]  # Access Device data as above\n<SMART Attribute 'Reallocated_Sector_Ct' 173/140 raw:214>\n```\n\nIn the above cases if a new DeviceList is empty or a specific Device reports an\n\"UNKNOWN INTERFACE\", you are likely running without administrative privileges.\nOn POSIX systems, you can request smartctl is run as a superuser by setting the\nsudo attribute of the global SMARTCTL object to True. Note this may cause you\nto be prompted for a password.\n\n\n```python\n>>> from pySMART import DeviceList\n>>> from pySMART import Device\n>>> sda = Device('/dev/sda')\n>>> sda\n<UNKNOWN INTERFACE device on /dev/sda mod:None sn:None>\n>>> devlist = DeviceList()\n>>> devlist\n<DeviceList contents:\n>\n>>> from pySMART import SMARTCTL\n>>> SMARTCTL.sudo = True\n>>> sda = Device('/dev/sda')\n>>> sda\n[sudo] password for user:\n<SAT device on /dev/sda mod:ST10000DM0004-1ZC101 sn:ZA20VNPT>\n>>> devlist = DeviceList()\n>>> devlist\n<DeviceList contents:\n<NVME device on /dev/nvme0 mod:Sabrent Rocket 4.0 1TB sn:03850709185D88300410>\n<NVME device on /dev/nvme1 mod:Samsung SSD 970 EVO Plus 2TB sn:S59CNM0RB05028D>\n<NVME device on /dev/nvme2 mod:Samsung SSD 970 EVO Plus 2TB sn:S59CNM0RB05113H>\n<SAT device on /dev/sda mod:ST10000DM0004-1ZC101 sn:ZA20VNPT>\n<SAT device on /dev/sdb mod:ST10000DM0004-1ZC101 sn:ZA22W366>\n<SAT device on /dev/sdc mod:ST10000DM0004-1ZC101 sn:ZA22SPLG>\n<SAT device on /dev/sdd mod:ST10000DM0004-1ZC101 sn:ZA2215HL>\n>\n```\n\nIn general, it is recommended to run the base script with enough privileges to\nexecute smartctl, but this is not possible in all cases, so this workaround is\nprovided as a convenience. However, note that using sudo inside other\nnon-terminal projects may cause dev-bugs/issues.\n\nUsing the pySMART wrapper, Python applications be be rapidly developed to take\nadvantage of the powerful features of smartmontools.\n\nInstallation\n============\n``pySMART`` is available on PyPI and installable via ``pip``::\n\n```bash\npython -m pip install pySMART\n```\n\nThe only external (non-python) dependency is the ``smartctl`` component of the smartmontools\npackage.  This should be pre-installed in most Linux distributions, or it\ncan be obtained through your package manager.  Likely one of the following::\n\n```bash\napt-get install smartmontools\n#    or\nyum install smartmontools\n```\n\nOn Windows PC's, smartmontools must be downloaded and installed.  The latest\nversion can be obtained from the project's homepage, http://www.smartmontools.org/.\n\nNote that after installing smartmontools on Windows, the directory containing\n``smartctl.exe`` must be added to the system path, if it is not already.\n\nDocumentation\n=============\nAPI documentation for ``pySMART`` was generated using ``pdoc`` and can be\nfound in the /docs folder within the package archive.\n\nAcknowledgements\n================\nI would like to thank the entire team behind smartmontools for creating and\nmaintaining such a fantastic product.\n\nIn particular I want to thank Christian Franke, who maintains the Windows port\nof the software.  For several years I have written Windows batch files that\nrely on smartctl.exe to automate evaluation and testing of large pools of\nstorage devices.  Without his work, my job would have been significantly\nmore miserable. :)\n\nAdditionally I would like to thank iXsystems, Inc., the team behind the amazing\nFreeNAS and TrueNAS products.  Several years ago that team approached me with an\ninterest in pySMART, though I have no other affiliation with the company.  At\ntheir request I made a simple change to allow pySMART to run on FreeBSD and\nchanged the license from GPL to LGPL to allow them to build upon my work and\nincorporate it into their products.  They began hosting the code on their github,\nand in the intervening years they've taken the project to all new heights.\nBecause of their work the code is now Python 3 compatible, supports NVME hardware\ndevices, and has several other improvements and bug fixes.\n\nFinal Note on Licensing\n=======================\nAt the request of several companies seeking to use this code in their products,\nthe license has been changed from GPL to the slightly more permissive LGPL.\nThis should allow you to call into pySMART as a library as use it as-is in your\nown project without fear of \"GPL contamination\".  If you are reading this and\nthinking that the license is still too restrictive, please contact me. I am very\nwilling to make the code available privately under a more permissive license,\nincluding for some corporate or commercial uses. I'd just like for you to say hello\nfirst, and tell me a bit about your project and how pySMART could fit into it. \n",
    "bugtrack_url": null,
    "license": "GNU LGPLv2.1",
    "summary": "Wrapper for smartctl (smartmontools)",
    "version": "1.2.3",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3fc984dc856a9b8a1041335bdd9b7d74c0711fd22f7c19281d344b48967845bc",
                "md5": "5fd51f9c9d2cb5d86bb3a8a9d667049c",
                "sha256": "5fb02244043c2d55679d749accde2209ae9af974e43d0e15d8c503d7bfec5ede"
            },
            "downloads": -1,
            "filename": "pySMART-1.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5fd51f9c9d2cb5d86bb3a8a9d667049c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 54699,
            "upload_time": "2023-01-25T10:22:40",
            "upload_time_iso_8601": "2023-01-25T10:22:40.647038Z",
            "url": "https://files.pythonhosted.org/packages/3f/c9/84dc856a9b8a1041335bdd9b7d74c0711fd22f7c19281d344b48967845bc/pySMART-1.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e9f993f6fa6cd6035caf2cfb46358ebc5e639824690e00289f10c457fe692de7",
                "md5": "c733776086bc17ef426717a3f6677a38",
                "sha256": "982bb4c7d10f694aa0ea155aec7a4abdf9fd9e5d1ce414ee511f8400767cc3df"
            },
            "downloads": -1,
            "filename": "pySMART-1.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "c733776086bc17ef426717a3f6677a38",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 194553,
            "upload_time": "2023-01-25T10:22:42",
            "upload_time_iso_8601": "2023-01-25T10:22:42.433014Z",
            "url": "https://files.pythonhosted.org/packages/e9/f9/93f6fa6cd6035caf2cfb46358ebc5e639824690e00289f10c457fe692de7/pySMART-1.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-25 10:22:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "truenas",
    "github_project": "py-SMART",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pysmart"
}
        
Elapsed time: 0.10252s