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
- Install an appropriate Rust toolchain for your platform. See here for supported toolchain versions.
- Install
uv. - Clone the
tailscale-rsrepository. - Create, activate, and populate a virtual environment for
ts_pythondevelopment:
# 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.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| tailscale_py-0.6.1-cp312-abi3-win_amd64.whl | CPython 3.12 | abi3 | Windows x86-64 | Details |
| tailscale_py-0.6.1-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.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.12 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| tailscale_py-0.6.1-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.1-cp312-abi3-win_amd64.whl
| Download URL | tailscale_py-0.6.1-cp312-abi3-win_amd64.whl |
|---|---|
| Size | 4.7 MB |
| Tags | CPython 3.12 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
2caed7c015043908ca0077617f3710a9876a2aafddee6c10919a80a5c88bd1c7
|
|
BLAKE2b-256 checksum How to use checksums |
f2258be49a0d9e505777d0e338352f53b59c5938e9d70bfdae4762cde318a50a
|
| 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.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | tailscale_py-0.6.1-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 |
04ad71bcb4cfd5fff5c0275945d5a647b2c359d99ca9552f36a0e02229befaf8
|
|
BLAKE2b-256 checksum How to use checksums |
9f6b8e4831d3c384db2a053035bc248a8dd74083430bfa193ecee817f5449f79
|
| 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.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | tailscale_py-0.6.1-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 |
35ce06bad9bdce3bf786c341d06b02a70d07794bd39c73d05b319334e282a4ef
|
|
BLAKE2b-256 checksum How to use checksums |
e33d2000e2e6c551996626e691511ca4146feaa62ef339047a44ca959a92bd91
|
| 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.1-cp312-abi3-macosx_11_0_arm64.whl
| Download URL | tailscale_py-0.6.1-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 |
d17a4d2b64b420e9ca1bb542e0fd14dc3e742fabe4b7060ca40505faa8b66201
|
|
BLAKE2b-256 checksum How to use checksums |
f937757a1cdcff6ea4f8c21652154659ec6b4e627efbd8355e3ff3ddbfb63bf7
|
| 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}
|