Pure-python asyncio rtnetlink client.
Install from PyPI:
pip install aiortnetlink
Or, adding to your uv project:
uv add aiortnetlink
Example:
from aiortnetlink import NetlinkClient
async with NetlinkClient() as nl:
async for link in nl.get_links():
print(f"{link.index}: {link.name}")
The module ships with a CLI, for example if running from the repository root:
uv run aiortnetlink addr show
get_links
: List all links.get_link
: Lookup link by index or name.
get_links
: List all addresses.add_addr
: Add IP address to link.del_addr
: Remove IP address from link.
get_routes
: List all routes.get_route
: Get route for the given address.
get_rules
: List all rules.
recv_notification
: Receive netlink notification. Notification subscription is done by passing the revelant rtnetlink groups to the netlink client.
create_tuntap
: Create tun or tap device.delete_tuntap
: Delete tun or tap device.
All network operations can be performed in a network namesapce by passing the netns_name
argument to the NetlinkClient
.
This project uses uv for project management and poe the poet to run development tasks. Linting and code formatting is done using ruff, type checking using mypy and tests using pytest.
For example to run all checks locally:
uvx --from poethepoet poe lint
To format code using ruff:
uvx --from poethepoet poe fmt
Linux user API constants are exposed to C programs as symbols. In order to extract their values for use in a pure-Python module without violating the license we need to write a C program that will import the appropriate linux uapi headers and print their values.
To facilitate development of this library we generate a C program and use its output to generate python source code representing the various constants. The constants are grouped into types using IntEnum.
This is handled by the constants generator. The files in the constants directory and generated in this way and should not be edited manually.