Client for the ZCHPC platform: GPUs, managed databases, caches and media buckets.
Project description
zchpc
The Python client for ZCHPC: rent GPU slices, and provision managed databases, caches and S3-compatible media buckets.
pip install zchpc
Nothing is required to talk to the API itself. The drivers are pulled in only when you actually connect to a resource, so a bucket user never installs a Postgres driver:
pip install "zchpc[postgres]" # psycopg
pip install "zchpc[cache]" # redis
pip install "zchpc[buckets]" # boto3
pip install "zchpc[gpu]" # paramiko
pip install "zchpc[all]" # all of them
Rent a GPU
with destroys the rental on the way out, including when the code in the
middle raises. A GPU bills by the second, and the usual way a box gets left
running is an exception between renting it and destroying it.
from zchpc import ZCHPC
z = ZCHPC("gpv_YOUR_API_KEY") # or set ZCHPC_API_KEY
with z.gpus.rent(gpu_mem_gb=8, hours=1).wait() as gpu:
print(gpu.gpu_info()) # Tesla V100S-PCIE-32GB, 32768 MiB, 0 MiB
print(gpu.run("nvidia-smi"))
hours is prepaid, so ask for what you need: the API default of 24 is a full
day of rent.
Databases
db = z.databases.first_running("postgres") or z.databases.create().wait()
db.sql("CREATE TABLE IF NOT EXISTS notes (id serial PRIMARY KEY, body text)")
db.executemany("INSERT INTO notes (body) VALUES (%s)", [("first",), ("second",)])
print(db.sql("SELECT id, body FROM notes ORDER BY id"))
print(db.tables())
print(db.uri) # the raw connection string
The client is a convenience, not a wall. db.uri is a standard connection
string and db.connect() is a real driver connection, so you can drop to plain
SQL whenever the wrapper is in the way.
Cache
cache = z.cache.first_running() or z.cache.create().wait()
cache.set("session:42", "abc", ttl=60)
print(cache.ttl("session:42")) # 60 (-1 = no expiry, -2 = no key)
cache.incr("hits") # atomic, safe across processes
cache.flush_prefix("session:") # scoped delete, never FLUSHALL
Buckets
bucket = z.buckets.first() or z.buckets.create("media")
bucket.put("photos/cat.jpg", open("cat.jpg", "rb").read(),
content_type="image/jpeg")
print(bucket.presign("photos/cat.jpg", expires=300)) # expiring share link
print(bucket.presign_put("uploads/from-browser.png")) # browser-direct upload
Path-style addressing is set for you. Amazon puts the bucket in the hostname and every SDK defaults to that, but this endpoint serves buckets as a path, so doing it by hand is the usual first thing to go wrong.
Errors
Typed by what you can do about them: AuthError, InsufficientCredit,
LimitReached, NotFoundError, ProvisioningError, WaitTimeout,
MissingDependency.
License
MIT
Project details
Release history Release notifications | RSS feed
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 zchpc-0.1.0.tar.gz.
File metadata
- Download URL: zchpc-0.1.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8c8d66489662ad75f116c1748228c418c9603bc3c74588df6c9448d6491d55d
|
|
| MD5 |
cfa838c8b4a075b9892d96635cf9b576
|
|
| BLAKE2b-256 |
48084e8928b40677df0e7db19bed4b6bd6ad7c3bbfab1df12e2470426a764dbb
|
File details
Details for the file zchpc-0.1.0-py3-none-any.whl.
File metadata
- Download URL: zchpc-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68a83529369fcb1a95fc29245c6620210b425df487eb5bae4d15adc0413d2530
|
|
| MD5 |
67e3ca8e59b1562d3cdd1faabfc90f57
|
|
| BLAKE2b-256 |
3c1a8d45a76836629df8a747625a5e0b11ad6cc1f2fa84ab8983762b5fde32dd
|