pyroute2
Python Netlink library
What it is and what it does
Pyroute2 is a pure Python networking framework that exposes Linux netlink protocols for programmatic control of network configuration. It started as an RTNL (routing netlink) implementation but now supports multiple protocol families including DHCP, netfilter, generic netlink, and others. The core requires only Python's standard library, with a single optional dependency for Windows compatibility.
The library offers three main APIs: IPRoute for low-level synchronous netlink access (link/address/route manipulation), AsyncIPRoute for asyncio-based operations, and NDB for high-level transactional network state management with commit/rollback semantics. It handles network namespace management, virtual interface creation, firewall rules, traffic control, and hardware monitoring through a unified Python interface.
Use it for:
- Automate Linux network configuration (interfaces, routes, addresses) in infrastructure or container orchestration tools.
- Implement network namespace isolation and virtual network topology setup for containerization or testing.
- Build firewall rule management or packet filtering applications using netfilter and nftables APIs.
- Monitor and react to network state changes via netlink event subscriptions.
- Manage VPN or wireless network configuration programmatically through wireguard and nl80211 APIs.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Pyroute2 is a pure Python networking framework that provides direct access to Linux netlink protocols for configuring network interfaces, routes, firewall rules, and other system networking resources.
Yes, if you need programmatic Linux network configuration on Python 3.9+. The library is actively maintained, has no known vulnerabilities, and low install friction. However, verify the dual GPL/Apache license terms for your use case first, and confirm that the unclear license treatment does not conflict with your project's licensing requirements. Not suitable for non-Linux platforms.
Install
pyroute2 on PyPI
pip
pip install pyroute2uv
uv add pyroute2poetry
poetry add pyroute2Installing pyroute2
Before you install
Low install friction; distributed as a pure Python wheel with only one runtime dependency (win_inet_pton). Actively maintained with recent commits and no known vulnerabilities.
License in practice
Dual-licensed under GPL-2.0-or-later OR Apache-2.0, but license treatment is marked unclear. Verify which license terms apply to your use case before integrating into proprietary or commercial projects.
Quickstart
pip install pyroute2
from pyroute2 import IPRoute
ipr = IPRoute()
for link in ipr.get_links():
print(link)
ipr.close()
Requires Linux; emulates limited RTNL API on BSD but is not supported on other platforms. Requires Python >= 3.9.
Verify before relying
- Exact scope of BSD emulation support and which RTNL operations are available on non-Linux systems.
- Performance characteristics and scalability limits when handling large numbers of netlink messages or network state changes.
Package facts
| License | GPL-2.0-or-later OR Apache-2.0 (unclear) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — win_inet_pton |
| Maintenance | actively maintained — 121 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,390,171/month — #3,966 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pyroute2-0.9.6-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
PyRICPyRIC provides programmatic control over Linux…
copyleft · top 15,000 on PyPI
netaddrRepresents and manipulates IPv4, IPv6, MAC…
permissive · top 5,000 on PyPI
netifacesProvides portable access to network interface…
permissive · top 5,000 on PyPI
pyobjc-framework-MultipeerConnectivityProvides Python bindings to macOS's…
permissive · top 15,000 on PyPI
icmplibicmplib provides a pure Python implementation…
copyleft · top 5,000 on PyPI
ipaddrProvides utilities for parsing, validating, and…
permissive · top 15,000 on PyPI
pyobjc-framework-NetworkProvides Python bindings to Apple's Network…
permissive · top 15,000 on PyPI
python3-dtlsAdds DTLS (Datagram Transport Layer Security)…
permissive · top 15,000 on PyPI
pyRFXtrxA Python library that communicates with RFXtrx…
copyleft · top 15,000 on PyPI
netifaces-plusRetrieves network interface information…
permissive · top 15,000 on PyPI