Python Wrapper for wireguard-tools

Andrew Roth andrew at andrewjroth.com
Fri Aug 21 16:04:58 CEST 2020


Hello,

Recently joined the list, but reviewed the archives as best I could.
I figured before I get too far in writing this, I should ask here.

I'm looking for a way to create and configure WireGaurd interfaces
programmatically using Python.  Has anyone created a Python wrapper
for the wireguard-tools?  If not, could I try my hand at it?

In my research, I was not able to find any true libraries supporting
configuring a WireGuard implementation.  Since wireguard-tools [1] is
cross-platform, and Python is cross-platform, I wanted a
cross-platform library to configure WireGuard interfaces.  This would
help application programmers or tool developers who want to utilize
WireGuard as part of the application or tool written in Python,
potentially cross-platform.

I did see wgnlpy [2], but don't think it is a fit since it relies on
Netlink (Linux kernel interface), so it's not cross-platform.  I also
found a few other packages on Pypi, but none of them seemed to
interface with the WireGuard module interfaces.

In the wireguard-tools repository, I noticed the embeddable-wg-library
[3] with C source and header.  Python (using CFFI) supports creating
an extension module that is compiled from C sources to directly invoke
the target C function [4].  It claims to be fast, simple, and
platform-agnostic (by that, I mean it can be compiled for any
platform).  I am planning on writing a python module to expose the C
functions from the embeddable-wg-library using CFFI.

Does this make sense?  Any comments, gotchas, or limitations?

Thanks for your time,
Andrew

[1]:  https://git.zx2c4.com/wireguard-tools/about/
[2]:  https://github.com/ArgosyLabs/wgnlpy
[3]:  https://git.zx2c4.com/wireguard-tools/tree/contrib/embeddable-wg-library
[4]:  https://cffi.readthedocs.io/en/latest/overview.html#api-mode-calling-c-sources-instead-of-a-compiled-library

--

~Andrew Roth
http://www.andrewjroth.com

"Our greatest glory is not in never falling, but in getting up every
time we do." -Confucius


More information about the WireGuard mailing list