Skip to main content

pytap3 - Cross-platform tunnel interface for Python

This is a cross-platform fork of the original johnthagen/pytap2. It provides a packet-oriented interface to TUN devices on Linux, macOS, and Windows.

Requirements

Requirements depend on your operating system:

  • Linux: Install net-tools to provide the ifconfig command.

    On Debian/Ubuntu:

    $ sudo apt install net-tools

    On RHEL/Rocky Linux/Fedora:

    $ sudo yum install net-tools
  • macOS: No additional packages are required; ifconfig is included with macOS.

  • Windows: wintun.dll is required. When building/installing from source on Windows, the package downloads the signed Wintun 0.14.1 archive from Wintun, verifies its SHA-256 checksum, and bundles the DLL matching the Python platform. This requires network access during installation. Wheels are platform-tagged; build Windows wheels on Windows to include the DLL. Source distributions build locally on any supported OS.

Creating and configuring a TUN device may require administrator or root privileges.

Installation

You can install, upgrade, and uninstall pytap3 with these commands:

$ pip install pytap3
$ pip install --upgrade pytap3
$ pip uninstall pytap3

Usage

Using as a context manager automatically brings up the device and closes it at the end of the with block.

from pytap3 import TapDevice

with TapDevice() as device:
    device.ifconfig(mtu=1300)
    device.write(b'0000')

Or manually call up() and close().

from pytap3 import TapDevice

device = TapDevice()
device.up()
device.ifconfig(mtu=1300)
device.write(b'0000')
device.close()

The fileno() method is defined, so that the device object can be passed directly to select(). This might not work on Windows, as the underlying Wintun driver does not support this.

On macOS, configuring an IP address with ifconfig(ip=..., netmask=...) also adds a route for that subnet through the utun interface. Routes that conflict with an existing route may require administrator privileges or manual adjustment.

You can make pytap3 a drop-in replacement for pytap2 by just importing it like this:

import pytap3 as pytap2

Releases

3.0.0 - 2024-06-05

  • Windows, Linux and macOS support!

Metadata

Release files for pytap3 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytap3 3.0.0
File Size Uploaded Provenance Actions
pytap3-3.0.0.tar.gz 13.4 kB Without provenance Details for pytap3-3.0.0.tar.gz

Release files / pytap3-3.0.0.tar.gz

Download URL pytap3-3.0.0.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ae86bf160affe7391611b8d73203d24fdf1f1e2884e8ef473c3f7e23f5ce5ba6
BLAKE2b-256 checksum
How to use checksums
db70f360254c7e39844e83dbcbde7aace48d05a89cf2d508b863c76fe6be52ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.9

Security for pytap3 3.0.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page