Skip to main content

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

pip install purehosting-sdk

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

purehosting_sdk-1.0.1.tar.gz (6.1 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-1.0.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for purehosting_sdk-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d9ea3d9a38eb8f4c7a814fcfcf37483af5733d442f9059da39c6586b743c37af
MD5 88ca297834507ae6ed8408c8f1b5c055
BLAKE2b-256 76cf2a07154e6b7fb008062b75e15d7ea848661b86ee72fd4636255db51e55d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for purehosting_sdk-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aabdf90fb74e944d43a4420f4b19c2f2d2a32993d00ea350339c3d5ffe7ecc2b
MD5 b0e650dd081ba8f3ccd5032cda96e670
BLAKE2b-256 2bdd25f5f37347ac7f2f93b5dd279b4ce490c08d9e296c6494121c5844ba3dfd

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