Skip to main content

ByteRun Python SDK

The official Python SDK for ByteRun, an AI infrastructure platform that provides execution environments for Python, SQL and AI agents.

Early preview. Version 0.0.x is a preview: the API may still change between releases. Try ByteRun in the playground on byterun.io, and follow the roadmap for what comes next.

What is ByteRun?

ByteRun gives developers managed environments to run code and AI agents without operating the infrastructure themselves. Today that covers Python, SQL and agent execution; the platform roadmap also includes headless jobs, workflows and inference. See the platform overview for details.

What this SDK is for

This SDK is meant to be the single Python entry point to ByteRun, so you can work with the platform from your own code, scripts and services. AI agent execution comes first; other platform capabilities will be added to the same package rather than split into separate ones.

Available today: projects (start, stop, status), running Python code in them, uploading and downloading files, SQL on your data connections, and checking what a key is. Planned, in no fixed order and subject to change: headless jobs, workflows and inference.

Installation

Requires Python 3.10 or newer.

pip install byterun

Check that it installed:

python -c "import byterun; print(byterun.__version__)"

Running code

from byterun import ByteRun

with ByteRun() as client:
    project = client.project()            # the key's default project
    result = project.exec("x = 6 * 7; print(x)")
    print(result.stdout)                  # 42
    print(project.exec("print(x + 1)").stdout)  # 43: state is kept until the project stops
    project.stop()
  • exec() starts the project if it is stopped and waits until it is ready (auto_start=False to refuse instead). A Python exception or a timeout comes back as a result: check result.ok, result.status and result.error. Problems with the request itself raise ByteRunError.
  • A run is safe to wait for. exec() submits it with a key made for that call and polls until it finishes, so a dropped connection, a rate limit or a gateway error is retried without running your code twice. Only two cases are unknown: the backend restarted mid-run (ExecutionOutcomeUnknownError, reason="lost") or nothing answered before the deadline. Both carry execution_id. If the run finished but its result is no longer stored, you get ExecutionExpiredError.
  • Ctrl-C asks ByteRun to cancel the run, then raises KeyboardInterrupt as usual with a note saying whether the run may still be going. cancel_on_interrupt=False leaves the run alone.
  • exec_file("script.py") runs one local file's text as exec(text); nothing else is uploaded.
  • client.project("name") picks a project by name, and creates it if the key may create projects.
  • project.start(), project.stop() and project.status() manage the project. stop() is never done for you: a running project uses your plan's compute hours.

ByteRun() finds a key in this order: the api_key= argument, then the BYTERUN_API_KEY environment variable, then the key byterun login saved. For CI, servers and containers, create a key in Settings, API keys on byterun.io and set BYTERUN_API_KEY.

Choosing the compute

from byterun import ByteRun

with ByteRun() as client:
    project = client.project("training", template="deeplearning-gpu", flavor="gpu_starter")
    print(project.template, project.flavor, project.template_version)
  • flavor is the machine size ("small", "medium", "gpu_starter") and template the software image. Both are optional and need a project name; leave them out for the default Python project on small. A GPU template on its own gets its GPU flavor.
  • They apply when the project is created. An existing project is never changed: asking for different compute is a ConflictError (code="PROJECT_COMPUTE_MISMATCH").
  • GPU and medium machines need a paid plan (PlanLimitExceededError, reason="gpu_not_allowed" or "flavor_not_allowed"). Creating needs the key's project:create permission, which byterun login keys do not include: create such a key in Settings.

Errors

Every exception can be imported from byterun, and they all subclass ByteRunError.

from byterun import ByteRun, ProjectStartFailedError

with ByteRun() as client:
    try:
        client.project().start()
    except ProjectStartFailedError as error:
        print(error.crash_reason, error.retryable)   # for example: gpu_capacity_unavailable True

crash_reason is one of gpu_capacity_unavailable, image_unavailable, jupyter_not_ready, too_many_starts, start_interrupted or launch_failed; new ones may appear. A failed start is not billed.

Files

from pathlib import Path
from byterun import ByteRun

with ByteRun() as client:
    project = client.project()
    project.upload("data/in.csv", Path("in.csv"))    # a Path is streamed from disk
    project.upload("data/note.txt", b"hello")        # or pass the bytes
    project.exec("open('out.txt', 'w').write(open('data/note.txt').read())")
    project.download("out.txt", "out.txt")           # write a local file
    content = project.download("out.txt")            # or get the bytes
  • Paths are relative to the project's workspace, which is where your code runs. One file per call.
  • Nothing is overwritten unless you say overwrite=True: a taken name is a ConflictError on upload and a FileExistsError for the local file on download. A download is complete or not there at all.
  • Accepted types are common data, text, image and archive formats; notebooks, pickles and executables are refused. Size and storage limits depend on your plan (PlanLimitExceededError when storage is full). They are checked on uploads; files your code writes in the project are not capped by them.
  • The key needs the files permission. byterun login includes it; if you logged in before, run byterun login --force. Files do not need the project to be running.

