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

Commit faa4c66

Browse files
committed
docs: add Python SDK example and README instructions
- 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>
1 parent 0b9b082 commit faa4c66

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,29 @@ npm run build
2828
node examples/napi.js
2929
```
3030

31+
### Python
32+
33+
34+
> **Setup (one-time):**
35+
> ```bash
36+
> pipx install maturin # to install, see: https://pipx.pypa.io/stable/
37+
>
38+
> pipx ensurepath # adds ~/.local/bin to PATH
39+
>
40+
> # Restart your terminal or run: export PATH="$HOME/.local/bin:$PATH"
41+
> ```
42+
43+
Run from Python:
44+
```bash
45+
# Create and activate venv
46+
python3 -m venv .venv
47+
source .venv/bin/activate
48+
49+
# Build the Rust extension and install it in venv then run example
50+
maturin develop --features python
51+
python examples/python_sdk_example.py
52+
```
53+
3154
### C & C++ Programs
3255

3356
For compiled languages, you'll need to compile first, then run.
@@ -120,6 +143,26 @@ if (result.success) {
120143
}
121144
```
122145

146+
### Python
147+
148+
```python
149+
import asyncio
150+
from hyperlight_nanvix import NanvixSandbox, SandboxConfig
151+
152+
async def main():
153+
config = SandboxConfig(
154+
log_directory="/tmp/hyperlight-nanvix",
155+
tmp_directory="/tmp/hyperlight-nanvix"
156+
)
157+
sandbox = NanvixSandbox(config)
158+
159+
result = await sandbox.run('guest-examples/hello.js')
160+
if result.success:
161+
print('Execution completed')
162+
163+
asyncio.run(main())
164+
```
165+
123166
To embed in your own project:
124167

125168
```bash

examples/python_sdk_example.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import asyncio
2+
from hyperlight_nanvix import NanvixSandbox
3+
4+
async def main():
5+
print("Running guest-examples/hello.js...")
6+
7+
try:
8+
sandbox = NanvixSandbox()
9+
result = await sandbox.run("guest-examples/hello.js")
10+
11+
if result.success:
12+
print("Workload completed successfully!")
13+
else:
14+
print(f"Error: {result.error}")
15+
exit(1)
16+
except Exception as error:
17+
print(f"Error: {error}")
18+
exit(1)
19+
20+
asyncio.run(main())

0 commit comments

Comments
 (0)