3tsapi is a lightweight wrapper for calling the Tailscale API with
4a local instance of the Tailscale control plane. It's to save me
5remembering the exact set of curl commands I need.
12from typing import TypedDict
14from chives.text import coloured
28 parser = argparse.ArgumentParser(
30 description="Make API calls to a local instance of devcontrol",
33 parser.add_argument("--endpoint", help="API endpoint", required=True)
34 parser.add_argument("--api-key", help="API key", required=True)
35 parser.add_argument("--data", help="Body to POST with the request")
37 args = parser.parse_args()
39 method, path = args.endpoint.split()
44 "api_key": args.api_key,
49if __name__ == "__main__":
53 f"http://localhost:31544/api/v2{args['path']}",
58 f"Authorization: Bearer {args['api_key']}",
61 cmd.extend(["--data", args["data"]])
63 print(coloured("-> " + " ".join(shlex.quote(c) for c in cmd), "blue"))
64 output = subprocess.check_output(cmd)
65 print(json.dumps(json.loads(output), indent=2))