Skip to content

Python SDK Reference

The qubithub package (0.2.4) ships a synchronous QubitHubClient and an AsyncQubitHubClient with the same methods. Each example below ran once against a local QubitHub server; only the base URL and the circuit names differ (the local server had its own circuits). For the CLI, see the CLI reference.

Terminal window
pip install --upgrade qubithub==0.2.4
QubitHubClient(
base_url="https://qubithub.co/api",
api_key=None,
token=None,
timeout=30.0,
auto_login=True,
)
  • auto_login=True (the default) uses the credentials qubithub login stored in ~/.qubithub/config.toml. There is one credential set for every host.
  • token sends a JWT you already have as Authorization: Bearer ….
  • api_key: don’t use it for the API. It is sent as X-API-Key, and no API route accepts a key yet, so every authenticated call returns 401. API keys authenticate git only (Git authentication).

Both clients are context managers (with / async with); call close() / aclose() otherwise.

AsyncQubitHubClient has every method below as a coroutine (await client.me()).

MethodDescription
login(email: str, password: str) -> AuthResponseLog in, store credentials, and return AuthResponse. email takes an email address or a username (since 0.2.4; the parameter keeps its name, so login(email=...) still works).
logout() -> boolLog out: revoke the refresh token server-side and clear stored credentials.
me() -> UserGet current user profile.
MethodDescription
`list_circuits(framework: strNone = None, tags: list[str]
resolve_circuit(repo_name: str) -> CircuitDetailResolve circuit by repo name (e.g., ‘QubitHub/bell-state’).
get_circuit(circuit_id: str) -> CircuitDetailGet circuit by UUID.
create_circuit(req: CircuitCreateRequest) -> CircuitDetailCreate a new circuit.
update_circuit(circuit_id: str, **updates: Any) -> CircuitDetailUpdate circuit metadata.
delete_circuit(circuit_id: str) -> NoneDelete a circuit.
`fork_circuit(circuit_id: str, name: strNone = None) -> CircuitDetail`
star_circuit(circuit_id: str) -> dict[str, Any]Star/unstar a circuit. Returns {starred: bool, stars_count: int}.
`list_circuit_files(circuit_id: str, version: strNone = None) -> dict[str, Any]`
`upload_circuit_file(circuit_id: str, file_path: strPath, commit_message: str
`upload_circuit_files(circuit_id: str, file_paths: list[tuple[strPath, str]], commit_message: str
download_file(file_path: str) -> bytesDownload a circuit file by its full path.
MethodDescription
create_run(req: RunCreateRequest) -> RunResponseSubmit a circuit execution run.
get_run(run_id: str) -> RunResponseGet run details.
`list_runs(circuit_id: strNone = None, status: str
cancel_run(run_id: str) -> NoneCancels a pending or running run. On a finished run it deletes the run’s record instead. Returns None (204 No Content).
get_run_stats() -> RunStatsResponseGet current user’s run statistics.
MethodDescription
execute_space(space_id: str, req: SpaceExecuteRequest) -> SpaceExecuteResponseExecute code in a space sandbox.
MethodDescription
create_api_key(req: APIKeyCreateRequest) -> APIKeyCreateResponseCreate a new API key (plaintext shown once).
list_api_keys() -> APIKeyListResponseList user’s API keys.
get_api_key(key_id: str) -> APIKeyResponseGet API key details.
revoke_api_key(key_id: str) -> NoneRevoke an API key.

execute_space runs code in a Space you own (others get 403), in the server’s sandbox. It is limited to 30 runs per minute per user (429 above that). If the sandbox itself is unavailable, the result has status="error" and a generic message rather than server details.

The client’s HTTP timeout defaults to 30 seconds. A request that takes longer raises NetworkError, even if the Space run is still going. For Space runs that may take close to 30 seconds or more, create the client with a longer timeout, e.g. QubitHubClient(timeout=120).

import time
from qubithub import QubitHubClient, RunCreateRequest
with QubitHubClient(base_url="https://qubithub.co/api") as client: # reads the stored `qubithub login`
circuit = client.resolve_circuit("qubithub/bell-state")
run = client.create_run(RunCreateRequest(
circuit_id=str(circuit.id), backend_type="simulation",
backend_name="qiskit_aer", shots=1024))
deadline = time.monotonic() + 180
while run.status not in {"completed", "failed", "cancelled"}:
if time.monotonic() > deadline:
raise TimeoutError(f"run {run.id} still {run.status}")
time.sleep(2)
run = client.get_run(str(run.id))
if run.status == "completed":
print(run.status, run.results["counts"])
else: # failed or cancelled: run.results is None
print(run.status, run.error_message)

Runs are on a simulator. For a PennyLane circuit, read run.results["pennylane_result"]: counts is empty and shots is ignored.

from qubithub import QubitHubClient, RunCreateRequest
with QubitHubClient(base_url="https://qubithub.co/api") as client: # uses the credentials `qubithub login` stored
# List circuits
circuits = client.list_circuits(framework="qiskit")
for c in circuits.circuits:
print(f"{c.slug} ({c.framework}) — {c.title}")
# Execute a circuit
run = client.create_run(RunCreateRequest(
circuit_id="<circuit-uuid>", # str(resolve_circuit("owner/name").id)
backend_name="qiskit_aer",
shots=1024,
))
print(run.status, run.id)
import asyncio
from qubithub import AsyncQubitHubClient
async def main():
async with AsyncQubitHubClient(base_url="https://qubithub.co/api") as client:
a, b = await asyncio.gather(
client.resolve_circuit("qubithub/bell-state"),
client.resolve_circuit("qubithub/ghz-state"))
print(a.title, "|", b.title)
asyncio.run(main())

The CLI’s keys create sets no expiry; the SDK can:

from qubithub import QubitHubClient
from qubithub.models import APIKeyCreateRequest
with QubitHubClient(base_url="https://qubithub.co/api") as client:
key = client.create_api_key(APIKeyCreateRequest(
name="CI pipeline", scopes=["circuit:read", "circuit:write"], expires_in_days=90))
print(key.name, key.expires_at) # key.key is shown once: store it now
client.revoke_api_key(str(key.id))

Scopes are recorded on the key but not enforced today: git access follows ownership, so a personal key can clone and push every circuit you own, whatever its scopes (see Git authentication).

from qubithub import QubitHubClient
from qubithub.models import SpaceExecuteRequest
with QubitHubClient(base_url="https://qubithub.co/api") as client:
result = client.execute_space("<your-space-id>", SpaceExecuteRequest(code="print('hello from a Space')"))
print(result.status, (result.output or "").strip(), f"{result.execution_time:.2f}s")

All errors derive from QubitHubError. HTTP errors are APIError subclasses:

ExceptionWhen
AuthenticationError401: not logged in, or the token expired
AuthorizationError403: logged in, but not allowed
NotFoundError404
ConflictError409
ValidationError422
RateLimitError429
ServerError5xx
NetworkErrorthe server could not be reached
ConfigurationErrorthe client is misconfigured

Need help? See Troubleshooting or email [email protected].