dnspython
Provides a DNS toolkit.
- Downloads / mo
- 295.8M
- Stars
- 2.7K
- Last release
- 2.9.2
- License
- ISC
Quickstart
import dns.message query = dns.message.make_query('example.com', 'A') wire = query.to_wire()
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.
dnspython has the most monthly downloads in this comparison, at 295.8M.
| Library | Monthly downloads | Stars | Last release | License |
|---|---|---|---|---|
| dnspython | 2.7K | Nov 2026 | ISC | |
| Paramiko | 9.9K | Oct 2026 | LGPL-2.1 | |
| Scapy | 12.7K | Oct 2026 | GPL-2.0-only | |
| PyModbus | 2.8K | Nov 2026 | BSD-3-Clause | |
| dpkt | 1.2K | Aug 2022 | BSD | |
| python-pcapng | 129 | Aug 2022 | Apache-2.0 | |
| Pyroute2 | 1.1K | Oct 2026 | GPL-2.0-or-later OR Apache-2.0 | |
| pyshark | 2.5K | Apr 2023 | MIT |
Provides a DNS toolkit.
import dns.message query = dns.message.make_query('example.com', 'A') wire = query.to_wire()
Implements the SSH2 protocol.
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()
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, )
Builds, decodes, captures, and stores layered network packets.
from scapy.all import IP, ICMP packet = IP(dst='127.0.0.1') / ICMP() packet.show2()
Implements the Modbus protocol stack in Python.
from pymodbus.client import ModbusTcpClient client = ModbusTcpClient("MyDevice.lan") client.connect() result = client.read_coils(1, count=1) client.close()
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
Parses packet bytes into protocol objects and reads or writes capture files.
import dpkt packet = dpkt.ip.IP() wire = bytes(packet)
Reads and writes the pcap-ng format used by packet sniffers.
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.
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.
import pyshark capture = pyshark.FileCapture('capture.pcapng') print(capture[0]) capture.close()
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
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
Add to ~/.cursor/mcp.json
{
"mcpServers": {
"exa": {
"url": "https://mcp.exa.ai/mcp"
}
}
}Open in your browser, then install the Exa plugin
https://chatgpt.com/plugins/exa
Add to .vscode/mcp.json
{
"servers": {
"exa": {
"type": "http",
"url": "https://mcp.exa.ai/mcp"
}
}
}In Devin, open Customize, then MCPs, and add a custom HTTP server with this URL
https://mcp.exa.ai/mcp
Add to ~/.config/devin/mcp_config.json
{
"mcpServers": {
"exa": {
"serverUrl": "https://mcp.exa.ai/mcp"
}
}
}Add to ~/.gemini/settings.json
{
"mcpServers": {
"exa": {
"httpUrl": "https://mcp.exa.ai/mcp"
}
}
}Add to opencode.json
{
"mcp": {
"exa": {
"type": "remote",
"url": "https://mcp.exa.ai/mcp"
}
}
}