{"library":"pyzabbix","title":"PyZabbix","description":"PyZabbix provides a Python interface to the Zabbix API, allowing programmatic interaction with Zabbix monitoring systems. It handles API authentication, requests, and response parsing. The current version is 1.3.1, with releases occurring intermittently, often several months apart.","language":"python","status":"active","last_verified":"Sat May 16","install":{"commands":["pip install pyzabbix"],"cli":null},"imports":["from pyzabbix import ZabbixAPI","from pyzabbix import ZabbixAPIException"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom pyzabbix import ZabbixAPI, ZabbixAPIException\n\n# Configure Zabbix access via environment variables or replace directly\nZABBIX_URL = os.environ.get('ZABBIX_URL', 'http://localhost/zabbix') # e.g., 'http://your-zabbix-server/zabbix'\nZABBIX_USER = os.environ.get('ZABBIX_USER', 'Admin')\nZABBIX_PASSWORD = os.environ.get('ZABBIX_PASSWORD', 'zabbix') # Default 'zabbix' for Admin user\nZABBIX_TOKEN = os.environ.get('ZABBIX_TOKEN', '') # Optional: for API token authentication\n\n# Initialize zapi outside try-block for finally access\nzapi = None\n\ntry:\n    # Connect to Zabbix API\n    zapi = ZabbixAPI(ZABBIX_URL)\n\n    if ZABBIX_TOKEN:\n        # Authenticate using API token (requires Zabbix 5.0+ and pyzabbix >= 1.0.0)\n        zapi.login(api_token=ZABBIX_TOKEN)\n        print(\"Authenticated using API Token.\")\n    else:\n        # Authenticate using username and password\n        zapi.login(ZABBIX_USER, ZABBIX_PASSWORD)\n        print(f\"Authenticated as user: {ZABBIX_USER}\")\n\n    print(f\"Connected to Zabbix API version: {zapi.api_version()}\")\n\n    # Example: Fetch Zabbix server info\n    version_info = zapi.apiinfo.version()\n    print(f\"Zabbix Server Version: {version_info}\")\n\n    # Example: Fetch some hosts\n    # 'output' determines which fields are returned, 'selectInterfaces' specifies linked data\n    hosts = zapi.host.get(output='extend', selectInterfaces=['interfaceid', 'ip', 'port'])\n    print(f\"Found {len(hosts)} hosts.\")\n    if hosts:\n        print(f\"First host: {hosts[0]['host']} (IP: {hosts[0]['interfaces'][0]['ip']})\")\n\nexcept ZabbixAPIException as e:\n    print(f\"Error interacting with Zabbix API: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\nfinally:\n    # Ensure proper logout if authenticated\n    if zapi and zapi.is_authenticated:\n        zapi.logout()\n        print(\"Logged out from Zabbix API.\")\n","lang":"python","description":"This quickstart demonstrates how to connect to the Zabbix API, authenticate using either username/password or an API token (if provided via environment variables), retrieve basic Zabbix server information, and list hosts. It includes error handling for API-specific issues and ensures proper session cleanup with `logout()`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-16","installed_version":"1.3.1","pypi_latest":"1.3.1","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.3,"avg_import_s":0.6,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pyzabbix","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.63,"mem_mb":9.9,"disk_size":"22.0M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pyzabbix","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.3,"import_time_s":0.41,"mem_mb":9.9,"disk_size":"22M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pyzabbix","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.72,"mem_mb":10.9,"disk_size":"24.1M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pyzabbix","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.3,"import_time_s":0.64,"mem_mb":10.9,"disk_size":"25M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pyzabbix","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.66,"mem_mb":11.4,"disk_size":"15.9M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pyzabbix","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.1,"import_time_s":0.72,"mem_mb":11.4,"disk_size":"16M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pyzabbix","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.64,"mem_mb":11.8,"disk_size":"15.7M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pyzabbix","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.1,"import_time_s":0.61,"mem_mb":11.8,"disk_size":"16M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pyzabbix","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.51,"mem_mb":9.5,"disk_size":"21.2M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pyzabbix","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.7,"import_time_s":0.46,"mem_mb":9.5,"disk_size":"22M"}]}}