Skip to main content

purehosting-sdk (Python)

Official Python SDK for the PureHosting API — servers, Telegram accounts, balance, webhooks and WebSocket events. Standard library only, no pip dependencies.

Install

pip install purehosting-sdk

If PyPI is unreachable, install the same wheel straight from our own domain:

pip install https://docs.purehosting.top/sdk/purehosting_sdk-1.0.1-py3-none-any.whl

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

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

purehosting_sdk-3.0.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

purehosting_sdk-3.0.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file purehosting_sdk-3.0.0.tar.gz.

File metadata

  • Download URL: purehosting_sdk-3.0.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for purehosting_sdk-3.0.0.tar.gz
Algorithm Hash digest
SHA256 cf8d77fab05f0dcade7a438140576dfe04468a55504e6c08f9fcd1533fee94a7
MD5 8890763169fee69f1a36bf8bfcb7fa79
BLAKE2b-256 599df72ae0d889bc7eea44cc32c916fb271231544288fe2f7ceae47e4380894e

See more details on using hashes here.

File details

Details for the file purehosting_sdk-3.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for purehosting_sdk-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7d466f9cd5c90b2bdb62d56ebbe438c02fc71071d51eaa5255160e0c36316e5
MD5 9689437ed47867d93e1680ecc725fb06
BLAKE2b-256 3462f7ea9c7c35fae25427ac9bff1745c7fb8c0d53e02c9166facf9a8ea173fc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page