Skip to main content

ts_python

Python bindings for tailscale-rs.

At the moment, this exposes facilities for connecting to a tailnet and binding network sockets that have access to the tailnet.

Code Sample

#!/usr/bin/env python3

import asyncio
import tailscale

async def main():
    # connect to the tailnet:
    dev = await tailscale.connect('tsrs_keys.json', "tskey-auth-$MY_AUTH_KEY")

    # bind a udp socket on this node's ipv4 address:
    tailnet_ipv4 = await dev.ipv4_addr()
    udp_sock = await dev.udp_bind((tailnet_ipv4, 1234))
    print(f'udp bound, local endpoint: {udp_sock.local_addr()}')

    # send a message to a peer once per second
    while True:
        await udp_sock.sendto(('1.2.3.4', 5678), msg=b"HELLO")
        print("sent message to peer")
        await asyncio.sleep(1)


if __name__ == "__main__":
    asyncio.run(main())

To run this demo:

$ python demo.py

Building and Usage

The easiest way to get the library is through PyPI:

$ pip install tailscale-py

Developing

This package uses uv. All other tooling (maturin, ruff, etc.) is managed by uv.

Setup

  1. Install an appropriate Rust toolchain for your platform. See here for supported toolchain versions.
  2. Install uv.
  3. Clone the tailscale-rs repository.
  4. Create, activate, and populate a virtual environment for ts_python development:
# At the root of your tailscale-rs checkout:
~/tailscale-rs $ cd ts_python

# Create a virtual environment for ts_python development.
~/tailscale-rs/ts_python $ uv venv
...
Activate with: source .venv/bin/activate

# Activate the new virtual environment.
~/tailscale-rs/ts_python $ source .venv/bin/activate

# Install runtime and dev dependencies (for generating type stubs, testing, etc.).
(ts_python) ~/tailscale-rs/ts_python $ uv sync --dev
...

Formatting

We use ruff (via uv's preview feature) to format Python code:

~/tailscale-rs/ts_python $ uv format
...
4 files reformatted

Generating Type Stubs

The type stubs in ts_python/python/tailscale/_internal.pyi need to be generated any time the Rust source code (in ts_python/src/) changes. To re-generate the stubs:

# Make sure ts_python is built/up-to-date and maturin is installed.
~/tailscale-rs/ts_python $ uv sync --dev
...
~/tailscale-rs/ts_python $ maturin generate-stubs --out python/tailscale
🍹 Building a mixed python/rust project
...
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.09s

# The stubs are not properly formatted.
~/tailscale-rs/ts_python $ uv format

Currently, you need to manually check the generated type stubs and add any missing imports by hand.

Metadata

Release files for tailscale-py 0.6.0

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

Built distributions (wheels)

Table of built distributions (wheels) for tailscale-py 0.6.0
File
tailscale_py-0.6.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details
tailscale_py-0.6.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 abi3 Linux glibc 2.17+ x86-64 Details
tailscale_py-0.6.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.12 abi3 Linux glibc 2.17+ ARM64 Details
tailscale_py-0.6.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details

Total release size: 18.9 MB

Release files / tailscale_py-0.6.0-cp312-abi3-win_amd64.whl

Download URL tailscale_py-0.6.0-cp312-abi3-win_amd64.whl
Size 4.7 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
6949d9de2ab391e22972fe80b28aae009659ff69e4dac826f61694bd06a485c6
BLAKE2b-256 checksum
How to use checksums
bfe9865002265b8825bfa38c30bbeb9dd2ec6efd7cb4707863166c09ef803aa4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / tailscale_py-0.6.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL tailscale_py-0.6.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 4.9 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
112806c1aba7658670c4f8d6f95440be7aed78de7c0bebcd72257cbbf9bb0f27
BLAKE2b-256 checksum
How to use checksums
6c9b555cbdeea7530cc9c7f43ef2d9693e2eab21a0ec9882174a7275f26b2086
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / tailscale_py-0.6.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL tailscale_py-0.6.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 4.7 MB
Tags CPython 3.12 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
96f96cc27ce9c51a8247fcc6ce7e3e4197d9233d33615d51aff472b701ac1542
BLAKE2b-256 checksum
How to use checksums
11773242a0d1deff1c3474d327463ca3cd81a6499a0448c65bcf00580698d466
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / tailscale_py-0.6.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL tailscale_py-0.6.0-cp312-abi3-macosx_11_0_arm64.whl
Size 4.6 MB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
486b5794063aa03a4ec5b40965dacbe824c3f5096b2428dbba0eb34267f6a8cf
BLAKE2b-256 checksum
How to use checksums
f3f729e2eccc1d3f61f9282cf6ba2679e1ae465420235a575dc6b8d05beed77d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.6.1

4 release files

This release

0.6.0 This release

4 release files

0.5.0

4 release files

0.4.0

4 release files

0.3.3

4 release files

0.3.1

4 release files

0.2.0

1 release file

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