Pan-Python is a multi-tool set for interacting with Palo Alto Networks PAN-OS, Panorama, WildFire, and AutoFocus platforms. It provides a powerful, low-level Python interface to the PAN-OS and Panorama XML API, as well as interfaces for WildFire, AutoFocus, and licensing APIs. The library is actively maintained, with its current version being 0.25.0, and receives regular updates.
Install & Compatibility
Where this runs
tested against v0.25.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.171s · 18.1MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.6s · import 0.156s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
from pan.xapi import PanXapi
from pan.wfapi import PanWFapi
from pan.afapi import PanAFapi
from pan.licapi import PanLicapi
This quickstart demonstrates how to connect to a Palo Alto Networks device (Firewall or Panorama) using `pan.xapi.PanXapi` and execute an operational command (`show system info`). It also includes a commented example for a configuration edit. Ensure you have the hostname/IP and an API key configured as environment variables for secure access.
import os
from pan.xapi import PanXapi, PanXapiError
hostname = os.environ.get('PAN_OS_HOSTNAME', 'your_firewall_ip')
api_key = os.environ.get('PAN_OS_API_KEY', 'your_api_key')
if not hostname or not api_key:
print("Please set PAN_OS_HOSTNAME and PAN_OS_API_KEY environment variables.")
exit(1)
try:
# Initialize the XAPI connection
xapi = PanXapi(hostname=hostname, api_key=api_key)
# Example 1: Execute an operational command (show system info)
print("\n--- Showing System Info ---")
xapi.op(cmd='show system info', cmd_xml=True)
if xapi.status == 'success':
print(xapi.xml_result())
else:
print(f"Error fetching system info: {xapi.status}: {xapi.status_detail}")
# Example 2: Edit a configuration element (e.g., disable a security rule)
# Note: This is a configuration change and requires appropriate permissions.
# For a real scenario, ensure rule 'rule7' exists and handle commit.
print("\n--- Attempting to disable 'rule7' ---")
xpath = "/config/devices/entry/vsys/entry/rulebase/security/rules/entry[@name='rule7']/disabled"
element = "<disabled>yes</disabled>"
# Example: Uncomment and adjust for your environment
# xapi.edit(xpath=xpath, element=element)
# if xapi.status == 'success':
# print("Rule 'rule7' disabled. Remember to commit changes.")
# else:
# print(f"Error disabling rule: {xapi.status}: {xapi.status_detail}")
except PanXapiError as e:
print(f"PanXapi Error: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
panxapi --version
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.