MonkeysCode Python SDK
Programmatic agent control for Python. Run coding agents, stream events, define custom tools, and integrate with CI/CD pipelines.
Installation
pip install monkeyscode
Quick Start
from monkeyscode import MonkeysCode
import asyncio
async def main():
agent = MonkeysCode(api_key="mc_...")
result = await agent.run("Fix all Python type errors")
print(f"✓ {result.summary}")
print(f" Files: {len(result.files_changed)}, Cost: ${result.cost:.4f}")
asyncio.run(main())
Streaming
async for event in agent.stream("Refactor auth module"):
if event.type == "text":
print(event.content, end="", flush=True)
elif event.type == "tool_call":
print(f" 🔧 {event.tool}")
Custom Tools
from monkeyscode import define_tool
@define_tool(
name="deploy",
description="Deploy the application",
parameters={"env": {"type": "string", "enum": ["staging", "prod"]}},
)
async def deploy(env: str) -> dict:
return {"deployed": True, "url": f"https://{env}.example.com"}
agent.add_tool(deploy)
Goal Mode
result = await agent.goal(
"All tests pass",
verify_command="pytest",
max_iterations=5,
)
print(f"Goal met: {result.goal_met} in {result.iterations} iterations")
Sessions
from monkeyscode import Session
session = await Session.create(agent, workspace="/my/project")
await session.run("Add auth module")
await session.run("Now add tests for it") # Carries context
session.close()
Local agent (mc subprocess)
The client above calls the hosted API. To run the agent on this machine
with your settings, permission rules, hooks and MCP servers, drive an
installed mc (standard library only):
from monkeyscode.cli_process import (
CliOptions, MonkeysCodeClient, PermissionAllow, PermissionDeny, ResultMessage, query,
)
async for event in query("explain src/main.ts"):
if isinstance(event, ResultMessage):
print(event.result, event.cost_usd)
async def can_use_tool(tool, tool_input, ctx):
if str(tool_input.get("path", "")).startswith("docs/"):
return PermissionAllow()
return PermissionDeny(message="only docs/ may be written")
async with MonkeysCodeClient(CliOptions(can_use_tool=can_use_tool, max_cost_usd=1)) as client:
await client.send("write docs/intro.md")
result = await client.receive_result()
query_cli and MonkeysCodeClient are also exported from monkeyscode.
Guide: docs/cli/sdk.md; a runnable three-turn
example: examples/three_turn_approval.py.
CI/CD
from monkeyscode.ci import ci_run, to_sarif
import json
result = await ci_run(
prompt="Review this PR for security issues",
diff=open("pr.diff").read(),
)
sarif = to_sarif(result)
with open("results.sarif", "w") as f:
json.dump(sarif, f, indent=2)
License
MIT
Metadata
Release files for monkeyscode 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| monkeyscode-1.0.0.tar.gz | 46.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| monkeyscode-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 97.1 kB
Release files / monkeyscode-1.0.0.tar.gz
| Download URL | monkeyscode-1.0.0.tar.gz |
|---|---|
| Size | 46.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f7e9b2073d8ca3f5d93ccede6630765790238629b156337b25ec0752cfe5e801
|
|
BLAKE2b-256 checksum How to use checksums |
3a00ac381f60560167813efce19f3b3252ed236a9de699c7c5c64800aab24f4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 30, 2026.
Transparency logRelease files / monkeyscode-1.0.0-py3-none-any.whl
| Download URL | monkeyscode-1.0.0-py3-none-any.whl |
|---|---|
| Size | 50.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1dcf090f6bcde79fc28d51c178c92e1be974a8d6de7cbd59375bb9d2501dc461
|
|
BLAKE2b-256 checksum How to use checksums |
cd163ef23ae8e9a12b860d2b700dc932ce97667eee7caacb0360eac2c36e01d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 30, 2026.
Transparency log