Skip to main content

TPM 2.0 TSS Bindings for Python

Project description


Build Status Total alerts Language grade: Python Code style: black PyPI version

TPM2 TSS Python bindings for Enhanced System API (ESYS).

Supported versions of Python are

  • 3.5
  • 3.6
  • 3.7
  • 3.8


We support the FAPI, ESAPI, and marshalling library.


This has been tested against TPM2 TSS 2.4.0, SWIG 3 and SWIG 4.


You need to install tpm2-tss prior to installing this,


You need to install pkg-config


You need to install swig


$ sudo apt-get -y install swig pkg-config


When you ran ./configure for tpm2-tss if you didn't supply a prefix it usually defaults to /usr/local/. When you ran make install it then installed the libraries under that path. Your pacakge manager usually installs libraries to /usr. If you properly configure the ldconfig tool, it'll make the libraries you just installed available from within /usr/local (which means they won't clash with things your package manager installs). If you don't configure it then you might get this error:

ImportError: cannot open shared object file: No such file or directory

We make a config file that tells ldconfig to look in /usr/local/lib for shared libraries, then we run ldconfig.

$ sudo mkdir -p /etc/
$ echo 'include /etc/*.conf' | sudo tee -a /etc/
$ echo '/usr/local/lib' | sudo tee -a /etc/
$ sudo ldconfig

More info on ldconfig error:


Install from PyPi.

$ python3 -m pip install tpm2-pytss

Or install from the master branch via GitHub

$ python3 -m pip install git+


See tests/ folder for example usage.


You need to have tpm_server installed in your path to run the tests.

Download the latest version from and put it somewher in your $PATH.

$ python3 test


To get traces of all calls into the TSS, use the TPM2_PYTSS_LOG_LEVEL environment variable.

$ export TPM2_PYTSS_LOG_LEVEL=debug

Example logs:

test_random_length (tests.test_esys_get_random.TestGetRandom) ... DEBUG:asyncio:Using selector: EpollSelector
    name: mssim,
    conf: port=63684,
    context: <Swig Object of type 'TSS2_TCTI_CONTEXT **' at 0x7f5e63d8ea50>,

    esys_context: <Swig Object of type 'ESYS_CONTEXT **' at 0x7f5e63d8e9f0>,
    tcti: <Swig Object of type 'TSS2_TCTI_CONTEXT *' at 0x7f5e63d8e5d0>,
    abiVersion: <tpm2_pytss.binding.TSS2_ABI_VERSION; proxy of <Swig Object of type 'TSS2_ABI_VERSION *' at 0x7f5e6337ab10> >,
    obj: <Swig Object of type 'ESYS_CONTEXT **' at 0x7f5e63d8e9f0>,
    esysContext: <Swig Object of type 'ESYS_CONTEXT *' at 0x7f5e63d8e7e0>,
    startupType: 0,
    esys_context: <Swig Object of type 'ESYS_CONTEXT *' at 0x7f5e63d8e7e0>,
    timeout: -1,
    esysContext: <Swig Object of type 'ESYS_CONTEXT *' at 0x7f5e63d8e7e0>,
    shandle1: 4095,
    shandle2: 4095,
    shandle3: 4095,
    bytesRequested: 11,
    randomBytes: <Swig Object of type 'TPM2B_NONCE **' at 0x7f5e63d8e8d0>,
    context: <Swig Object of type 'ESYS_CONTEXT **' at 0x7f5e63d8e9f0>,
    obj: <Swig Object of type 'ESYS_CONTEXT **' at 0x7f5e63d8e9f0>,



  • Document need for ctypes for certain values, example
  • ESYS_TR_PTR should be SessionContext

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for tpm2-pytss, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size tpm2-pytss-0.1.0.tar.gz (25.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page