Skip to main content

Work-in-progress Tailscale library written in Rust.

Project description

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.

Project details


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.4.0-cp312-abi3-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.12+Windows x86-64

tailscale_py-0.4.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.7 MB view details)

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

tailscale_py-0.4.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.4 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

tailscale_py-0.4.0-cp312-abi3-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: tailscale_py-0.4.0-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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.4.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 eeaa8af55be7291239c9ef0053aa7db7d24a92bb3b7d33795273441495f42579
MD5 2dfb8434d25e7b7cb3c2ba1dc69afa03
BLAKE2b-256 c46dc65d8ebbd0326f262929e3181072e8f03a34d21a738f65878d0b74c14624

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tailscale_py-0.4.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 4.7 MB
  • Tags: CPython 3.12+, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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.4.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b41c849a5e671eac589323b224b98d1fb5d54ecdd1c6f28bcbb11ce6e9dce7fc
MD5 3418c6e7cd23b1ef6adee0319efefe17
BLAKE2b-256 d090f117fb35d6469ed13f0ee125b904747ae779673c8bae54c4f79f838665a4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tailscale_py-0.4.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.12+, manylinux: glibc 2.17+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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.4.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 73eb468795c9320bdc7b3b29b5e72270cb67acd9bc05524dae9a6f80b5e334b3
MD5 b9b3da436c21585977fd7b88ecac19a7
BLAKE2b-256 6728a771de1b02b3e871ec520b9992f170437609f77bdec25b1cf4fdf3bb6b39

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tailscale_py-0.4.0-cp312-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 4.1 MB
  • Tags: CPython 3.12+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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.4.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a8a696ed66d638d9ffec197d5a1148a38755e6d68243e6037f0f990ee8230f2b
MD5 04d2fa531137f1e6ac095231ff5e261a
BLAKE2b-256 b7374b9fa8e9af428a4ec39456a51abf322243e778dfb858d9d752ec5a2246b7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page