-
Notifications
You must be signed in to change notification settings - Fork 1
Add Python host SDK #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
8f943de to
374d0cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds Python bindings for hyperlight-nanvix using PyO3, enabling Python developers to run JavaScript, Python, C, and C++ workloads in sandboxed environments with an API that mirrors the existing Node.js SDK.
Key Changes:
- Implements PyO3-based Python bindings with async support via pyo3-asyncio and Tokio runtime
- Adds type stubs for IDE support and type checking
- Provides complete Python package configuration with maturin build system
Reviewed changes
Copilot reviewed 8 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/python.rs | Core PyO3 implementation providing NanvixSandbox, SandboxConfig, and WorkloadResult classes with async methods |
| src/lib.rs | Adds conditional compilation flag for python feature module |
| python/hyperlight_nanvix/init.pyi | Type stub definitions for IDE autocomplete and type checking |
| python/hyperlight_nanvix/init.py | Python package initialization with version and exports |
| pyproject.toml | Maturin build configuration for Python packaging |
| Cargo.toml | Adds optional pyo3 and pyo3-asyncio dependencies with python feature flag |
| Cargo.lock | Lock file updates with new PyO3 dependency tree |
| examples/python_sdk_example.py | Example demonstrating Python SDK usage with async/await |
| README.md | Documentation for Python setup, usage examples, and API reference |
| .gitignore | Adds Python-specific ignore patterns for virtual environments and build artifacts |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fn clear_cache<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { | ||
| let runtime = Arc::clone(&self.runtime); | ||
|
|
||
| pyo3_asyncio::tokio::future_into_py(py, async move { | ||
| runtime.clear_cache().await | ||
| .map_err(|e| PyRuntimeError::new_err(format!("Failed to clear cache: {}", e))) | ||
| }) | ||
| } |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Python binding's clear_cache method has an inconsistent return type compared to the Node.js binding. The Node.js version returns a boolean (true on success, error on failure), while the Python version returns None on success. For API consistency across language bindings, consider returning a boolean value in the Python binding as well. This would make the Python API more predictable and align with the Node.js SDK pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in e0e69cf.
- Add pyo3 and pyo3-asyncio dependencies with python feature flag - Implement Python bindings in src/python.rs mirroring napi.rs structure - Add pyproject.toml for maturin build configuration - Create Python package structure with type stubs - Support async/await for sandbox operations Signed-off-by: danbugs <danilochiarlone@gmail.com>
- Add python_sdk_example.py following napi.js pattern - Update README with Python setup and usage instructions - Include one-time maturin installation steps Signed-off-by: danbugs <danilochiarlone@gmail.com>
- Ignore .venv/, __pycache__/, and Python compiled files - Ignore compiled .so files in python/ directory Signed-off-by: danbugs <danilochiarlone@gmail.com>
- Changes clear_cache to return bool (true on success) - Updates type stub to reflect bool return type - Aligns Python SDK with Node.js SDK behavior Addresses PR #20 feedback from @copilot-pull-request-reviewer Related issues: #22 (tests), #23 (code strings) Signed-off-by: danbugs <danilochiarlone@gmail.com>
374d0cb to
e0e69cf
Compare
Adds Python bindings for hyperlight-nanvix using PyO3. Python users can now run JavaScript, Python, C, and C++ workloads in sandboxes with the same API as the Node.js bindings.
Setup:
Usage:
Changes include PyO3 bindings with async support, maturin build configuration, type stubs, and an example that follows the same pattern as the Node.js SDK.