Python client for the Contree API, generated from the OpenAPI specification
Project description
contree-client
Python client for the Contree API — sandboxed code execution combining virtual machine isolation with container operational efficiency.
Synchronous clients are named ContreeClient, asynchronous ones are
named ContreeAsyncClient; every backend shares the same interface:
| Backend | Extra | Import |
|---|---|---|
| http.client | — (stdlib) | from contree_client.http import ContreeClient |
| urllib3 | contree-client[urllib3] |
from contree_client.urllib3 import ContreeClient |
| requests | contree-client[requests] |
from contree_client.requests import ContreeClient |
| httpx | contree-client[httpx] |
from contree_client.httpx import ContreeClient / ContreeAsyncClient |
| aiohttp | contree-client[aiohttp] |
from contree_client.aiohttp import ContreeAsyncClient |
Or let the package pick the first installed backend:
from contree_client.sync import ContreeClient
from contree_client.asyncio import ContreeAsyncClient
Quick start
from contree_client.sync import ContreeClient
# reuse a saved Contree profile,
# or pass credentials directly: ContreeClient("IAM_TOKEN", project=...)
with ContreeClient.from_profile() as client:
response = client.spawn_instance("uname -a", "tag:ubuntu:latest", shell=True)
for event in client.iter_operation_events(response.uuid, follow=True):
print(event.type, event.data)
Use cases
Run a command and read its output:
from contree_client import OperationStatus
response = client.spawn_instance(
"echo hello",
"tag:ubuntu:latest",
shell=True,
disposable=True, # do not persist a result image
timeout=60,
)
operation = client.wait_operation(response.uuid)
assert operation.status is OperationStatus.SUCCESS
print(operation.metadata.result.stdout.as_text())
Follow the live event stream with transparent reconnection
(Last-Event-Id resume; ends on the completion event):
import sys
from contree_client import decode_chunk
for event in client.follow_operation_events(response.uuid):
if event.type in ("stdout", "stderr"):
sys.stdout.buffer.write(decode_chunk(event.data))
Retry transient failures (network errors, 410/425/5xx) automatically:
from contree_client import RetryPolicy
client = ContreeClient.from_profile(retry=RetryPolicy())
Stage files into the sandbox:
from contree_client import FileSpec
uploaded = client.upload_file(open("data.txt", "rb"))
client.spawn_instance(
"wc -l /work/data.txt",
"tag:ubuntu:latest",
shell=True,
files={"/work/data.txt": FileSpec(uuid=uploaded.uuid, mode="0644")},
)
Import an image and inspect it without spawning anything:
from contree_client import ImageImportRegistry
operation_id = client.import_image(
ImageImportRegistry(url="docker://docker.io/library/busybox:latest"),
tag="busybox:latest",
)
image_uuid = client.inspect_find_image_by_tag("busybox:latest")
print(client.inspect_image_list(image_uuid, "/etc").files)
Download a directory as a tar stream:
with open("etc.tar", "wb") as archive:
for chunk in client.inspect_image_archive(image_uuid, "/etc"):
archive.write(chunk)
Asynchronous flavour mirrors the sync API exactly:
from contree_client.asyncio import ContreeAsyncClient
async with ContreeAsyncClient.from_profile() as client:
me = await client.whoami()
print(me.permissions)
Test your code without a server — the in-memory double from
contree_client.testing implements the same interface as every real
backend; unmocked methods raise, calls are recorded:
from contree_client.testing import ContreeClient
client = ContreeClient()
client.mock("spawn_instance", spawn_response)
client.mock("iter_operation_events", [stdout_event, exit_event])
run_my_code(client)
assert client.calls_for("spawn_instance")
Debug logging (redacted, off by default):
import logging
from contree_client.types import set_log_level
set_log_level(logging.DEBUG)
Copyright
Nebius B.V. 2026, Licensed under the Apache License, Version 2.0 (see "LICENSE" file).
Project details
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 contree_client-0.1.3.tar.gz.
File metadata
- Download URL: contree_client-0.1.3.tar.gz
- Upload date:
- Size: 130.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5dd328cc400803311a7bdfcdd98db3e4035febc94303bfc141b5f1c7cb782d2
|
|
| MD5 |
70a851f85946dd365c1d8c1a49f0f495
|
|
| BLAKE2b-256 |
8f23c8ac6db7872eda1ede7b6ae76c5445faefae2a34d9a35e2b1544e8233930
|
Provenance
The following attestation bundles were made for contree_client-0.1.3.tar.gz:
Publisher:
publish.yml on nebius/contree-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
contree_client-0.1.3.tar.gz -
Subject digest:
c5dd328cc400803311a7bdfcdd98db3e4035febc94303bfc141b5f1c7cb782d2 - Sigstore transparency entry: 2189706715
- Sigstore integration time:
-
Permalink:
nebius/contree-client@46e48342fd34358fedbe214a528bf6f8b5bde258 -
Branch / Tag:
refs/tags/0.1.3 - Owner: https://github.com/nebius
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@46e48342fd34358fedbe214a528bf6f8b5bde258 -
Trigger Event:
release
-
Statement type:
File details
Details for the file contree_client-0.1.3-py3-none-any.whl.
File metadata
- Download URL: contree_client-0.1.3-py3-none-any.whl
- Upload date:
- Size: 96.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2bc43b10f5eaee7c489d07425d00dac89f30ecf22509a2401272a0c20970534
|
|
| MD5 |
8280c37447d600cc5a5efa74603a590b
|
|
| BLAKE2b-256 |
8036e28aa3e5172a5eb9a166fcc8c9e85a1c00415d834fdee43bc2a51d0a7cfe
|
Provenance
The following attestation bundles were made for contree_client-0.1.3-py3-none-any.whl:
Publisher:
publish.yml on nebius/contree-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
contree_client-0.1.3-py3-none-any.whl -
Subject digest:
a2bc43b10f5eaee7c489d07425d00dac89f30ecf22509a2401272a0c20970534 - Sigstore transparency entry: 2189706744
- Sigstore integration time:
-
Permalink:
nebius/contree-client@46e48342fd34358fedbe214a528bf6f8b5bde258 -
Branch / Tag:
refs/tags/0.1.3 - Owner: https://github.com/nebius
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@46e48342fd34358fedbe214a528bf6f8b5bde258 -
Trigger Event:
release
-
Statement type: