Repository navigation
feat(sdk): add Python SDK (minimax-code-sdk) 0.1 - #571
Merged
Merged
Conversation
Adds packages/code-sdk-python, a Python counterpart of @minimax-ai/code-sdk that drives `mcode exec --output-format=stream-json` once per Turn and resumes Sessions with --session.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
packages/code-sdk-python, the Python counterpart of@minimax-ai/code-sdk. The PyPI name isminimax-code-sdk, the import isminimax_code, it is MIT licensed and needs Python 3.10+. Its only runtime dependency istyping_extensions.The SDK has the same shape as the TS SDK. Each Turn runs
mcode exec --output-format=stream-json --input=- --input-format=jsonand later Turns continue the Session with--session. Events are typed frompackages/code-sdk/src/types.ts(schemaVersion 1) and are passed through unchanged.API sketch
bin, then$MCODE_BIN, thenPATH. JS entries run throughnode. The SDK checksmcode --versionagainst a minimum of 0.6.3, the same as the TS SDK.MCodeNotFoundError,MCodeVersionError,MCodeInvocationError,MCodeRunError(withstatusandcategory),MCodeAbortError,MCodeProtocolErrorandThreadBusyError. They carryexit_code, thestderrtail,session_id,resultanditems. Exit codes map the same way asMCODE_EXEC_EXIT_CODES.item.*events are merged by id, and duplicate snapshot updates are dropped, the same asItemAccumulator. System prompts are passed through private temp files that are removed after the Turn.Design choice
For 0.1 the SDK uses exec-per-turn, the same transport as the TS SDK, so the two SDKs behave the same and the CLI needs no changes. This transport cannot handle interactive approvals (
permission="ask") or tools defined in Python. A long-lived ACP transport (mcode acpplus theagent-client-protocolclient) is planned for 0.2, behind the sameThreadAPI.Repo changes outside the package
.github/workflows/python-sdk.ymlruns ruff, ruff format, mypy (strict) and pytest on Ubuntu and macOS with Python 3.10 and 3.13. It triggers only on changes under its own paths, and the existing verify jobs are untouched.release/public-source.jsonrecords the new files.scripts/source-inventory.mjsnow skips local Python caches (.venv,__pycache__,.pytest_cache,.mypy_cache,.ruff_cache). Without this, runninguv synclocally breakscheck:sourcebecause of the.venvsymlinks.Testing
uv run pytest -W error: 15 unit tests passed and 3 e2e tests were skipped (they are opt-in). The unit tests use a fakemcodescript and cover arguments, multi-turn and resume, streaming and dedupe, failure, invocation, crash and protocol errors, a missing CLI, an old CLI version, cancellation bycancel(), by task cancel and bybreak, the busy-thread error and the sync wrapper. They passed on Python 3.12 and 3.10.ruff check,ruff format --checkandmypy --strictare clean.dist/cli.jsbuilt from this branch (0.7.2) with a real MiniMax model:MCODE_SDK_E2E=1 uv run pytest -m e2ecovers a single run, a streamed run and multi-turn resume, and all 3 passed. A manual check also confirmed:streamed.cancel()ends the stream withexec.completedstatuscancelled.pnpm verify --profile fullpasses locally on Linux.Follow-ups
_meta.packages/protocolinstead of mirroring them by hand.cli-contract.test.ts.pkill.Need help on this PR? Tag
@codesmith-botwith what you need.