Python networking libraries

Updated Nov 2026

Python networking libraries build, send, capture, and decode network traffic below the level of an HTTP client. A packet library represents each protocol layer as an object that code can construct or parse from raw bytes. These libraries let security tools, network monitors, and automation scripts inspect and control traffic on a network.

Popularity

dnspython has the most monthly downloads in this comparison, at 295.8M.

LibraryMonthly downloadsStarsLast releaseLicense
dnspython
295.8M
2.7KNov 2026ISC
Paramiko
115.1M
9.9KOct 2026LGPL-2.1
Scapy
4.3M
12.7KOct 2026GPL-2.0-only
PyModbus
2.0M
2.8KNov 2026BSD-3-Clause
dpkt
1.6M
1.2KAug 2022BSD
python-pcapng
1.1M
129Aug 2022Apache-2.0
Pyroute2
1.0M
1.1KOct 2026GPL-2.0-or-later OR Apache-2.0
pyshark
979.1K
2.5KApr 2023MIT
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Provides a DNS toolkit.

Downloads / mo
295.8M
Stars
2.7K
Last release
2.9.2
License
ISC

Quickstart

From message.py
$ pip install dnspython
import dns.message

query = dns.message.make_query('example.com', 'A')
wire = query.to_wire()

Implements the SSH2 protocol.

Downloads / mo
115.1M
Stars
9.9K
Last release
5.1.0
License
LGPL-2.1

Quickstart

From client.py
$ pip install paramiko
from paramiko.client import SSHClient

client = SSHClient()
client.load_system_host_keys()
client.connect('ssh.example.com')
stdin, stdout, stderr = client.exec_command('ls -l')
client.close()

Paramiko examples

From open-source projects on GitHub

Builds, decodes, captures, and stores layered network packets.

Downloads / mo
4.3M
Stars
12.7K
Last release
2.8.0
License
GPL-2.0-only

Strengths

  • Combines packet construction and capture. Build protocol packets, capture traffic, and save packet files.
  • Reads PCAP and PCAPNG files. Use rdpcap to load captured packets into a packet list.

Limitations

  • Windows capture needs Npcap. Install Npcap for Scapy capture on Windows.
  • rdpcap returns a packet list. Choose streaming readers when a packet list is too large.

Quickstart

From usage.rst
$ pip install scapy
from scapy.all import IP, ICMP

packet = IP(dst='127.0.0.1') / ICMP()
packet.show2()

Implements the Modbus protocol stack in Python.

Downloads / mo
2.0M
Stars
2.8K
Last release
3.16.2
License
BSD-3-Clause

Quickstart

From README.rst
$ pip install pymodbus
from pymodbus.client import ModbusTcpClient

client = ModbusTcpClient("MyDevice.lan")
client.connect()
result = client.read_coils(1, count=1)
client.close()

PyModbus examples

From open-source projects on GitHub

Parses packet bytes into protocol objects and reads or writes capture files.

Downloads / mo
1.6M
Stars
1.2K
Last release
1.9.8
License
BSD

Strengths

  • Constructs packet objects from fields. Pass a byte buffer or named header fields to a packet constructor.
  • Writes standard capture containers. Use separate writers for PCAP and PCAPNG output.

Limitations

  • PCAPNG needs a different reader. Use dpkt.pcapng.Reader for PCAPNG captures.

Quickstart

From print_packets.py
$ pip install dpkt
import dpkt

packet = dpkt.ip.IP()
wire = bytes(packet)

python-pcapng

Reads and writes the pcap-ng format used by packet sniffers.

Downloads / mo
1.1M
Stars
129
Last release
2.1.1
License
Apache-2.0

Quickstart

From README.rst
$ pip install python-pcapng
from pcapng import FileScanner

with open('/tmp/mycapture.pcap', 'rb') as fp:
    scanner = FileScanner(fp)
    for block in scanner:
        print(block)

Exchanges Netlink messages from Python.

Downloads / mo
1.0M
Stars
1.1K
Last release
0.9.7
License
GPL-2.0-or-later OR Apache-2.0

Quickstart

From README.rst
$ pip install pyroute2
from pyroute2 import IPRoute

with IPRoute() as ipr:
    for link in ipr.get_links():
        print(link)

Wraps TShark to expose Wireshark-decoded packets in Python.

Downloads / mo
979.1K
Stars
2.5K
Last release
0.6
License
MIT

Strengths

  • Uses Wireshark protocol dissectors. Decode packets with the dissectors installed in TShark.
  • Applies capture display filters. Pass display_filter when opening a capture file.

Limitations

  • Requires a TShark installation. Install TShark separately; the Python package wraps its parser.

Quickstart

From README.md
$ pip install pyshark
import pyshark

capture = pyshark.FileCapture('capture.pcapng')
print(capture[0])
capture.close()

FAQ

Scapy suits building, sending, and decoding packets across many protocols. PyShark suits reading packets that Wireshark's dissectors have already decoded. dnspython suits DNS queries and messages.

Paramiko implements the SSH protocol in Python and supports SFTP file transfer over its sessions.

Scapy builds, decodes, captures, and stores layered network packets. Sending and capturing live traffic requires the matching system permissions.

PyModbus is a Modbus protocol stack with client, server, and simulator layers.

PyShark wraps TShark to expose packets decoded by Wireshark's dissectors in Python. It reads protocol fields rather than constructing new packets.

For coding agents

Found your networking library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official