A previous release had provenance metadata, but this release does not. View details.
PyHetznerServer
A modern, type-safe Python library for Hetzner Cloud Server management with comprehensive API coverage.
🚀 Features
- Complete Server Lifecycle Management - Create, manage, and delete cloud servers
- All Server Actions - Power management, backups, rescue mode, ISO handling, and more
- Type Safety - Full type hints throughout the codebase
- Dry-Run Mode - Test your code without making real API calls
- Comprehensive Error Handling - Detailed exception hierarchy
- Automatic Model Parsing - JSON responses automatically converted to Python objects
- Rate Limiting Aware - Built-in handling of API rate limits
- Modern Python - Supports Python 3.8+
📦 Installation
pip install pyhetznerserver
🔑 Authentication
First, create an API token in the Hetzner Cloud Console:
- Go to your project
- Navigate to Security → API Tokens
- Generate a new token with appropriate permissions
🛠️ Quick Start
from pyhetznerserver import HetznerClient
# Initialize client
client = HetznerClient(token="your_api_token_here")
# List all servers
servers = client.servers.list()
print(f"Found {len(servers)} servers")
# Create a new server
server, action = client.servers.create(
name="my-web-server",
server_type="cx11",
image="ubuntu-20.04",
location="fsn1",
ssh_keys=["your-ssh-key-name"],
labels={"env": "production", "app": "web"}
)
print(f"Server created: {server.name} ({server.public_net.ipv4.ip})")
# Server management
server.power_off() # Power off server
server.power_on() # Power on server
server.reboot() # Reboot server
server.reset() # Hard reset
# Advanced operations
server.enable_backup("22-02") # Enable daily backups
server.create_image("my-snapshot") # Create server image
server.enable_rescue() # Enable rescue mode
server.attach_iso("ubuntu-20.04") # Mount ISO
server.change_type("cx21", upgrade_disk=True) # Upgrade server
# Cleanup
client.close()
📋 Server Operations
Power Management
server.power_on() # Start server
server.power_off() # Stop server
server.reboot() # Restart server
server.reset() # Force restart
server.shutdown() # Graceful shutdown
Backup & Recovery
server.enable_backup("22-02") # Enable backups at 22:00-02:00 UTC
server.disable_backup() # Disable backups
server.create_image("snapshot-name") # Create snapshot
server.rebuild("ubuntu-22.04") # Rebuild from image
Rescue & Maintenance
password, action = server.enable_rescue("linux64", ssh_keys=["key1"])
server.disable_rescue()
server.attach_iso("ubuntu-20.04")
server.detach_iso()
Network Management
server.attach_to_network(network_id, ip="10.0.0.100")
server.detach_from_network(network_id)
server.change_dns_ptr("1.2.3.4", "server.example.com")
Security
password, action = server.reset_password()
server.change_protection(delete=True, rebuild=False)
🔍 Server Information
Access comprehensive server information through nested objects:
server = client.servers.get(server_id)
# Basic info
print(f"Server: {server.name} (ID: {server.id})")
print(f"Status: {server.status}")
print(f"Created: {server.created}")
# Network information
print(f"IPv4: {server.public_net.ipv4.ip}")
print(f"IPv6: {server.public_net.ipv6.ip}")
# Hardware details
print(f"Type: {server.server_type.name}")
print(f"CPU Cores: {server.server_type.cores}")
print(f"RAM: {server.server_type.memory} GB")
print(f"Disk: {server.server_type.disk} GB")
# Location
print(f"Datacenter: {server.datacenter.name}")
print(f"Location: {server.datacenter.location.city}, {server.datacenter.location.country}")
# Operating System
print(f"OS: {server.image.name} ({server.image.os_flavor})")
🧪 Testing & Development
Enable dry-run mode for testing without making real API calls:
client = HetznerClient(token="fake_token", dry_run=True)
# All operations return mock data
servers = client.servers.list() # Returns empty list
server, action = client.servers.create(name="test", server_type="cx11", image="ubuntu-20.04")
print(f"Mock server created: {server.name}") # Uses fake data
🚨 Error Handling
The library provides detailed exception hierarchy:
from pyhetznerserver import (
HetznerAPIError,
AuthenticationError,
ValidationError,
ServerNotFoundError,
RateLimitError
)
try:
server = client.servers.get(999999)
except ServerNotFoundError:
print("Server not found")
except AuthenticationError:
print("Invalid API token")
except RateLimitError:
print("API rate limit exceeded")
except ValidationError as e:
print(f"Invalid input: {e}")
except HetznerAPIError as e:
print(f"API error: {e}")
📊 Filtering & Pagination
# Filter servers
servers = client.servers.list(
status="running",
label_selector="env=production",
sort="name:asc"
)
# Pagination
servers = client.servers.list(page=2, per_page=10)
🏷️ Labels & Metadata
# Create server with labels
server, action = client.servers.create(
name="web-server",
server_type="cx11",
image="ubuntu-20.04",
labels={
"environment": "production",
"team": "backend",
"cost-center": "engineering"
}
)
# Filter by labels
prod_servers = client.servers.list(label_selector="environment=production")
🔧 Advanced Configuration
client = HetznerClient(
token="your_token",
dry_run=False, # Enable for testing
timeout=30 # Request timeout in seconds
)
📚 API Coverage
This library covers all Hetzner Cloud Server API endpoints:
- ✅ Server Management - CRUD operations
- ✅ Power Actions - Start, stop, reboot, reset
- ✅ Image Management - Create snapshots, rebuild
- ✅ Backup System - Enable/disable, scheduling
- ✅ Rescue Mode - Recovery operations
- ✅ ISO Handling - Mount/unmount ISO images
- ✅ Network Operations - Attach/detach networks
- ✅ DNS Management - PTR record management
- ✅ Security - Password reset, protection settings
- ✅ Server Types - Hardware configuration changes
- ✅ Actions - Retrieve operation status and history
🤝 Contributing
Contributions are welcome! Please read our Contributing Guide for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Hetzner Cloud for providing excellent cloud infrastructure
- The Python community for amazing tools and libraries
📞 Support
- 📖 Documentation: GitHub Repository
- 🐛 Bug Reports: GitHub Issues
- 💬 Discussions: GitHub Discussions
🔗 Related Projects
- hcloud-python - Official Hetzner Cloud Python library
- terraform-provider-hcloud - Terraform provider
Made with ❤️ for the Python and Hetzner Cloud community
Metadata
Release files for pyhetznerserver 1.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Loss of provenance
These files do not have provenance metadata, despite files in a prior release including this data.
We recommend further investigation before installing these files. View details.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyhetznerserver-1.2.4.tar.gz | 24.3 kB | Without provenance | Details for pyhetznerserver-1.2.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyhetznerserver-1.2.4-py3-none-any.whl | Python 3 | none | any | Details for pyhetznerserver-1.2.4-py3-none-any.whl |
Total release size: 40.4 kB
Release files / pyhetznerserver-1.2.4.tar.gz
Loss of provenance
This file belongs to a release without provenance metadata, despite a prior release including this data.
We recommend further investigation before installing this file. View details.
| Download URL | pyhetznerserver-1.2.4.tar.gz |
|---|---|
| Size | 24.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ebe510fcdcabb14395fe32a924637b20a8f0327a10521c222cd9b2a1c18d72ea
|
|
BLAKE2b-256 checksum How to use checksums |
9f1d26e6faa693045412ee7131b1ed1d1ee8b6248a2910fefd2761e7c711ffad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.1
|
Release files / pyhetznerserver-1.2.4-py3-none-any.whl
Loss of provenance
This file belongs to a release without provenance metadata, despite a prior release including this data.
We recommend further investigation before installing this file. View details.
| Download URL | pyhetznerserver-1.2.4-py3-none-any.whl |
|---|---|
| Size | 16.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5bc1bf277362ad7073b56ac9f2e52f4d134e3e1abbb796eb8606b7d270ae985a
|
|
BLAKE2b-256 checksum How to use checksums |
7729226fc28d3fccee101d309850f4ad42df15a24835d91bfb56a3865447e9ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.1
|
Security for pyhetznerserver 1.2.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Loss of provenance
A previous release of these files had provenance metadata, but this release does not.
While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.
Release comparison
- Removed 1.2.1 2 files With provenance
- Added 1.2.4 2 files Without provenance
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.