diff --git a/examples/create_server.py b/examples/create_server.py index 348939a2..d85c1d9d 100644 --- a/examples/create_server.py +++ b/examples/create_server.py @@ -1,11 +1,18 @@ from __future__ import annotations +from os import environ + from hcloud import Client from hcloud.images import Image from hcloud.server_types import ServerType -# Please paste your API token here between the quotes -client = Client(token="{YOUR_API_TOKEN}") +assert ( + "HCLOUD_TOKEN" in environ +), "Please export your API token in the HCLOUD_TOKEN environment variable" +token = environ["HCLOUD_TOKEN"] + +client = Client(token=token) + response = client.servers.create( name="my-server", server_type=ServerType("cx11"), diff --git a/examples/list_servers.py b/examples/list_servers.py index 005e9b6c..82524301 100644 --- a/examples/list_servers.py +++ b/examples/list_servers.py @@ -1,9 +1,14 @@ from __future__ import annotations +from os import environ + from hcloud import Client -client = Client( - token="{YOUR_API_TOKEN}" -) # Please paste your API token here between the quotes +assert ( + "HCLOUD_TOKEN" in environ +), "Please export your API token in the HCLOUD_TOKEN environment variable" +token = environ["HCLOUD_TOKEN"] + +client = Client(token=token) servers = client.servers.get_all() print(servers) diff --git a/examples/usage_oop.py b/examples/usage_oop.py index b6fcddcd..0a867cf6 100644 --- a/examples/usage_oop.py +++ b/examples/usage_oop.py @@ -1,11 +1,18 @@ from __future__ import annotations +from os import environ + from hcloud import Client from hcloud.images import Image from hcloud.server_types import ServerType +assert ( + "HCLOUD_TOKEN" in environ +), "Please export your API token in the HCLOUD_TOKEN environment variable" +token = environ["HCLOUD_TOKEN"] + # Create a client -client = Client(token="project-token") +client = Client(token=token) # Create 2 servers # Create 2 servers diff --git a/examples/usage_procedurale.py b/examples/usage_procedurale.py index 6c4aa962..8e901e60 100644 --- a/examples/usage_procedurale.py +++ b/examples/usage_procedurale.py @@ -1,12 +1,19 @@ from __future__ import annotations +from os import environ + from hcloud import Client from hcloud.images import Image from hcloud.server_types import ServerType from hcloud.servers import Server from hcloud.volumes import Volume -client = Client(token="project-token") +assert ( + "HCLOUD_TOKEN" in environ +), "Please export your API token in the HCLOUD_TOKEN environment variable" +token = environ["HCLOUD_TOKEN"] + +client = Client(token=token) # Create 2 servers response1 = client.servers.create(