skillfed

pyroute2

Python Netlink library

pyroute2 v0.9.6 1.4M downloads/30d#3,966 on PyPI1,064
License unclear GPL-2.0-or-later OR Apache-2.0 Active released

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 pyroute2

uv

uv add pyroute2

poetry

poetry add pyroute2

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersIntended Audience :: System AdministratorsIntended Audience :: Telecommunications IndustryOperating System :: POSIX :: LinuxProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries :: Python ModulesTopic :: System :: NetworkingTopic :: System :: Systems Administration

Tags

linux netlink socket programmingnetwork interface configuration pythonrouting table manipulationfirewall rule managementnetwork namespace management
netlink-socketlinux-networkinginfrastructure-automation

More Python Modules packages