Skip to main content

Setup

uv pip install "${NULLSPACE_SDK_INSTALL_SPEC:-nullspace-sdk==0.1.9}"
export NULLSPACE_API_KEY=ns_live_...
export NULLSPACE_API_URL=https://api.your-nullspace-domain

Python

from nullspace import FileUploadError, Sandbox

def on_progress(event) -> None:
    print(event.phase, event.bytes_completed, event.bytes_total, event.transport)

with Sandbox.create(template="base", timeout=300) as sandbox:
    try:
        result = sandbox.files.upload_file(
            "./dist/model.bin",
            "/workspace/model.bin",
            resumable=True,
            progress=on_progress,
        )
    except FileUploadError as exc:
        if exc.upload_id is None:
            raise
        result = sandbox.files.resume_upload(
            exc.upload_id,
            "./dist/model.bin",
            progress=on_progress,
        )

    print(result.target_path, result.bytes_uploaded)

Directory upload

result = sandbox.files.upload_dir(
    "./src",
    "/workspace/src",
    ignore_patterns=["*.pyc"],
)
print(result.file_count, result.target_path)
Guide: Uploads.