purehosting-sdk (Python)
Official Python SDK for the PureHosting API — servers, domains, Telegram accounts, balance, webhooks and WebSocket events. Standard library only, no pip dependencies.
Install
Not yet on PyPI — install straight from the repository:
pip install "git+https://github.com/permach-dev/vds.git#subdirectory=sdk/purehosting-python"
Or copy the purehosting/ package into your project — it has no dependencies to drag along.
Quick start
from purehosting import PureHosting
client = PureHosting(api_key="phk_...") # Profile → API access in the bot
servers = client.servers.list()["items"]
print(servers)
Servers
client.servers.list()
client.servers.get(42)
client.servers.catalog()
client.servers.buy({"tariff_id": "DE-3", "months": 1, "os_family": "ubuntu", "os_version": "24.04"})
client.servers.power(42, "restart") # 'start' | 'stop' | 'restart'
client.servers.reinstall(42, {"os_family": "ubuntu", "os_version": "24.04"})
client.servers.reset_password(42)
client.servers.os_options(42)
client.servers.cancel(42) # only while not yet issued
client.servers.extend(42, 3) # 3 months
Domains
client.domains.list()
client.domains.get(7)
client.domains.check("example")
client.domains.buy({"name": "example", "tld": "com"})
client.domains.cancel(7)
client.domains.dns.list(7)
client.domains.dns.add(7, {"type": "A", "name": "@", "value": "1.2.3.4", "ttl": 3600})
client.domains.dns.delete(7, 15)
Telegram accounts
client.accounts.list()
client.accounts.catalog()
acc = client.accounts.buy("US") # ISO 3166-1 alpha-2
client.accounts.request_code(acc["id"]) # AFTER signing in with that number
client.accounts.mark_used(acc["id"])
bulk = client.accounts.bulk.buy("US", 10)
client.accounts.bulk.get(bulk["id"]) # poll until status != 'pending'
archive_bytes = client.accounts.bulk.download(bulk["id"])
with open("accounts.zip", "wb") as f:
f.write(archive_bytes)
Balance
balance = client.balance.get()["balance_usd"]
tx = client.balance.transactions(limit=50)
Webhooks
cfg = client.webhook.set("https://example.com/hooks/purehosting")
print(cfg["secret"]) # save this — it signs every incoming request
# In your webhook handler:
ok = PureHosting.verify_webhook_signature(
stored_secret,
raw_body, # the RAW request body string/bytes, not json.loads()'d
request.headers.get("X-PureHosting-Signature"),
)
if not ok:
return "", 401
Delivery: 5 attempts (1 initial + 4 retries) with a 1 → 2 → 4 → 8 minute pause between them.
WebSocket
stream = client.connect_websocket()
stream.on("open", lambda _: print("connected"))
stream.on("event", lambda msg: print("any event:", msg))
stream.on("server.expiring", lambda data: print("expiring:", data["order_id"]))
stream.start(background=True) # runs the receive loop in a daemon thread
# ... your app keeps running ...
stream.close()
Reconnects automatically with a growing pause (1s → 2s → … → 60s). Implements the RFC 6455 handshake and framing directly over socket/ssl — no websockets/websocket-client dependency.
Errors
from purehosting import PureHosting, PureHostingError
try:
client.servers.buy({...})
except PureHostingError as e:
print(e.status, e.body.get("error"), e.body.get("detail"))
Full docs
docs.purehosting.top — every endpoint, schemas, webhook event formats.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file purehosting_sdk-1.0.0.tar.gz.
File metadata
- Download URL: purehosting_sdk-1.0.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c55cb4d5b3af9a68fa558be50c99056ca88ab43100c5d076b942ef838470d14e
|
|
| MD5 |
8a22befdd5086eed1bfcfb8e418b49ae
|
|
| BLAKE2b-256 |
4a06649e63f242e6535c9979923b53c7649f8f857480d010509565f6c9eae666
|
File details
Details for the file purehosting_sdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: purehosting_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13f0e65620b5eab15191da9d5825ed4492c80c7a60294fe2eb75ea74687d3458
|
|
| MD5 |
5ac6f1a33d64fabd7f4fcad11e2041e0
|
|
| BLAKE2b-256 |
b92a4de860bef85e76a9f76ab9eafde53a4ef29d8aaaf30ab5898740e9736aa0
|