ByteRun Python SDK
Run Python code and AI agents on managed cloud infrastructure from your Python application.
The official Python SDK for ByteRun. ByteRun provides remote execution environments for Python, SQL and AI agents, so you can build your workloads instead of provisioning and managing the infrastructure they run on. See the platform overview.
Early preview. Version
0.0.8is 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.
Quickstart
You need a ByteRun account and Python 3.10 or newer. Running code and starting projects
needs an active trial or plan: once a free trial has ended, exec() and start() raise
PlanLimitExceededError.
1. Install
pip install byterun
python -c "import byterun; print(byterun.__version__)"
2. Log in. This opens your browser; approve the request and a key is saved on this machine.
byterun login
byterun status # shows the key, its permissions and your remaining compute hours
3. Run code. Save as hello.py and run python hello.py:
from byterun import ByteRun
with ByteRun() as client:
project = client.project() # the key's default project
result = project.exec('print("Hello from ByteRun!"); print(6 * 7)')
print(result.stdout, end="") # Hello from ByteRun! / 42
project.stop() # a running project uses compute hours
exec() starts the project if it is stopped and waits until it is ready. A Python exception comes back
as a result, not a raised error: check result.ok and result.error.
Leaving the with block only closes connections; it never stops the project, so call project.stop() yourself.
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.
Authentication
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.
Each feature needs a permission on the key:
| Feature | Permission | In a byterun login key |
|---|---|---|
exec, exec_file |
exec |
yes |
start, stop, status |
project:lifecycle |
yes |
| SQL | sql |
yes |
upload, download |
files |
yes (log in again with byterun login --force if you logged in before) |
| Creating projects, choosing compute | project:create |
no: create a key in Settings |
Running code
from byterun import ByteRun
with ByteRun() as client:
project = client.project()
project.exec("x = 6 * 7; print(x)")
print(project.exec("print(x + 1)").stdout, end="") # 43: state is kept until the project stops
result = project.exec("1 / 0")
print(result.ok, result.status) # False FAILED: a Python exception is a result
print(result.error.name, result.error.message) # ZeroDivisionError division by zero
project.stop()
exec()starts the project if it is stopped and waits until it is ready (auto_start=Falseto refuse instead). A Python exception or a timeout comes back as a result: checkresult.ok,result.statusandresult.error. Problems with the request itself raiseByteRunError.exec_file("script.py")runs one local file's text asexec(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()andproject.status()manage the project.stop()is never done for you: a running project uses your plan's compute hours.
Reliability
- 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 carryexecution_id. If the run finished but its result is no longer stored, you getExecutionExpiredError. - Ctrl-C asks ByteRun to cancel the run, then raises
KeyboardInterruptas usual with a note saying whether the run may still be going.cancel_on_interrupt=Falseleaves the run alone.
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)
flavoris the machine size ("small","medium","gpu_starter") andtemplatethe software image. Both are optional and need a project name; leave them out for the default Python project onsmall. 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
mediummachines need a paid plan (PlanLimitExceededError,reason="gpu_not_allowed"or"flavor_not_allowed"). Creating needs the key'sproject:createpermission, whichbyterun loginkeys 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
Needs the files permission. A byterun login key has it; if you logged in before it was added, run
byterun login --force. Files do not need the project to be running.
from byterun import ByteRun
with ByteRun() as client:
project = client.project()
project.upload("data/note.txt", b"hello", overwrite=True) # pass bytes, or a pathlib.Path to stream from disk
project.exec("open('out.txt', 'w').write(open('data/note.txt').read().upper())")
print(project.download("out.txt")) # b'HELLO': the bytes
project.download("out.txt", "out.txt", overwrite=True) # or write a local file
- 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 aConflictErroron upload and aFileExistsErrorfor 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 (
PlanLimitExceededErrorwhen storage is full). They are checked on uploads; files your code writes in the project are not capped by them.
SQL
Connections are set up in ByteRun. List yours first, then use one of those names in place of warehouse below:
from byterun import ByteRun
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 == Falseanderror. A query is never repeated; if no answer comes back,ServiceErrorsays it may have run. - Values are text. SQL
NULLisNone, 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
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-browseronly prints the link, for SSH and headless machines: open it on any device.--forcelogs 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-onlyonly deletes the local file; the key stays valid until revoked.- Exit codes:
0success,1failure (denied, expired, network),2usage error,130Ctrl+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.
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.
Links
- Website: https://byterun.io/
- Platform: https://byterun.io/platform
- Roadmap: https://byterun.io/roadmap
- PyPI: https://pypi.org/project/byterun/
- Source: https://github.com/byterunio/byterun-python
Naming
| Where | Name |
|---|---|
| PyPI package | byterun |
| Python import | byterun |
| GitHub repository | byterun-python |
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.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| byterun-0.0.8.tar.gz | 56.6 kB | With provenance | Details for byterun-0.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| byterun-0.0.8-py3-none-any.whl | Python 3 | none | any | Details for byterun-0.0.8-py3-none-any.whl |
Total release size: 98.9 kB
Release files / byterun-0.0.8.tar.gz
| Download URL | byterun-0.0.8.tar.gz |
|---|---|
| Size | 56.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
606d21a86bf326fe47c4e3144de2a67810d79f6ecb48303460e7792912cfa909
|
|
BLAKE2b-256 checksum How to use checksums |
bb71fbb07f9c011165c994f1ffea74761dabf1b1251024b65e47d9a3c47af0e6
|
| 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 logRelease files / byterun-0.0.8-py3-none-any.whl
| Download URL | byterun-0.0.8-py3-none-any.whl |
|---|---|
| Size | 42.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a0b198b907c15de5159f133488ea433697d7d7a31892d5779fc10664e63c26f2
|
|
BLAKE2b-256 checksum How to use checksums |
1b9885467fdf8d4a71212a01ec607c934aa4aa6548311c4f1d59af7e222899c0
|
| 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 logSecurity for byterun 0.0.8
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.
Attestation for byterun-0.0.8.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 logA 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.