{"library":"pyshark","title":"PyShark","description":"PyShark is a Python wrapper for TShark, the command-line network protocol analyzer that comes with Wireshark. It allows for Pythonic packet parsing and analysis by leveraging Wireshark's powerful dissection engine. The library is currently at version 0.6 and sees active development with several minor and patch releases per year, addressing compatibility and adding features.","language":"python","status":"active","last_verified":"Fri May 15","install":{"commands":["pip install pyshark"],"cli":{"name":"tshark","version":"sh: 1: tshark: not found"}},"imports":["from pyshark import LiveCapture","from pyshark import FileCapture"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import pyshark\nimport os\n\n# Ensure TShark is installed and in your system's PATH.\n# For Windows, you might need to specify the interface like r'\\Device\\NPF_{YOUR-GUID}'\n# For macOS, 'en0' or 'en1' are common.\n# For Linux, 'eth0' or 'wlan0' are common.\ninterface_name = os.environ.get('PYSHARK_INTERFACE', 'eth0')\n\ntry:\n    # Create a LiveCapture object to sniff on the specified interface\n    # Use display_filter for Wireshark-style filtering, e.g., 'http or dns'\n    capture = pyshark.LiveCapture(interface=interface_name)\n    \n    print(f\"Capturing 5 packets on {interface_name}...\")\n    for packet in capture.sniff_continuously(packet_count=5):\n        # Access packet layers and fields\n        protocol = packet.highest_layer\n        src = packet.ip.src if 'IP' in packet else 'N/A'\n        dst = packet.ip.dst if 'IP' in packet else 'N/A'\n        print(f\"Packet: {packet.number} | Time: {packet.sniff_time} | Protocol: {protocol} | Source: {src} -> Dest: {dst}\")\n        \n        # Example: print DNS query name if available\n        if 'DNS' in packet and hasattr(packet.dns, 'qry_name'):\n            print(f\"    DNS Query: {packet.dns.qry_name}\")\n\nexcept FileNotFoundError:\n    print(\"Error: TShark not found. Please ensure Wireshark/TShark is installed and in your system's PATH.\")\nexcept Exception as e:\n    print(f\"An error occurred during capture: {e}\")\nfinally:\n    if 'capture' in locals() and capture:\n        capture.close() # Important: ensure the capture process is closed to prevent resource leaks\n","lang":"python","description":"This quickstart demonstrates how to perform a live packet capture using `pyshark.LiveCapture`. It sniffs 5 packets on a specified network interface (defaulting to 'eth0' or an environment variable) and prints basic information about each packet. It also includes error handling for the common `TShark not found` issue and ensures the capture process is properly closed. Remember to replace 'eth0' with your actual network interface name or set the `PYSHARK_INTERFACE` environment variable.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-15","installed_version":"0.6","pypi_latest":"0.6","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.3,"avg_import_s":0.27,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pyshark","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.16,"mem_mb":6.7,"disk_size":"31.0M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pyshark","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.3,"import_time_s":0.11,"mem_mb":6.7,"disk_size":"31M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pyshark","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.25,"mem_mb":7.8,"disk_size":"33.0M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pyshark","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.2,"import_time_s":0.23,"mem_mb":7.8,"disk_size":"33M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pyshark","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.44,"mem_mb":8.2,"disk_size":"25.0M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pyshark","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2,"import_time_s":0.42,"mem_mb":8.2,"disk_size":"25M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pyshark","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.44,"mem_mb":8.7,"disk_size":"24.7M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pyshark","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.1,"import_time_s":0.41,"mem_mb":8.7,"disk_size":"25M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pyshark","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.14,"mem_mb":6.6,"disk_size":"30.5M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pyshark","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.8,"import_time_s":0.14,"mem_mb":6.6,"disk_size":"31M"}]}}