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
# connect to the tailnet:
= await
# bind a udp socket on this node's ipv4 address:
= await
= await
# send a message to a peer once per second
await
await
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
- 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:
# Create a virtual environment for ts_python development.
# Activate the new virtual environment.
# Install runtime and dev dependencies (for generating type stubs, testing, etc.).
()
Formatting
We use ruff (via uv's preview feature) to format Python code:
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.
)
# The stubs are not properly formatted.
Currently, you need to manually check the generated type stubs and add any missing imports by hand.