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.
pip install pan-pythonVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade your Python environment to version 3.7 or later.
Initialize `PanXapi` with either `api_key` or `api_username` and `api_password`, but not both simultaneously.
When importing a file as bytes, ensure to pass a dummy string for the `filename` argument, e.g., `xapi.import_file(filename='temp_file.txt', file=your_bytes_data)`.
Reduce the `nlog` value to retrieve fewer log entries at a time or implement pagination/batching to manage memory usage.
For object-oriented interaction and higher-level configuration, consider using `pan-os-python`. For direct XML API interaction or specific commands not covered by `pan-os-python`, `pan-python` is appropriate.
Verify the API key is correct and ensure the user associated with the key has the necessary administrative roles and permissions on the PAN-OS device or Panorama.
Install the package using `pip install pan-python` in your active Python environment. If using a virtual environment, ensure it is activated.
Consult the `pan-python` documentation for available methods and attributes on `PanXapi` and other classes. If attempting a higher-level operation, consider if `pan-os-python` would be more appropriate.
Inspect the XML response structure from the device using `xapi.xml_result()` to confirm the exact key names. Use `.get('key_name', default_value)` for safer dictionary access.No dependency data recorded yet.