API References

Main Interface

class Client(token: str, api_endpoint: str = 'https://api.hetzner.cloud/v1', application_name: str | None = None, application_version: str | None = None, poll_interval: int | float | BackoffFunction = 1.0, poll_max_retries: int = 120, timeout: float | tuple[float, float] | None = None, *, api_endpoint_hetzner: str = 'https://api.hetzner.com/v1')[source]

Client for the Hetzner Cloud API.

The Hetzner Cloud API reference is available at https://docs.hetzner.cloud.

Make sure to follow our API changelog available at https://docs.hetzner.cloud/changelog (or the RRS feed available at https://docs.hetzner.cloud/changelog/feed.rss) to be notified about additions, deprecations and removals.

Retry mechanism

The Client.request method will retry failed requests that match certain criteria. The default retry interval is defined by an exponential backoff algorithm truncated to 60s with jitter. The default maximal number of retries is 5.

The following rules define when a request can be retried:

  • When the client returned a network timeout error.

  • When the API returned an HTTP error, with the status code:

    • 502 Bad Gateway

    • 504 Gateway Timeout

  • When the API returned an application error, with the code:

    • conflict

    • rate_limit_exceeded

    • timeout

Changes to the retry policy might occur between releases, and will not be considered breaking changes.

actions

ActionsClient Instance

Type:

ActionsClient

certificates

CertificatesClient Instance

Type:

CertificatesClient

datacenters

DatacentersClient Instance

Type:

DatacentersClient

firewalls

FirewallsClient Instance

Type:

FirewallsClient

floating_ips

FloatingIPsClient Instance

Type:

FloatingIPsClient

images

ImagesClient Instance

Type:

ImagesClient

isos

ImagesClient Instance

Type:

IsosClient

load_balancer_types

LoadBalancerTypesClient Instance

Type:

LoadBalancerTypesClient

load_balancers

LoadBalancersClient Instance

Type:

LoadBalancersClient

locations

LocationsClient Instance

Type:

LocationsClient

networks

NetworksClient Instance

Type:

NetworksClient

placement_groups

PlacementGroupsClient Instance

Type:

PlacementGroupsClient

primary_ips

PrimaryIPsClient Instance

Type:

PrimaryIPsClient

request(method: str, url: str, **kwargs) dict[str, Any][source]

Perform a request to the Hetzner Cloud API.

Parameters:
  • method – Method to perform the request.

  • url – URL to perform the request.

  • timeout – Requests timeout in seconds.

server_types

ServerTypesClient Instance

Type:

ServerTypesClient

servers

ServersClient Instance

Type:

ServersClient

ssh_keys

SSHKeysClient Instance

Type:

SSHKeysClient

storage_box_types

StorageBoxTypesClient Instance

Type:

StorageBoxTypesClient

storage_boxes

StorageBoxesClient Instance

Type:

StorageBoxesClient

volumes

VolumesClient Instance

Type:

VolumesClient

zones

ZonesClient Instance

Type:

ZonesClient

API Clients

Exceptions

class HCloudException[source]

There was an error while using the hcloud library.

All exceptions in the hcloud library inherit from this exception. It may be used as catch-all exception.

class APIException(code: int | str, message: str, details: Any, *, correlation_id: str | None = None)[source]

There was an error while performing an API Request.

class ActionException(action: Action | BoundAction)[source]

A generic action exception

class ActionFailedException(action: Action | BoundAction)[source]

The pending action failed

class ActionTimeoutException(action: Action | BoundAction)[source]

The pending action timed out

Other