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.
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.pyThe easiest way to get the library is through pypi:
$ pip install tailscaleIf you want to use the module from within this repo, you'll need to build it. The best way to do
that is with maturin:
# In the project where you want to use the tailscale bindings:
$ python -m virtualenv .venv
$ . .venv/bin/activate
$ pip install maturin
# Then in tailscale-rs:
$ cd ~/tailscale-rs/ts_python # use your path to a local clone of tailscale-rs
$ maturin develop # build and install python bindings into your virtualenv
$ python -c 'import tailscale' && echo "ready!" # bindings are available!