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.7.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.7.0
File Actions
tailscale_py-0.7.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for tailscale_py-0.7.0-cp312-abi3-win_amd64.whl
tailscale_py-0.7.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.12 abi3 Linux glibc 2.17+ x86-64 Details for tailscale_py-0.7.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
tailscale_py-0.7.0-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.12 abi3 Linux glibc 2.17+ ARM64 Details for tailscale_py-0.7.0-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
tailscale_py-0.7.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for tailscale_py-0.7.0-cp312-abi3-macosx_11_0_arm64.whl

Total release size: 19.0 MB

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

Download URL tailscale_py-0.7.0-cp312-abi3-win_amd64.whl
Size 4.8 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
aa0d45ab6451a769e7178e7240a4202567872b17ad874049f2408c021f99aaf4
BLAKE2b-256 checksum
How to use checksums
a94e252d5411d46d92720ad71a102f7727f70051e3acfc14a7c626558f0820ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","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.7.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL tailscale_py-0.7.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_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
4a2294f8b7d7dbe0d7afadacb454482af697651759d963ea5f6a61e4697637bc
BLAKE2b-256 checksum
How to use checksums
1dfbfc1a51032f87d1cc0fa057d2f4e81ec92e7b30564ffbf5754246e061bcc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","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.7.0-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL tailscale_py-0.7.0-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 4.7 MB
Tags CPython 3.12 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
296046f454919b94a96fcfae0e104adf3a3870ed26d8e2517300e39a6f047713
BLAKE2b-256 checksum
How to use checksums
46c8e29b92f8951cf979edc91556e601cc4f4818805aefe3266bfc95998e9c90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","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.7.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL tailscale_py-0.7.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
936f7a278f7232b836efa0f1dbcc6b6b2b7a89f796c9017e4644b20337842086
BLAKE2b-256 checksum
How to use checksums
d596065dc035ebd49b04abee9659af16ebf626e035feadc8eecc1c0ff8e86893
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for tailscale-py 0.7.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