Python SDK for Qoder Agent
Project description
Qoder Agent SDK for Python
Python SDK for building applications on top of Qoder Agent.
The SDK starts qodercli for you, streams agent messages back to Python, and
lets your application configure tools, permissions, working directories, MCP
servers, hooks, and interactive sessions.
Installation
pip install qoder-agent-sdk
Prerequisites:
- Python 3.10+
- A Qoder account or another authentication method supported by your host application
CLI Behavior
Published platform wheels include a bundled qodercli, so a separate CLI
installation is not required for normal SDK use. If you prefer to use a
system-wide CLI or a pinned local build, pass QoderAgentOptions(cli_path=...).
Authentication
Every SDK query needs an explicit authentication option.
To reuse the local qodercli login state:
from qoder_agent_sdk import QoderAgentOptions, qodercli_auth
options = QoderAgentOptions(auth=qodercli_auth())
To authenticate with a personal access token:
Generate a Personal Access Token at qoder.com/account/integrations:
- Sign in to your Qoder account.
- Open the integrations page.
- Create a new PAT, choosing the expiry and scopes you need.
- Copy the token immediately. The value cannot be retrieved again after the page is closed.
Use separate tokens for local scripts, CI, and production services when possible, so each environment can be revoked independently. Do not hard-code tokens in source code.
from qoder_agent_sdk import QoderAgentOptions, access_token_from_env
options = QoderAgentOptions(auth=access_token_from_env())
access_token_from_env() reads QODER_PERSONAL_ACCESS_TOKEN by default.
Quick Start
import anyio
from qoder_agent_sdk import QoderAgentOptions, qodercli_auth, query
async def main() -> None:
options = QoderAgentOptions(auth=qodercli_auth())
async for message in query(
prompt="What is 2 + 2?",
options=options,
):
print(message)
anyio.run(main)
Basic Usage
query() runs a single SDK query and returns an async iterator of response
messages.
from qoder_agent_sdk import (
AssistantMessage,
QoderAgentOptions,
TextBlock,
qodercli_auth,
query,
)
options = QoderAgentOptions(
auth=qodercli_auth(),
system_prompt="You are a helpful assistant.",
max_turns=1,
)
async for message in query(prompt="Explain this repository", options=options):
if isinstance(message, AssistantMessage):
for block in message.content:
if isinstance(block, TextBlock):
print(block.text)
Tools and Permissions
Qoder Agent can use tools such as file reads, file edits, shell commands, and
MCP tools. allowed_tools is an approval allowlist: listed tools are
auto-approved, while unlisted tools continue through permission_mode and
can_use_tool for a decision. It does not remove tools from the agent's
available toolset. To block tools, use disallowed_tools.
from qoder_agent_sdk import QoderAgentOptions, qodercli_auth, query
options = QoderAgentOptions(
auth=qodercli_auth(),
allowed_tools=["Read", "Edit"],
disallowed_tools=["Bash"],
permission_mode="acceptEdits",
)
async for message in query(
prompt="Update the README introduction.",
options=options,
):
print(message)
For application-specific approval flows, provide can_use_tool:
from qoder_agent_sdk import (
PermissionResultAllow,
PermissionResultDeny,
QoderAgentOptions,
ToolPermissionContext,
qodercli_auth,
)
async def can_use_tool(
tool_name: str,
tool_input: dict,
context: ToolPermissionContext,
):
if tool_name == "Bash":
return PermissionResultDeny(message="Shell commands are disabled here.")
return PermissionResultAllow()
options = QoderAgentOptions(
auth=qodercli_auth(),
can_use_tool=can_use_tool,
)
Working Directory
Use cwd to run the agent in a specific project directory:
from pathlib import Path
from qoder_agent_sdk import QoderAgentOptions, qodercli_auth
options = QoderAgentOptions(
auth=qodercli_auth(),
cwd=Path("/path/to/project"),
)
Interactive Sessions
Use QoderSDKClient when you need a long-lived, bidirectional session instead
of a single query() call.
from qoder_agent_sdk import QoderAgentOptions, QoderSDKClient, qodercli_auth
options = QoderAgentOptions(auth=qodercli_auth())
async with QoderSDKClient(options=options) as client:
await client.query("Inspect this project and summarize the main modules.")
async for message in client.receive_response():
print(message)
QoderSDKClient is useful for chat interfaces, follow-up prompts, interrupts,
runtime permission changes, MCP server management, and other workflows that need
state across multiple turns.
Custom Tools
You can expose Python functions to Qoder Agent as in-process SDK MCP servers. This avoids managing a separate MCP subprocess for simple application-local tools.
from qoder_agent_sdk import (
QoderAgentOptions,
QoderSDKClient,
create_sdk_mcp_server,
qodercli_auth,
tool,
)
@tool("greet", "Greet a user", {"name": str})
async def greet_user(args):
return {
"content": [
{"type": "text", "text": f"Hello, {args['name']}!"}
]
}
server = create_sdk_mcp_server(
name="my-tools",
version="1.0.0",
tools=[greet_user],
)
options = QoderAgentOptions(
auth=qodercli_auth(),
mcp_servers={"tools": server},
allowed_tools=["mcp__tools__greet"],
)
async with QoderSDKClient(options=options) as client:
await client.query("Greet Alice.")
async for message in client.receive_response():
print(message)
Hooks
Hooks are deterministic Python callbacks invoked at specific points in the agent loop. They are useful for validation, policy checks, logging, and application-specific feedback.
from qoder_agent_sdk import HookMatcher, QoderAgentOptions, qodercli_auth
async def block_script(input_data, tool_use_id, context):
if input_data["tool_name"] != "Bash":
return {}
command = input_data["tool_input"].get("command", "")
if "./deploy.sh" in command:
return {
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": "deny",
"permissionDecisionReason": "Deployment scripts require review.",
}
}
return {}
options = QoderAgentOptions(
auth=qodercli_auth(),
hooks={
"PreToolUse": [
HookMatcher(matcher="Bash", hooks=[block_script]),
],
},
)
Error Handling
from qoder_agent_sdk import (
CLIConnectionError,
CLIJSONDecodeError,
CLINotFoundError,
ProcessError,
QoderAgentOptions,
QoderSDKError,
qodercli_auth,
query,
)
try:
async for message in query(
prompt="Hello Qoder",
options=QoderAgentOptions(auth=qodercli_auth()),
):
print(message)
except CLINotFoundError:
print("qodercli was not found. Install a platform wheel or set cli_path.")
except CLIConnectionError as exc:
print(f"Connection failed: {exc}")
except ProcessError as exc:
print(f"qodercli exited with code {exc.exit_code}")
except CLIJSONDecodeError as exc:
print(f"Could not parse qodercli output: {exc}")
except QoderSDKError as exc:
print(f"SDK error: {exc}")
License and Terms
Copyright (c) 2026 Qoder
Use of this software is governed by the Qoder Product Service Terms:
https://qoder.com/product-service
By installing or using this package, you agree to those terms.
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 Distributions
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 qoder_agent_sdk-1.0.1.tar.gz.
File metadata
- Download URL: qoder_agent_sdk-1.0.1.tar.gz
- Upload date:
- Size: 338.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0da07358082064dc5bd90418f860901c1060ab124e36748dfa30c3191ba9eff3
|
|
| MD5 |
5c3efdec944e1cd2617556e8e8b425f0
|
|
| BLAKE2b-256 |
106d8d8f1c080c482002df01e464532a1602eeca16eb9deea7c5f71b6249d980
|
File details
Details for the file qoder_agent_sdk-1.0.1-py3-none-win_amd64.whl.
File metadata
- Download URL: qoder_agent_sdk-1.0.1-py3-none-win_amd64.whl
- Upload date:
- Size: 68.5 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53488b925e036eab6bb408f1fa3e535de55bb00b90475595f4676e9f6df57fac
|
|
| MD5 |
339ec6dccdc9772aa4e6234719dc95a7
|
|
| BLAKE2b-256 |
133c343da7d6eca7078cc044bcd6ad0e2e85972f865c8ecc1db82267e520aed7
|
File details
Details for the file qoder_agent_sdk-1.0.1-py3-none-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: qoder_agent_sdk-1.0.1-py3-none-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 48.8 MB
- Tags: Python 3, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21987a4723b879ddf17564d1cee4bcd8b68c3c44b05ba0fb1e11006e8ee7f26e
|
|
| MD5 |
4421b2186d1d017f2082d955630fc496
|
|
| BLAKE2b-256 |
c6b35a76db96244d6ec2e3428ee35dbb6e92116264cf9b715e126c94bd1a0b1b
|
File details
Details for the file qoder_agent_sdk-1.0.1-py3-none-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: qoder_agent_sdk-1.0.1-py3-none-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 48.2 MB
- Tags: Python 3, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8eb9b4b8977a74d887233cfb3856324e4bab840f923937ddc0335c92b586616f
|
|
| MD5 |
1eaad0fb3718d7d5f1879f9b4c9d9a86
|
|
| BLAKE2b-256 |
fe90155099e10d1f0a3b2a7c62d55676bde8b7b24460dbef69297e53bdbc17cb
|
File details
Details for the file qoder_agent_sdk-1.0.1-py3-none-manylinux_2_17_x86_64.whl.
File metadata
- Download URL: qoder_agent_sdk-1.0.1-py3-none-manylinux_2_17_x86_64.whl
- Upload date:
- Size: 49.7 MB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff90b894ac2d868e00df85bb8cbe2af9b2b435436532f9528d008032b0689496
|
|
| MD5 |
a1ce9a2c7837bed2a07938002556c0ed
|
|
| BLAKE2b-256 |
b82b7fa9e2b0bfb623df089e0540986820e02ebc79077c35ca27d48e7b5dfdf7
|
File details
Details for the file qoder_agent_sdk-1.0.1-py3-none-manylinux_2_17_aarch64.whl.
File metadata
- Download URL: qoder_agent_sdk-1.0.1-py3-none-manylinux_2_17_aarch64.whl
- Upload date:
- Size: 49.5 MB
- Tags: Python 3, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87b17a85e2b7ad3d94e23544cf2dc94f0b88fd9dc55ddb14c72bafeb90fb81ca
|
|
| MD5 |
59b4a0c2603d00d6beff8ad470cd6ead
|
|
| BLAKE2b-256 |
1a24ce7f64574360aa6cb72cf1199aad4c68bd2f0ad954167018a5b09c100c9b
|
File details
Details for the file qoder_agent_sdk-1.0.1-py3-none-macosx_11_0_x86_64.whl.
File metadata
- Download URL: qoder_agent_sdk-1.0.1-py3-none-macosx_11_0_x86_64.whl
- Upload date:
- Size: 41.3 MB
- Tags: Python 3, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62d1424486f9cca8fa12b3d888b79d78a5738abab69d3c2256e4c5687e02c265
|
|
| MD5 |
9077f8c3b7f3006d8c2dd7264995fb53
|
|
| BLAKE2b-256 |
14679d90831496dd50030c1a95d61b42304b897944036538a2c6705ec660f07e
|
File details
Details for the file qoder_agent_sdk-1.0.1-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: qoder_agent_sdk-1.0.1-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 37.9 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f94208f336e6dab7401b14329c9566c7b774f72fd2e60cb47a231a0bd8a142e4
|
|
| MD5 |
43c8312d4b8223d94b69c1942a7e25d6
|
|
| BLAKE2b-256 |
5a47ab83b3e602436a754e38cd3476d526d195f88dd15df41dbed10c8a2b37b9
|