Hetzner Cloud Python Library

2.17.1 · active · verified Thu Apr 16

The `hcloud` library is the official Python client for interacting with the Hetzner Cloud API, enabling programmatic management of resources such as servers, networks, volumes, and more. It is actively maintained with frequent releases, currently at version 2.17.1, providing access to the latest Hetzner Cloud features and API updates.

Common errors

Warnings

Install

Imports

Quickstart

Initializes the Hetzner Cloud client using an API token from the `HCLOUD_TOKEN` environment variable and lists all available servers. This demonstrates basic client setup and interaction with resources.

import os
from hcloud import Client

HCLOUD_TOKEN = os.environ.get('HCLOUD_TOKEN', '')

if not HCLOUD_TOKEN:
    print("Error: HCLOUD_TOKEN environment variable not set.")
    exit(1)

client = Client(token=HCLOUD_TOKEN, application_name="my-app", application_version="1.0.0")

# Example: List all servers
try:
    servers = client.servers.get_all()
    if servers:
        print("Hetzner Cloud Servers:")
        for server in servers:
            print(f"  - ID: {server.id}, Name: {server.name}, Status: {server.status}")
    else:
        print("No servers found.")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →