Python SDK for programmatic access to qwen-code CLI
Project description
qwen-code-sdk
Experimental Python SDK for programmatic access to Qwen Code through the
stream-json protocol.
Installation
pip install qwen-code-sdk
Requirements
- Python
>=3.10 - External
qwenCLI installed and available inPATH
You can also point the SDK at an explicit CLI binary or script with
path_to_qwen_executable.
Quick Start
import asyncio
from qwen_code_sdk import is_sdk_result_message, query
async def main() -> None:
result = query(
"List the top-level packages in this repository.",
{
"cwd": "/path/to/project",
"path_to_qwen_executable": "qwen",
},
)
async for message in result:
if is_sdk_result_message(message):
print(message["result"])
asyncio.run(main())
Sync API
from qwen_code_sdk import query_sync
with query_sync(
"Say hello",
{
"path_to_qwen_executable": "qwen",
},
) as result:
for message in result:
print(message)
Main APIs
query(prompt, options=None) -> Queryquery_sync(prompt, options=None) -> SyncQueryQuery.close(),interrupt(),set_model(),set_permission_mode()Query.supported_commands(),mcp_server_status(),get_session_id()
prompt accepts either a single str or an AsyncIterable[SDKUserMessage]
for multi-turn sessions.
Permission Callback
from qwen_code_sdk import query
async def can_use_tool(tool_name, tool_input, context):
if tool_name == "write_file":
return {"behavior": "deny", "message": "Writes disabled in this app"}
return {"behavior": "allow", "updatedInput": tool_input}
result = query(
"Create hello.txt",
{
"path_to_qwen_executable": "qwen",
"can_use_tool": can_use_tool,
},
)
The callback defaults to deny. If it does not return within 60 seconds, the SDK auto-denies the tool request.
The context argument includes cancel_event, suggestions, and
blocked_path when the CLI provides a path-specific permission target.
can_use_tool must be an async def callback accepting
(tool_name, tool_input, context). stderr must accept a single str.
Errors
ValidationError: invalid query options or malformed session identifiersControlRequestTimeoutError: CLI control operation exceeded timeoutProcessExitError:qwenexited with a non-zero codeAbortError: query or control request was cancelled
Current Scope
0.1.x is intentionally narrow:
- Uses external
qwenCLI via process transport - Targets
stream-jsonparity with the TypeScript SDK core flow - Does not yet implement ACP transport
- Does not yet embed MCP servers inside the SDK process
See developer documentation for more detail.
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 qwen_code_sdk-0.1.0rc0.tar.gz.
File metadata
- Download URL: qwen_code_sdk-0.1.0rc0.tar.gz
- Upload date:
- Size: 30.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44778d6a24acf14372de93caec427c0fd6187d772a3893a335bac4e55450b03d
|
|
| MD5 |
3953ab02fd9b4be7e8a8b1c20ec7b2d6
|
|
| BLAKE2b-256 |
6ca675b21be3972737f8c653ee83ed88824454abd293d432df793e37ce79943f
|
Provenance
The following attestation bundles were made for qwen_code_sdk-0.1.0rc0.tar.gz:
Publisher:
release-sdk-python.yml on QwenLM/qwen-code
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qwen_code_sdk-0.1.0rc0.tar.gz -
Subject digest:
44778d6a24acf14372de93caec427c0fd6187d772a3893a335bac4e55450b03d - Sigstore transparency entry: 1484878895
- Sigstore integration time:
-
Permalink:
QwenLM/qwen-code@4bab7a1ad64af8a050626686ba88750842c78620 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/QwenLM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-sdk-python.yml@4bab7a1ad64af8a050626686ba88750842c78620 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file qwen_code_sdk-0.1.0rc0-py3-none-any.whl.
File metadata
- Download URL: qwen_code_sdk-0.1.0rc0-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd31047815168a303f24ca44cc49b93f5ab4c5a731ee3fda33a2c691966804d5
|
|
| MD5 |
f94cbede30959d82b94caa75aacbba64
|
|
| BLAKE2b-256 |
c9d607c374a10453bcf9f0c79cbe3fcd78af791087025aa85c9db5e2ab86947f
|
Provenance
The following attestation bundles were made for qwen_code_sdk-0.1.0rc0-py3-none-any.whl:
Publisher:
release-sdk-python.yml on QwenLM/qwen-code
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qwen_code_sdk-0.1.0rc0-py3-none-any.whl -
Subject digest:
cd31047815168a303f24ca44cc49b93f5ab4c5a731ee3fda33a2c691966804d5 - Sigstore transparency entry: 1484878899
- Sigstore integration time:
-
Permalink:
QwenLM/qwen-code@4bab7a1ad64af8a050626686ba88750842c78620 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/QwenLM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-sdk-python.yml@4bab7a1ad64af8a050626686ba88750842c78620 -
Trigger Event:
workflow_dispatch
-
Statement type: