Here is an example that creates a server and list them:
from hcloud import Client
from hcloud.images import Image
from hcloud.server_types import ServerType
client = Client(
token="{YOUR_API_TOKEN}", # Please paste your API token here
application_name="my-app",
application_version="v1.0.0",
)
# Create a server named my-server
response = client.servers.create(
name="my-server",
server_type=ServerType(name="cx23"),
image=Image(name="ubuntu-22.04"),
)
server = response.server
print(f"{server.id=} {server.name=} {server.status=}")
print(f"root password: {response.root_password}")
# List your servers
servers = client.servers.get_all()
for server in servers:
print(f"{server.id=} {server.name=} {server.status=}")
Experimental features are published as part of our regular releases (e.g. a product
public beta). During an experimental phase, breaking changes on those features may occur
within minor releases.
The stability of experimental features is not related to the stability of its upstream API.
Experimental features have different levels of maturity (e.g. experimental, alpha, beta)
based on the maturity of the upstream API.
While experimental features will be announced in the release notes, you can also find
whether a python class or function is experimental in its docstring:
Experimental:
$PRODUCT is $MATURITY, breaking changes may occur within minor releases.
See https://docs.hetzner.cloud/changelog#$SLUG for more details.
Development
First, create a virtual environment and activate it:
make venv
source venv/bin/activate
You may setup pre-commit to run before you commit changes, this removes the need to run it manually afterwards:
pre-commit install
You can then run different tasks defined in the Makefile, below are the most important ones:
Build the documentation and open it in your browser:
make docs
Lint the code:
make lint
Run tests using the current python3 version:
make test
You may also run the tests for multiple python3 versions using tox:
tox .
Deprecations implementation
When deprecating a module or a function, you must:
Update the docstring with a deprecated notice:
"""Get image by name
.. deprecated:: 1.19
Use :func:`hcloud.images.client.ImagesClient.get_by_name_and_architecture` instead.
"""
Raise a warning when the deprecated module or function is being used:
warnings.warn(
"The 'hcloud.images.client.ImagesClient.get_by_name' method is deprecated, please use the "
"'hcloud.images.client.ImagesClient.get_by_name_and_architecture' method instead.",
DeprecationWarning,
stacklevel=2,
)
Releasing experimental features
To publish experimental features as part of regular releases:
an announcement, including a link to a changelog entry, must be added to the release notes.
an Experimental notice, including a link to a changelog entry, must be added to the python classes and functions that are experimental:
"""
Experimental:
$PRODUCT is $MATURITY, breaking changes may occur within minor releases.
See https://docs.hetzner.cloud/changelog#$SLUG for more details.
"""
License
The MIT License (MIT). Please see License File for more information.
Works well with
Use together with hcloud: extensions, drivers, servers and companion tools.
pulumi-hcloudPythie’s Index: 85A Pulumi package for creating and managing hcloud cloud resources.67.7K downloads/mo