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.
pip install --upgrade qubithub==0.2.4Creating a client
Section titled “Creating a client”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 credentialsqubithub loginstored in~/.qubithub/config.toml. There is one credential set for every host.tokensends a JWT you already have asAuthorization: Bearer ….api_key: don’t use it for the API. It is sent asX-API-Key, and no API route accepts a key yet, so every authenticated call returns401. API keys authenticate git only (Git authentication).
Both clients are context managers (with / async with); call close() / aclose() otherwise.
Methods
Section titled “Methods”AsyncQubitHubClient has every method below as a coroutine (await client.me()).
Account
Section titled “Account”| Method | Description |
|---|---|
login(email: str, password: str) -> AuthResponse | Log 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() -> bool | Log out: revoke the refresh token server-side and clear stored credentials. |
me() -> User | Get current user profile. |
Circuits
Section titled “Circuits”| Method | Description |
|---|---|
| `list_circuits(framework: str | None = None, tags: list[str] |
resolve_circuit(repo_name: str) -> CircuitDetail | Resolve circuit by repo name (e.g., ‘QubitHub/bell-state’). |
get_circuit(circuit_id: str) -> CircuitDetail | Get circuit by UUID. |
create_circuit(req: CircuitCreateRequest) -> CircuitDetail | Create a new circuit. |
update_circuit(circuit_id: str, **updates: Any) -> CircuitDetail | Update circuit metadata. |
delete_circuit(circuit_id: str) -> None | Delete a circuit. |
| `fork_circuit(circuit_id: str, name: str | None = 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: str | None = None) -> dict[str, Any]` |
| `upload_circuit_file(circuit_id: str, file_path: str | Path, commit_message: str |
| `upload_circuit_files(circuit_id: str, file_paths: list[tuple[str | Path, str]], commit_message: str |
download_file(file_path: str) -> bytes | Download a circuit file by its full path. |
| Method | Description |
|---|---|
create_run(req: RunCreateRequest) -> RunResponse | Submit a circuit execution run. |
get_run(run_id: str) -> RunResponse | Get run details. |
| `list_runs(circuit_id: str | None = None, status: str |
cancel_run(run_id: str) -> None | Cancels a pending or running run. On a finished run it deletes the run’s record instead. Returns None (204 No Content). |
get_run_stats() -> RunStatsResponse | Get current user’s run statistics. |
Spaces
Section titled “Spaces”| Method | Description |
|---|---|
execute_space(space_id: str, req: SpaceExecuteRequest) -> SpaceExecuteResponse | Execute code in a space sandbox. |
API keys
Section titled “API keys”| Method | Description |
|---|---|
create_api_key(req: APIKeyCreateRequest) -> APIKeyCreateResponse | Create a new API key (plaintext shown once). |
list_api_keys() -> APIKeyListResponse | List user’s API keys. |
get_api_key(key_id: str) -> APIKeyResponse | Get API key details. |
revoke_api_key(key_id: str) -> None | Revoke 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).
Examples
Section titled “Examples”Run a circuit and wait for the result
Section titled “Run a circuit and wait for the result”import timefrom 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.
List circuits and submit a run
Section titled “List circuits and submit a run”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)The async client
Section titled “The async client”import asynciofrom 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())An API key that expires
Section titled “An API key that expires”The CLI’s keys create sets no expiry; the SDK can:
from qubithub import QubitHubClientfrom 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).
Run code in a Space you own
Section titled “Run code in a Space you own”from qubithub import QubitHubClientfrom 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")Exceptions
Section titled “Exceptions”All errors derive from QubitHubError. HTTP errors are APIError subclasses:
| Exception | When |
|---|---|
AuthenticationError | 401: not logged in, or the token expired |
AuthorizationError | 403: logged in, but not allowed |
NotFoundError | 404 |
ConflictError | 409 |
ValidationError | 422 |
RateLimitError | 429 |
ServerError | 5xx |
NetworkError | the server could not be reached |
ConfigurationError | the client is misconfigured |
Next steps
Section titled “Next steps”- CLI reference: the same operations from the terminal.
- Authentication: tokens, refresh and API keys.
- Spaces: what runs in a Space today.
Need help? See Troubleshooting or email [email protected].