SQL

with ByteRun() as client:
    project = client.project()
    for connection in project.connections():
        print(connection.name, connection.type)
    print(project.schema("warehouse").tables)        # schema -> table -> columns
    result = project.sql("warehouse", "select region, count(*) from sales group by 1", limit=100)
    print(result.columns, result.rows, result.truncated)
    project.exec(f"df = byterun.load_result('{result.result_id}')")   # within about 10 minutes
  • Data connections are set up in ByteRun. The SDK sees their names and types, never hosts or credentials.
  • SQL does not need the project to be running. A query the database refuses is a result with ok == False and error. A query is never repeated; if no answer comes back, ServiceError says it may have run.
  • Values are text. SQL NULL is None, and an empty string stays "".

What is my key?

me = ByteRun().whoami()
me.require_scopes("exec", "sql")       # fail early, with the missing permission named
print(me.org_id, sorted(me.scopes), me.expires_at, me.allowance)

byterun status (or byterun whoami) prints the same, says which key is used, and warns when it is about to expire or when BYTERUN_API_KEY overrides your saved login.

Logging in from the command line

pip install byterun
byterun login     # opens your browser; approve the request, and a key is saved on this machine
byterun logout    # revokes this machine's key and deletes the saved credentials

byterun login prints a short code and a link, opens the link in your browser and waits. Check that the code on the page matches the one in your terminal before you approve, and only approve a login you started. Each machine gets its own key (limited to your starter project, 90 days), so revoking one never affects another. You can see and revoke keys in Settings on byterun.io.

  • --no-browser only prints the link, for SSH and headless machines: open it on any device.
  • --force logs in again even if this machine is already logged in. The new key is saved first, then the old one is revoked.
  • byterun logout --local-only only deletes the local file; the key stays valid until revoked.
  • Exit codes: 0 success, 1 failure (denied, expired, network), 2 usage error, 130 Ctrl+C.

The key is stored in ~/.config/byterun/credentials.json (or under $XDG_CONFIG_HOME), a 0600 file in a 0700 directory, and is never printed. The SDK talks to https://api.byterun.io; set BYTERUN_API_URL only to point at another deployment. A key is accepted on the API host only.

A key lets code run in your project's container with that project's privileges. ByteRun is not a sandbox for untrusted code: treat the key like a password.

Naming

Where Name
PyPI package byterun
Python import byterun
GitHub repository byterun-python

Feedback and contributions

Questions, ideas and bug reports are welcome as GitHub issues. The API is still being designed, so please open an issue to discuss before sending a large pull request.

License

Licensed under the Apache License, Version 2.0. Unless required by applicable law or agreed to in writing, the software is distributed on an "AS IS" basis, without warranties or conditions of any kind.

Metadata

Release files for byterun 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for byterun 0.0.7
File Size Uploaded Provenance Actions
byterun-0.0.7.tar.gz 55.9 kB With provenance Details for byterun-0.0.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for byterun 0.0.7
File Interpreter ABI Platform Actions
byterun-0.0.7-py3-none-any.whl Python 3 none any Details for byterun-0.0.7-py3-none-any.whl

Total release size: 97.8 kB

Release files / byterun-0.0.7.tar.gz

Download URL byterun-0.0.7.tar.gz
Size 55.9 kB
Tags Source
SHA-256 checksum
How to use checksums
cc947c388589347e9e02094d37394ffbedba3a2b5a214fc0159c0e6cd761e0c4
BLAKE2b-256 checksum
How to use checksums
420d0485cbeecc2acacbe16ad2207dc5dc8748b3d19f1c0cdf247f65b6b4148d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.

Transparency log

Release files / byterun-0.0.7-py3-none-any.whl

Download URL byterun-0.0.7-py3-none-any.whl
Size 41.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a0d5a688f854f64646b6c781dacb902d8a9f1a057072d167e9327fecf0fd50e5
BLAKE2b-256 checksum
How to use checksums
4ffdcc20a977f7f2ed7f97f80a7469e6a28eac806a2d1ce580fc1d390bb78a56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.

Transparency log

Security for byterun 0.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for byterun-0.0.7.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page