Skip to content

Commit

Permalink
docs: load token from env in examples scripts (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
jooola committed Sep 25, 2023
1 parent 6d46d06 commit f18c9a6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
11 changes: 9 additions & 2 deletions examples/create_server.py
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down
11 changes: 8 additions & 3 deletions examples/list_servers.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 8 additions & 1 deletion examples/usage_oop.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 8 additions & 1 deletion examples/usage_procedurale.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down

0 comments on commit f18c9a6

Please sign in to comment.