Skip to content

Zerotierlib DOCS v.1.4

Riemaru Karurosu edited this page May 12, 2026 · 4 revisions

Wiki: zerotierlib (v2.0.2)

Documentation for the internal library of ZT Manager. This library handles all interactions with the ZeroTier system service and the local JSON API.


Required Libraries

These dependencies are managed automatically within the Flatpak environment:

  • requests: Handles HTTP requests to the local ZeroTier API.
  • pydbus: Securely manages the zerotier-one.service status via D-Bus (systemd).
  • psutil: Used for process management and monitoring.
  • pathlib: Modern file path handling (native Python 3).
  • subprocess: Executes host commands (like pkexec) via flatpak-spawn.

Note

No requirements.txt needed: Since ZT Manager is distributed via Flatpak, all dependencies are declared in the manifest JSON.


The ZeroTierNetwork Class

The core class to interact with ZeroTier. It supports both Host Mode (automatic token retrieval) and Manual Mode (user-provided tokens).

Constants

  • COMMANDS: ('start', 'stop', 'enable', 'disable')
  • BASE_URL: http://localhost:9993/
  • PATH: ~/.config/ztlib/ (User configuration folder)
  • FILE: zt.conf (Persistence file)
  • SERVICE: zerotier-one.service

Core Methods

__init__(api_token=None)

Initializes the instance. It automatically calls read_token() to load saved settings and tokens.

is_installed() -> bool

Checks if the zerotier-one binary is present on the host system.

zt_status() -> bool

Returns True if the ZeroTier service is currently active on the host.

zt_enable_status() -> bool

Returns True if the service is enabled to start on boot.

service(setstatus: int) -> bool

Changes the system service state.

  1. start
  2. stop
  3. enable
  4. disable Uses D-Bus for safe interaction with the system bus.

read_token() -> int

Loads configuration from zt.conf.

  • 200: Success (Token loaded and validated).
  • 401: Unauthorized (Token invalid).
  • 404: Config file missing.
  • If host_mode is enabled, it automatically triggers get_token().

get_token() -> str | None

Attempts to read /var/lib/zerotier-one/authtoken.secret from the host using pkexec. Requires user authentication.

save_token()

Saves the current token and host_mode state to the config file with secure permissions (0600).


Network API Methods

get_networks(network=None) -> list | dict

Retrieves a list of all joined networks or details of a specific one.

join_networks(network_id: str)

Joins a new ZeroTier network.

leave_networks(network_id: str)

Leaves and forgets a ZeroTier network.

get_peers() -> list

Returns a list of all peers/nodes currently known by the local service.

update_network(network_id: str, config: dict)

Updates settings for a specific network.


Key Properties

  • self.host_mode: Whether the app is in "Host Mode" (auto-fetching tokens).
  • self.api_token: The current token used for X-ZT1-Auth headers.

Documentation updated on May 12, 2026, for ZT Manager v2.0.2 Stable.