wireguard_py - A cython library allowing direct access to Wireguard kernel functions from Python
For most use cases, the Wireguard CLI is all one needs to set up a working Wireguard tunnel. However, for more complex scenarios (e.g. the creation and maintenance of a
Wireguard mesh involving many thousands of peers), using a high-level language to manage all of the peer configuration and monitoring make life much easier. The wireguard_py
cython module exists to make this possible in Python without the additional overhead and fragility of having to shell out to the wireguard CLI, as well as providing type hints.
Installing
Installation is performed via pip:
pip install wireguard-py
Using wireguard_py
An quick example of setting up a wireguard connection and peering:
import ipaddress
import pyroute2
import wireguard_py
from wireguard_py.wireguard_common import Endpoint
# Create the wireguard interface
ipr = pyroute2.IPRoute()
ipr.link("add", ifname="wg0", kind="wireguard")
wg_ifc = ipr.link_lookup(ifname="wg0")[0]
ipr.addr("add", index=wg_ifc, address="172.16.0.1", prefixlen=24)
ipr.link("set", index=wg_ifc, state="up")
# Configure wireguard interface
priv_key = wireguard_py.gen_priv_key()
wireguard_py.set_device(
device_name=b"wg0",
priv_key=priv_key,
port=51820,
)
# Create a peer
wireguard_py.set_peer(
device_name=b"wg0",
pub_key=b"lM77O8LlU4PNI0ZPWsTPYS3SGubG2/YT26uh9o9LKzM=",
endpoint=Endpoint(ip=ipaddress.ip_address("172.16.0.2"), port=51820),
allowed_ips={
ipaddress.ip_network("172.16.0.2/32"),
ipaddress.ip_network("10.0.0.0/8"),
},
replace_allowed_ips=True,
)
# List peers
peers = wireguard_py.list_peers(b"wg0")
print(peers)
License
wireguard_py is licensed under the MIT License.
Metadata
Release files for wireguard-py 2023.6.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wireguard-py-2023.6.12.tar.gz | 71.0 kB | Without provenance | Details for wireguard-py-2023.6.12.tar.gz |
Release files / wireguard-py-2023.6.12.tar.gz
| Download URL | wireguard-py-2023.6.12.tar.gz |
|---|---|
| Size | 71.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6b9ed0b0b991b740da44c1deefbc94e3138b466e0213a23f511fd3fc8ccb19c9
|
|
BLAKE2b-256 checksum How to use checksums |
8bc043db3f6c5dc94073d4f37dcc1b5b410bb75263a9b3c9dd03d98cecb373a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|
Security for wireguard-py 2023.6.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.