Skip to content

Add runanywhere-python: Python SDK (pybind11 over the rac_* C ABI)#575

Open
AmanSwar wants to merge 187 commits into
mainfrom
feat/python-sdk
Open

Add runanywhere-python: Python SDK (pybind11 over the rac_* C ABI)#575
AmanSwar wants to merge 187 commits into
mainfrom
feat/python-sdk

Conversation

@AmanSwar

@AmanSwar AmanSwar commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Python SDK (runanywhere) over the rac_* C ABI via pybind11, with hermetic tests and wheel CI (Linux 3.9+3.12, macOS, Windows).
  • Overnight hardening (merge-readiness): honest secure-store/Phase-2 docs, removed dead api_key/base_url client knobs, full IDL ErrorCode table aligned with commons categories, VAD unload leases + Win32 _ftelli64, RAG registry ABI constants, IDL Python codegen wired into drift CI.
  • Thin commons bridges: LLM/VLM cancel (wired into stream on_stop), Silero load_vad_model, embed_batch, registry get/list/remove, VLM generation options.
  • SDK-level best practices recorded in sdk/runanywhere-python/AGENTS.md (symlink CLAUDE.md).

Test plan

  • pytest hermetic suite (438 passed, 20 skipped) in clean venv
  • python-linux / python-macos previously green; re-check after this push (incl. 3.9 matrix)
  • Confirm idl-drift-check installs grpcio-tools and covers _proto/**
  • Spot-check secure_set docstring / README no longer claim POSIX encryption or client auth knobs

@sanchitmonga22

Copy link
Copy Markdown
Contributor

@coderabbitai please review this PR

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

@sanchitmonga22 I’ll review this PR.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sdk/runanywhere-python/LICENSE`:
- Around line 310-316: Remove the duplicate trailing MIT-style disclaimer from
sdk/runanywhere-python/LICENSE, or reconcile it into the existing Apache 2.0
warranty and liability language in Part III. Preserve one canonical disclaimer
and ensure the final license structure is consistent before release.

In `@sdk/runanywhere-python/runanywhere/download.py`:
- Line 255: Update the __slots__ declaration in the relevant class to list its
slot names in natural alphabetical order, resolving Ruff RUF023 while preserving
the existing slot names.
- Around line 288-291: In the download completion cleanup within the surrounding
function, call state.event.set() before acquiring _IN_FLIGHT_LOCK and removing
dest from _IN_FLIGHT. Preserve the existing cleanup and signaling behavior while
ensuring waiters observe completion before another caller can claim the
destination.

In `@sdk/runanywhere-python/runanywhere/events.py`:
- Around line 98-103: Update the listener exception handler in the event
dispatch logic to log caught Exception instances without including or
serializing the event payload. Retain the broad Exception boundary so
control-flow exceptions propagate, add the explicit BLE001 suppression for the
intentional catch, and replace the silent pass with contextual exception
logging.

In `@sdk/runanywhere-python/tests/test_model_streaming.py`:
- Around line 48-49: Update the streaming tests around LLMModel construction to
use a shared fixture that replaces runanywhere._native.get_core with FakeCore,
rather than passing FakeCore directly into each model. Construct every affected
model through this get_core seam so the tests remain native-free while
exercising the required lifecycle boundary.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e809a91d-883c-4186-b457-b0bafc6b63c3

📥 Commits

Reviewing files that changed from the base of the PR and between 85760e5 and c35ca07.

📒 Files selected for processing (25)
  • .github/workflows/pr-build.yml
  • idl/codegen/generate_python.sh
  • sdk/runanywhere-python/LICENSE
  • sdk/runanywhere-python/native/module.cpp
  • sdk/runanywhere-python/native/posix_platform_adapter.cpp
  • sdk/runanywhere-python/native/win32_platform_adapter.cpp
  • sdk/runanywhere-python/pyproject.toml
  • sdk/runanywhere-python/runanywhere/_native/_core.pyi
  • sdk/runanywhere-python/runanywhere/_proto/__init__.py
  • sdk/runanywhere-python/runanywhere/_proto/rac_options_pb2.py
  • sdk/runanywhere-python/runanywhere/_proto/rag_pb2.py
  • sdk/runanywhere-python/runanywhere/cli/__init__.py
  • sdk/runanywhere-python/runanywhere/cli/handlers.py
  • sdk/runanywhere-python/runanywhere/cli/output.py
  • sdk/runanywhere-python/runanywhere/client.py
  • sdk/runanywhere-python/runanywhere/download.py
  • sdk/runanywhere-python/runanywhere/events.py
  • sdk/runanywhere-python/runanywhere/models.py
  • sdk/runanywhere-python/runanywhere/server/app.py
  • sdk/runanywhere-python/tests/test_cli.py
  • sdk/runanywhere-python/tests/test_client.py
  • sdk/runanywhere-python/tests/test_download.py
  • sdk/runanywhere-python/tests/test_grammar.py
  • sdk/runanywhere-python/tests/test_model_streaming.py
  • sdk/runanywhere-python/tests/test_parity_fixes.py
🚧 Files skipped from review as they are similar to previous changes (20)
  • sdk/runanywhere-python/runanywhere/_proto/init.py
  • sdk/runanywhere-python/runanywhere/_proto/rag_pb2.py
  • sdk/runanywhere-python/runanywhere/_proto/rac_options_pb2.py
  • sdk/runanywhere-python/tests/test_download.py
  • sdk/runanywhere-python/runanywhere/cli/init.py
  • sdk/runanywhere-python/runanywhere/cli/output.py
  • sdk/runanywhere-python/pyproject.toml
  • sdk/runanywhere-python/native/win32_platform_adapter.cpp
  • sdk/runanywhere-python/native/posix_platform_adapter.cpp
  • sdk/runanywhere-python/tests/test_parity_fixes.py
  • idl/codegen/generate_python.sh
  • sdk/runanywhere-python/tests/test_client.py
  • sdk/runanywhere-python/tests/test_cli.py
  • sdk/runanywhere-python/runanywhere/cli/handlers.py
  • sdk/runanywhere-python/runanywhere/models.py
  • sdk/runanywhere-python/runanywhere/client.py
  • .github/workflows/pr-build.yml
  • sdk/runanywhere-python/tests/test_grammar.py
  • sdk/runanywhere-python/runanywhere/server/app.py
  • sdk/runanywhere-python/native/module.cpp

Comment thread sdk/runanywhere-python/LICENSE Outdated
Comment thread sdk/runanywhere-python/runanywhere/download.py Outdated
Comment thread sdk/runanywhere-python/runanywhere/download.py Outdated
Comment thread sdk/runanywhere-python/runanywhere/events.py Outdated
Comment thread sdk/runanywhere-python/tests/test_model_streaming.py Outdated
sanchitmonga22 and others added 6 commits July 24, 2026 22:42
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@sanchitmonga22

Copy link
Copy Markdown
Contributor

Overnight hardening complete (ready for morning review)

Addressed all PR review comments in-tree (no new GitHub issues). Capability + architecture review vs Swift/commons completed.

Fixes landed (latest commits on feat/python-sdk)

  • Ignore compiled _core*.so / _core*.dylib
  • Public audio APIs raise SDKException (not bare ValueError)
  • Structured types: ModelType, ChatRole
  • Init/shutdown per-client idempotency under _state_lock
  • Download dedup: signal completion before popping in-flight entry
  • EventBus logs isolated listener failures
  • OpenAI server SSRF: resolve once, connect-by-IP, reject redirects
  • HTTPException → OpenAI error envelope (already present); pcm rejected; multipart >=0.0.32
  • CLI: --no-think, thinking stream display, backends/info/serve error exit codes
  • RAG: begin_op / take_handle_when_idle so destroy cannot UAF mid-query
  • QHexRT docs honesty: Android-only today — Windows Snapdragon HNPU not enabled
  • Sync generate_with_tools runs async tool coroutines via asyncio.run
  • Playground demo comments: INVALID (folded into runanywhere.server earlier)

Tests

431 passed, 20 skipped in a clean venv (pytest tests).

QHexRT / Snapdragon Windows

Cannot enable tonight. Engine is gated to RAC_PLATFORM_ANDROID + private arm64-v8a archive. Desktop wheels correctly ship llamacpp + onnx + sherpa (CPU). Future epic needs Windows QNN/QHexRT packaging + capability-gate lift.

Follow-up Electron PR

#592

Note on CI

python-windows / python-linux / python-macos were green on prior push. Unrelated swift-spm SwiftLint / kotlin-android failures should not block this Python package merge unless they prove branch-caused.

sanchitmonga22 and others added 16 commits July 24, 2026 23:13
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
macOS runners install grpcio-tools for python3 while bare `python` pointed
at a different interpreter without the module, breaking the IDL drift gate.

Co-authored-by: Cursor <cursoragent@cursor.com>
BSD sed rejects GNU `a` syntax; rewrite imports and insert the future
import with Python so the IDL drift gate works on macos-15 runners.

Co-authored-by: Cursor <cursoragent@cursor.com>
python-multipart>=0.0.32 requires 3.10+; pin the last 3.9-compatible
line via environment markers so the Linux 3.9 CI hermetic install works.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants