Registry / devops / pan-python

pan-python

JSON →
library0.25.0pypypi✓ verified 35d ago

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.

devopshttp-networkingauth-security
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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.171s · 18.1MB
glibc
py 3.103.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
Debug
Known footguns
breakingPython 2 support was entirely removed starting from v0.19.0. Pan-Python now strictly requires Python 3.7 or newer.
gotchaWhen initializing `PanXapi`, providing both `api_key` and `api_username`/`api_password` is redundant. It is recommended to use only the `api_key` for authentication for simplicity and often better security practices.
gotchaThe `pan.xapi.PanXapi.import_file()` method, when used with `file` as bytes, requires a `filename` argument, even if it's a dummy string, as it's a required parameter.
gotchaUsing a large `nlog` value in `pan.xapi.PanXapi.log()` can lead to memory exceptions as the entire XML document is loaded into memory by the `ElementTree` module.
gotcha`pan-python` provides a low-level XML API interface, while `pan-os-python` is an object-oriented SDK. Ensure you are using the correct library for your automation needs; `pan-os-python` typically offers a more abstract and user-friendly experience for configuration tasks.
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.

Agent activity
12 hits · last 30 days
gptbot
4
ahrefsbot
4
bytedance
2
script
1
chatgpt-user
1
Resources