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:

$ TS_RS_EXPERIMENT=this_is_unstable_software 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tailscale_py-0.5.0-cp312-abi3-win_amd64.whl (5.2 MB view details)

Uploaded CPython 3.12+Windows x86-64

tailscale_py-0.5.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ x86-64

tailscale_py-0.5.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

tailscale_py-0.5.0-cp312-abi3-macosx_11_0_arm64.whl (4.7 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

File details

Details for the file tailscale_py-0.5.0-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: tailscale_py-0.5.0-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 5.2 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","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}

File hashes

Hashes for tailscale_py-0.5.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fca931f9be740000ba6543b672d9d094b318cbd0e7d5246aceb13950e7a86eec
MD5 b5d1dd68b8be23e99cf9aebf94df1d20
BLAKE2b-256 a322f0595ecab919289c62b2b9aaf1508a657404358c7275acd942ba3b455f16

See more details on using hashes here.

File details

Details for the file tailscale_py-0.5.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: tailscale_py-0.5.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 5.3 MB
  • Tags: CPython 3.12+, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","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}

File hashes

Hashes for tailscale_py-0.5.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f9181dfd8be0d5dc3ae0ad288dc9d01a799b9cd73eddfe63a9c90fd12699c62b
MD5 36c491df9f1e7f57ed0710f2afece9c3
BLAKE2b-256 222bae28eeb5e26100f5fc2ad190a4a98a497de89508538b8a746abd631ae175

See more details on using hashes here.

File details

Details for the file tailscale_py-0.5.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

  • Download URL: tailscale_py-0.5.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
  • Upload date:
  • Size: 5.0 MB
  • Tags: CPython 3.12+, manylinux: glibc 2.17+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","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}

File hashes

Hashes for tailscale_py-0.5.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7b53b11cbc5f89d076fd62b6d9cbecdbcc563bbec61dbc7d91df6b0b44c12cfa
MD5 decd280bfbc9badcc619706cab8a6db8
BLAKE2b-256 0a92cd76348917117f765e5f7454e76673f52fa38bfd048286e63caa7ff67299

See more details on using hashes here.

File details

Details for the file tailscale_py-0.5.0-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: tailscale_py-0.5.0-cp312-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 4.7 MB
  • Tags: CPython 3.12+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","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}

File hashes

Hashes for tailscale_py-0.5.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e4f33264321d1101726bf4b6a30ffe6920f23bc2af93f841f359e80573603d17
MD5 6bf61eabc82ffdc95e2ec5507d99a527
BLAKE2b-256 6e814d2318190045022ab5abeb12a75a70f0a47bb1472899cb1ea12a45955497

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.5.0 This release

4 files

0.4.0

4 files

0.3.3

4 files

0.3.1

4 files

0.2.0

1 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