Skip to content
This repository was archived by the owner on May 14, 2026. It is now read-only.

Commit 0b9b082

Browse files
committed
feat: add Python SDK with PyO3 bindings
- 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>
1 parent 2c39f34 commit 0b9b082

7 files changed

Lines changed: 363 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 164 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ libc = "0.2.178"
1414
napi = { version = "3.5.0", optional = true, features = ["async", "serde-json"] }
1515
napi-derive = { version = "3.3.0", optional = true }
1616

17+
# Python bindings (optional)
18+
pyo3 = { version = "0.20", optional = true, features = ["extension-module", "abi3-py38"] }
19+
pyo3-asyncio = { version = "0.20", optional = true, features = ["tokio-runtime"] }
20+
1721
[features]
1822
default = []
1923
napi = ["dep:napi", "dep:napi-derive", "dep:napi-build"]
24+
python = ["dep:pyo3", "dep:pyo3-asyncio"]
2025

2126
[lib]
2227
crate-type = ["cdylib", "rlib"]

pyproject.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[build-system]
2+
requires = ["maturin>=1.0,<2.0"]
3+
build-backend = "maturin"
4+
5+
[project]
6+
name = "hyperlight-nanvix"
7+
version = "0.1.0"
8+
requires-python = ">=3.8"
9+
10+
[tool.maturin]
11+
features = ["python"]
12+
module-name = "hyperlight_nanvix.hyperlight_nanvix"
13+
python-source = "python"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
hyperlight-nanvix: Python bindings for running sandboxed workloads
3+
4+
This module provides a Python interface to the Nanvix microkernel-based
5+
sandbox system, allowing you to run JavaScript, Python, C, and C++
6+
workloads in isolated environments.
7+
"""
8+
9+
from .hyperlight_nanvix import NanvixSandbox, SandboxConfig, WorkloadResult
10+
11+
__version__ = "0.1.0"
12+
__all__ = ["NanvixSandbox", "SandboxConfig", "WorkloadResult"]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from typing import Optional
2+
3+
class SandboxConfig:
4+
log_directory: Optional[str]
5+
tmp_directory: Optional[str]
6+
def __init__(self, log_directory: Optional[str] = None, tmp_directory: Optional[str] = None) -> None: ...
7+
8+
class WorkloadResult:
9+
success: bool
10+
error: Optional[str]
11+
12+
class NanvixSandbox:
13+
def __init__(self, config: Optional[SandboxConfig] = None) -> None: ...
14+
async def run(self, workload_path: str) -> WorkloadResult: ...
15+
async def clear_cache(self) -> None: ...
16+
17+
__all__ = ["NanvixSandbox", "SandboxConfig", "WorkloadResult"]

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ pub mod runtime;
77
#[cfg(feature = "napi")]
88
pub mod napi;
99

10+
#[cfg(feature = "python")]
11+
pub mod python;
12+
1013
#[cfg(test)]
1114
mod unit_tests;
1215

0 commit comments

Comments
 (0)