Python SDK
parallelworks-client is the official Python client for the ACTIVATE platform API.
Installation
pip install parallelworks-clientQuick Start
For CI or another unattended job, supply an API key through PW_API_KEY. The SDK extracts its platform host. For work you run yourself, including long-running scripts, use your saved CLI sign-in instead:
import os
from parallelworks_client import Client
with Client.from_credential(os.environ["PW_API_KEY"]).sync() as client:
response = client.get("/api/buckets")
for bucket in response.json():
print(f"Bucket: {bucket['name']}")Authentication
Signed in with pw auth
For scripts you run yourself, sign in with pw auth, then create the client from CLI credential config. The SDK automatically obtains OAuth access tokens, authenticates requests, and renews tokens through the CLI while your sign-in remains valid. Your code does not need to manage tokens or refresh logic. The SDK runs pw auth token --print -o json when it needs a token, so keep the CLI installed and on your PATH.
from parallelworks_client import Client
with Client.from_credential_config().sync() as client:
response = client.get("/api/buckets")The client uses the same context as the CLI: PW_API_KEY if set, then the context argument, PW_CONTEXT, and the current context. The cli_command argument sets the path to pw. If pw can't renew the sign-in, requests raise SignInExpiredError; run pw auth again.
To select a context named research, use Client.from_credential_config(context="research"). Without an explicit context, the client uses PW_CONTEXT or the saved default. A nonempty PW_API_KEY overrides even the explicitly named context, so unset it to use your saved sign-in.
For long-running work, reuse this client instead of passing a copied access token to a raw-credential constructor. PW_CREDENTIALS_DIR selects a separate $PW_CREDENTIALS_DIR/.credentials file for both the SDK and its CLI subprocess. Set it before creating the client and keep the directory writable. See long-running clients and separate credentials.
For CI and persistent unattended services, use an API key in PW_API_KEY and follow the key rotation steps.
Automatic Host Detection
These raw-credential constructors infer the host, but do not renew the credential you pass. Use the credential-config constructor above for a renewable sign-in.
An API key (pwt_...) contains your platform host, so from_credential connects to it with no URL. An access token from pw auth token --print doesn't name a host: the client uses PW_PLATFORM_HOST if set, otherwise the server of the selected CLI context.
# API key: host decoded from the key
client = Client.from_credential("pwt_Y2xvdWQucGFyYWxsZWwud29ya3M.xxxxx")
# Connects to: https://cloud.parallel.works
# Access token from `pw auth token --print`: host from PW_PLATFORM_HOST,
# else the server of the selected context
client = Client.from_credential(token)Explicit Host
If you prefer to specify the host explicitly:
# API key (Basic Auth) - for CI and other unattended automation
client = Client.with_api_key(
"https://cloud.parallel.works",
"pwt_..."
)
# Access token (Bearer), sent as is and never renewed
client = Client.with_token(
"https://cloud.parallel.works",
token
)
# Auto-detect credential type
client = Client.with_credential(
"https://cloud.parallel.works",
os.environ["PW_CREDENTIAL"]
)Credential Helpers
from parallelworks_client import is_api_key, is_token, extract_platform_host
is_api_key("pwt_abc.xyz") # True
is_token("eyJ.abc.def") # True
extract_platform_host("pwt_...") # "cloud.parallel.works"Async Support
The client supports async/await natively:
import asyncio
import os
from parallelworks_client import Client
async def main():
async with Client.from_credential(os.environ["PW_API_KEY"]) as client:
response = await client.get("/api/buckets")
print(response.json())
asyncio.run(main())Related Documentation
- SDKs Overview — Authentication basics and other languages
- API Reference — Browse every endpoint, with schemas and examples
- Creating API Keys — Generate a credential for the SDK