Tenable API Client (pyTenable)

1.9.1 · active · verified Thu Apr 16

pyTenable is the official Python library for interacting with Tenable's cybersecurity platforms, including Tenable.io and Tenable.sc. It provides a convenient, object-oriented interface to the various APIs, simplifying common tasks like vulnerability management, asset discovery, and compliance checks. The library is actively maintained, with frequent minor and patch releases to support new API features and address issues; its current version is 1.9.1.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes a Tenable.io client using environment variables for authentication and then lists all active scans. It demonstrates the basic structure for interacting with Tenable.io APIs through the `TenableIO` object.

import os
from tenable.io import TenableIO

# Ensure TENABLE_ACCESS_KEY and TENABLE_SECRET_KEY environment variables are set
access_key = os.environ.get('TENABLE_ACCESS_KEY', '')
secret_key = os.environ.get('TENABLE_SECRET_KEY', '')

if not access_key or not secret_key:
    print("Error: TENABLE_ACCESS_KEY and TENABLE_SECRET_KEY environment variables must be set.")
    exit(1)

tio = TenableIO(access_key, secret_key)

# Example: List active scans
try:
    print("Retrieving active scans...")
    scans = tio.scans.list()
    for scan in scans:
        print(f"Scan ID: {scan['id']}, Name: {scan['name']}, Status: {scan['status']}")
    
    if not scans:
        print("No active scans found.")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →