# Python networking libraries

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

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [dnspython](#dnspython) | 295.8M | 2.7K | Nov 2026 | ISC |
| [Paramiko](#paramiko) | 115.1M | 9.9K | Oct 2026 | LGPL-2.1 |
| [Scapy](#scapy) | 4.3M | 12.7K | Oct 2026 | GPL-2.0-only |
| [PyModbus](#pymodbus) | 2.0M | 2.8K | Nov 2026 | BSD-3-Clause |
| [dpkt](#dpkt) | 1.6M | 1.2K | Aug 2022 | BSD |
| [python-pcapng](#python-pcapng) | 1.1M | 129 | Aug 2022 | Apache-2.0 |
| [Pyroute2](#pyroutetwo) | 1.0M | 1.1K | Oct 2026 | GPL-2.0-or-later OR Apache-2.0 |
| [pyshark](#pyshark) | 979.1K | 2.5K | Apr 2023 | MIT |

Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[dnspython](#dnspython) has the most monthly downloads in this comparison, at 295.8M.

## Capabilities

| Library | Build protocol packets | Read capture files |
| --- | --- | --- |
| [dnspython](#dnspython) | Yes | No |
| [Paramiko](#paramiko) | Yes | No |
| [Scapy](#scapy) | Yes | Yes |
| [PyModbus](#pymodbus) | Yes | No |
| [dpkt](#dpkt) | Yes | Yes |
| [python-pcapng](#python-pcapng) | No | Yes |
| [Pyroute2](#pyroutetwo) | Yes | Undocumented |
| [pyshark](#pyshark) | No | Yes |

## Libraries

### dnspython

[GitHub](https://github.com/rthalley/dnspython) · [PyPI](https://pypi.org/project/dnspython) · [Docs](https://dnspython.readthedocs.io/en/stable/)

Provides a DNS toolkit.

- Downloads / mo: 295.8M
- Stars: 2.7K
- Last release: 2.9.2
- License: ISC
- Capabilities: [From the dnspython docs](https://dnspython.readthedocs.io/en/stable/)

```sh
pip install dnspython
```

**Quickstart**

```python
import dns.message

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

```

From [message.py](https://dnspython.readthedocs.io/en/stable/message-make.html) · [Find projects using dnspython →](https://dashboard.exa.ai/playground/search?q=dnspython%20GitHub%20projects)

### Paramiko

[GitHub](https://github.com/paramiko/paramiko) · [PyPI](https://pypi.org/project/paramiko) · [Docs](https://docs.paramiko.org/en/stable/)

Implements the SSH2 protocol.

- Downloads / mo: 115.1M
- Stars: 9.9K
- Last release: 5.1.0
- License: LGPL-2.1
- Capabilities: [From the Paramiko docs](https://docs.paramiko.org/en/stable/)

```sh
pip install paramiko
```

**fabric/fabric** (15.5K stars)

[fabric/fabric](https://github.com/fabric/fabric) 

```python
def get(self, remote, local=None, preserve_mode=True):
    """
    Copy a file from wrapped connection's host to the local filesystem.

    :param str remote:
        Remote file to download.

        May be absolute, or relative to the remote working directory.

        .. note::
            Most SFTP servers set the remote working directory to the
            connecting user's home directory, and (unlike most shells) do
            *not* expand tildes (``~``).

            For example, instead of saying ``get("~/tmp/archive.tgz")``,
            say ``get("tmp/archive.tgz")``.

    :param local:
        Local path to store downloaded file in, or a file-like object.

        **If None or another 'falsey'/empty value is given** (the default),
        the remote file is downloaded to the current working directory (as
        seen by `os.getcwd`) using its remote filename. (This is equivalent
        to giving ``"{basename}"``; see the below subsection on
        interpolation.)

        **If a string is given**, it should be a path to a local directory
        or file and is subject to similar behavior as that seen by common
        Unix utilities or OpenSSH's ``sftp`` or ``scp`` tools.

        For example, if the local path is a directory, the remote path's
        base filename will be added onto it (so ``get('foo/bar/file.txt',
        '/tmp/')`` would result in creation or overwriting of
        ``/tmp/file.txt``).

        This path will be **interpolated** with some useful parameters,
        using `str.format`:

        - The `.Connection` object's ``host``, ``user`` and ``port``
          attributes.
        - The ``basename`` and ``dirname`` of the ``remote`` path, as
          derived by `os.path` (specifically, its ``posixpath`` flavor, so
          that the resulting values are useful on remote POSIX-compatible
          SFTP servers even if the local client is Windows).
        - Thus, for example, ``"/some/path/{user}@{host}/{basename}"`` will
          yield different local paths depending on the properties of both
          the connection and the remote path.

        .. note::
            If nonexistent directories are present in this path (including
            the final path component, if it ends in `os.sep`) they will be
            created automatically using `os.makedirs`.

        **If a file-like object is given**, the contents of the remote file
        are simply written into it.

    :param bool preserve_mode:
        Whether to `os.chmod` the local file so it matches the remote
        file's mode (default: ``True``).

    :returns: A `.Result` object.

    .. versionadded:: 2.0
    .. versionchanged:: 2.6
        Added ``local`` path interpolation of connection & remote file
        attributes.
    .. versionchanged:: 2.6
        Create missing ``local`` directories automatically.
    """
    # TODO: how does this API change if we want to implement
    # remote-to-remote file transfer? (Is that even realistic?)
    # TODO: callback support
    # TODO: how best to allow changing the behavior/semantics of
    # remote/local (e.g. users might want 'safer' behavior that complains
    # instead of overwriting existing files) - this likely ties into the
    # "how to handle recursive/rsync" and "how to handle scp" questions

    # Massage remote path
    if not remote:
        raise ValueError("Remote path must not be empty!")
    orig_remote = remote
    remote = posixpath.join(
        self.sftp.getcwd() or self.sftp.normalize("."), remote
    )

    # Massage local path
    orig_local = local
    is_file_like = hasattr(local, "write") and callable(local.write)
    remote_filename = posixpath.basename(remote)
    if not local:
        local = remote_filename
    # Path-driven local downloads need interpolation, abspath'ing &
    # directory creation
    if not is_file_like:
        local = local.format(
            host=self.connection.host,
            user=self.connection.user,
            port=self.connection.port,
            dirname=posixpath.dirname(remote),
            basename=remote_filename,
        )
        # Must treat dir vs file paths differently, lest we erroneously
        # mkdir what was intended as a filename, and so that non-empty
        # dir-like paths still get remote filename tacked on.
        if local.endswith(os.sep):
            dir_path = local
            local = os.path.join(local, remote_filename)
        else:
            dir_path, _ = os.path.split(local)
        local = os.path.abspath(local)
        Path(dir_path).mkdir(parents=True, exist_ok=True)
        # TODO: reimplement mkdir (or otherwise write a testing function)
        # allowing us to track what was created so we can revert if
        # transfer fails.
        # TODO: Alternately, transfer to temp location and then move, but
        # that's basically inverse of v1's sudo-put which gets messy

    # Run Paramiko-level .get() (side-effects only. womp.)
    # TODO: push some of the path handling into Paramiko; it should be
    # responsible for dealing with path cleaning etc.
    # TODO: probably preserve warning message from v1 when overwriting
    # existing files. Use logging for that obviously.
    #
    # If local appears to be a file-like object, use sftp.getfo, not get
    if is_file_like:
        self.sftp.getfo(remotepath=remote, fl=local)
    else:
        self.sftp.get(remotepath=remote, localpath=local)
        # Set mode to same as remote end
        # TODO: Push this down into SFTPClient sometime (requires backwards
        # incompat release.)
        if preserve_mode:
            remote_mode = self.sftp.stat(remote).st_mode
            mode = stat.S_IMODE(remote_mode)
            os.chmod(local, mode)
    # Return something useful
    return Result(
        orig_remote=orig_remote,
        remote=remote,
        orig_local=orig_local,
        local=local,
        connection=self.connection,
    )

```

[fabric/transfer.py](https://github.com/fabric/fabric/blob/ded51893f02c33d2bc7c157624c44a039a952037/fabric/transfer.py#L43-L185) · [More projects using Paramiko →](https://dashboard.exa.ai/playground/search?q=paramiko%20GitHub%20projects)

**Quickstart**

```python
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()

```

From [client.py](https://docs.paramiko.org/en/stable/api/client.html)

### Scapy

[GitHub](https://github.com/secdev/scapy) · [PyPI](https://pypi.org/project/scapy) · [Docs](https://scapy.readthedocs.io/en/latest/)

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
- Capabilities: [From the Scapy docs](https://scapy.readthedocs.io/en/latest/)

**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.

**Watch out for**

- **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.

```sh
pip install scapy
```

**Quickstart**

```python
from scapy.all import IP, ICMP

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

```

From [usage.rst](https://github.com/secdev/scapy/blob/master/doc/scapy/usage.rst) · [Find projects using Scapy →](https://dashboard.exa.ai/playground/search?q=Projects%20using%20scapy%20for%20packet%20and%20capture%20processing&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### PyModbus

[GitHub](https://github.com/pymodbus-dev/pymodbus) · [PyPI](https://pypi.org/project/pymodbus) · [Docs](https://pymodbus.readthedocs.io/en/latest/)

Implements the Modbus protocol stack in Python.

- Downloads / mo: 2.0M
- Stars: 2.8K
- Last release: 3.16.2
- License: BSD-3-Clause
- Capabilities: [From the PyModbus docs](https://pymodbus.readthedocs.io/en/latest/)

```sh
pip install pymodbus
```

**home-assistant/core** (92.4K stars)

[home-assistant/core](https://github.com/home-assistant/core) 

```python
async def low_level_pb_call(
    self, slave: int | None, address: int, value: int | list[int], use_call: str
) -> ModbusPDU | None:
    """Call sync. pymodbus."""
    kwargs: dict[str, Any] = (
        {DEVICE_ID: slave} if slave is not None else {DEVICE_ID: 1}
    )
    entry = self._pb_request[use_call]

    if use_call in {"write_registers", "write_coils"}:
        if not isinstance(value, list):
            value = [value]

    kwargs[entry.value_attr_name] = value
    try:
        result: ModbusPDU = await entry.func(address, **kwargs)
    except ModbusException as exception_error:
        error = f"Error: device: {slave} address: {address} -> {exception_error!s}"
        self._log_error(error)
        return None
    if not hasattr(result, entry.attr):
        error = f"Error: device: {slave} address: {address} -> {result!s}"
        self._log_error(error)
        return None
    if result.isError():
        error = (
            f"Error: device: {slave} address: {address}"
            " -> pymodbus returned isError True"
        )
        self._log_error(error)
        return None
    return result
```

[homeassistant/components/modbus/modbus.py](https://github.com/home-assistant/core/blob/934a88b30bd07cac96f119ef111dc6508e58e1bf/homeassistant/components/modbus/modbus.py#L324-L355) · [More projects using PyModbus →](https://dashboard.exa.ai/playground/search?q=pymodbus%20GitHub%20projects)

**Quickstart**

```python
from pymodbus.client import ModbusTcpClient

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

From [README.rst](https://github.com/pymodbus-dev/pymodbus/blob/21842b1eb2d3d2790d55bfbb8862b1003697488a/README.rst)

### dpkt

[GitHub](https://github.com/kbandla/dpkt) · [PyPI](https://pypi.org/project/dpkt) · [Docs](https://dpkt.readthedocs.io/en/latest/)

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
- Capabilities: [From the dpkt docs](https://dpkt.readthedocs.io/en/latest/)

**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.

**Watch out for**

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

```sh
pip install dpkt
```

**Quickstart**

```python
import dpkt

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

```

From [print_packets.py](https://github.com/kbandla/dpkt/blob/master/dpkt/ip.py) · [Find projects using dpkt →](https://dashboard.exa.ai/playground/search?q=Projects%20using%20dpkt%20for%20packet%20and%20capture%20processing&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### python-pcapng

[GitHub](https://github.com/rshk/python-pcapng) · [PyPI](https://pypi.org/project/python-pcapng) · [Docs](https://python-pcapng.readthedocs.io/en/latest/)

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
- Capabilities: [From the python-pcapng docs](https://python-pcapng.readthedocs.io/en/latest/)

```sh
pip install python-pcapng
```

**Quickstart**

```python
from pcapng import FileScanner

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

```

From [README.rst](https://github.com/rshk/python-pcapng/blob/master/README.rst) · [Find projects using python-pcapng →](https://dashboard.exa.ai/playground/search?q=python-pcapng%20GitHub%20projects)

### Pyroute2

[GitHub](https://github.com/svinota/pyroute2) · [PyPI](https://pypi.org/project/pyroute2) · [Docs](https://docs.pyroute2.org/)

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
- Capabilities: [From the Pyroute2 docs](https://docs.pyroute2.org/)

```sh
pip install pyroute2
```

**Quickstart**

```python
from pyroute2 import IPRoute

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

```

From [README.rst](https://github.com/svinota/pyroute2/blob/master/README.rst) · [Find projects using Pyroute2 →](https://dashboard.exa.ai/playground/search?q=pyroute2%20GitHub%20projects)

### pyshark

[GitHub](https://github.com/KimiNewt/pyshark) · [PyPI](https://pypi.org/project/pyshark) · [Docs](https://pyshark-packet-analysis.readthedocs.io/en/latest/)

Wraps TShark to expose Wireshark-decoded packets in Python.

- Downloads / mo: 979.1K
- Stars: 2.5K
- Last release: 0.6
- License: MIT
- Capabilities: [From the pyshark docs](https://pyshark-packet-analysis.readthedocs.io/en/latest/)

**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.

**Watch out for**

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

```sh
pip install pyshark
```

**Quickstart**

```python
import pyshark

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

```

From [README.md](https://github.com/KimiNewt/pyshark/blob/master/src/pyshark/capture/file_capture.py) · [Find projects using pyshark →](https://dashboard.exa.ai/playground/search?q=Projects%20using%20pyshark%20for%20packet%20and%20capture%20processing&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

## FAQ

### Which Python networking library should I use?

[Scapy](#scapy) suits building, sending, and decoding packets across many protocols. [PyShark](#pyshark) suits reading packets that Wireshark's dissectors have already decoded. [dnspython](#dnspython) suits DNS queries and messages.

### What is Paramiko?

[Paramiko](#paramiko) implements the SSH protocol in Python and supports SFTP file transfer over its sessions.

### What is Scapy?

[Scapy](#scapy) builds, decodes, captures, and stores layered network packets. Sending and capturing live traffic requires the matching system permissions.

### What is PyModbus?

[PyModbus](#pymodbus) is a Modbus protocol stack with client, server, and simulator layers.

### What is PyShark?

[PyShark](#pyshark) wraps TShark to expose packets decoded by Wireshark's dissectors in Python. It reads protocol fields rather than constructing new packets.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best Python networking packet libraries Scapy dpkt PyShark Impacket code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
