Embed OpenCode in your Python application.
Project description
opencode-runtime
Embed OpenCode in your Python application.
OpenCode is a great CLI coding agent. But to embed it in a product, SaaS backend, or multi-user automation system, you need more than a CLI process.
opencode-runtime turns OpenCode into a managed application runtime for Python. It uses OpenCode as the agent harness and adds what you need to run it as part of an application: lifecycle management, per-user workspaces, reusable sessions, health checks, streaming output, and multi-server orchestration.
Install
pip install opencode-runtime
npm install -g opencode-ai # opencode must be on PATH
Use
Your first session
from opencode_runtime import OpenCodeRuntime
async with OpenCodeRuntime() as r:
session = await r.session()
response = await session.ask("Explain this repo")
print(response.text)
One server per user, automatically
Every (workspace, user_id) pair gets its own isolated server, workspace, and conversation history — started on first use, reused after:
async with OpenCodeRuntime(runtime_dir=".opencode-runtime") as r:
s1 = await r.session(workspace="org_a", user_id="u_1")
s2 = await r.session(workspace="org_b", user_id="u_2")
Stream every token as it arrives
async for event in session.stream("Review this PR"):
if event.type == "message.part.delta" and event.text:
print(event.text, end="", flush=True)
Inspect
Servers started from Python are visible and manageable from the terminal:
opencode-runtime ps
ID PID PORT STATUS UPTIME WORKSPACE USER PROJECT
───────────────────────────────────────────────────────────────────────────────────
39dce5beb4debfaa 12051 58409 ● running 5m org_a u_1 ~/Developer/myproject
81fa29acb3e9210f 12088 58411 ● running 3m org_b u_2 ~/Developer/myproject
opencode-runtime health 39dce5beb4debfaa
opencode-runtime inspect 39dce5beb4debfaa
opencode-runtime stop-all
Guides
- OpenCode config — models, permissions, agents, skills
- Sessions — continuation, resume across restarts
- Users & workspaces — multi-tenant isolation
- Streaming — event types, tool calls, permissions, cost
- CLI — manage your fleet from the terminal
- HTTP client — direct server access
Requirements
- Python 3.10+
opencode1.0+ on PATH
Contributing
See CONTRIBUTING.md.
License
Apache 2.0
Project details
Release history Release notifications | RSS feed
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 opencode_runtime-0.5.0.tar.gz.
File metadata
- Download URL: opencode_runtime-0.5.0.tar.gz
- Upload date:
- Size: 43.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
708f63a7bf425c6a1e13fd4d3012c747ce4e6571b31c7f711fa831d7b5881882
|
|
| MD5 |
4153f5ad96d6ccd55924bdf271da7c38
|
|
| BLAKE2b-256 |
210bb3f2690c57b534d64e26b097c4dea9b442c7bbfa925e5b049873f8321287
|
Provenance
The following attestation bundles were made for opencode_runtime-0.5.0.tar.gz:
Publisher:
publish.yml on ashish16052/opencode-runtime
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opencode_runtime-0.5.0.tar.gz -
Subject digest:
708f63a7bf425c6a1e13fd4d3012c747ce4e6571b31c7f711fa831d7b5881882 - Sigstore transparency entry: 2138828429
- Sigstore integration time:
-
Permalink:
ashish16052/opencode-runtime@67d17e9f3b13ebe492a718e4c86ba7bfd82056a9 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/ashish16052
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@67d17e9f3b13ebe492a718e4c86ba7bfd82056a9 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file opencode_runtime-0.5.0-py3-none-any.whl.
File metadata
- Download URL: opencode_runtime-0.5.0-py3-none-any.whl
- Upload date:
- Size: 29.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9bea5165f3f4f7f843e0ceccf2372df6bb2f522699a36e4527bbabe5061eb85
|
|
| MD5 |
01548e555e3271f2be462a3ffcf73f3a
|
|
| BLAKE2b-256 |
9cdd1aa319ee2ef6c57aa0607ce67073bf8466f5fb1fe8a5a92e4824924e4c28
|
Provenance
The following attestation bundles were made for opencode_runtime-0.5.0-py3-none-any.whl:
Publisher:
publish.yml on ashish16052/opencode-runtime
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opencode_runtime-0.5.0-py3-none-any.whl -
Subject digest:
a9bea5165f3f4f7f843e0ceccf2372df6bb2f522699a36e4527bbabe5061eb85 - Sigstore transparency entry: 2138828434
- Sigstore integration time:
-
Permalink:
ashish16052/opencode-runtime@67d17e9f3b13ebe492a718e4c86ba7bfd82056a9 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/ashish16052
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@67d17e9f3b13ebe492a718e4c86ba7bfd82056a9 -
Trigger Event:
workflow_dispatch
-
Statement type: