Skip to main content

Capsule adapter for Python applications — execute Python and JavaScript code in isolated WebAssembly sandboxes

Project description

Capsule Python Adapter

Python Adapter Release

Execute Python and JavaScript code securely inside Capsule sandboxes from your Python applications.

Installation

pip install capsule-run-adapter

Usage

Execute Python Code

from capsule_adapter import run_python

result = await run_python("""
print("Hello from Python!")
x = 5 + 3
x * 2
""")

print(result)  # "Hello from Python!\n16"

Execute JavaScript Code

from capsule_adapter import run_javascript

result = await run_javascript("""
console.log("Hello from JavaScript!");
const x = 5 + 3;
x * 2;
""")

print(result)  # "Hello from JavaScript!\n16"

Preload Sandboxes (Optional)

The first execution of a sandbox has a cold start (~1 second). You can preload sandboxes to warm them up for faster subsequent executions (~10ms):

import asyncio
from capsule_adapter import load_sandboxes, run_python

async def main():
    # Preload sandboxes
    await load_sandboxes()

    # Or preload individually
    # await load_python_sandbox()     # Warm up Python only
    # await load_javascript_sandbox() # Warm up JavaScript only

    # Fast execution
    result = await run_python('print("Fast!")')
    print(result)

asyncio.run(main())

How It Works

The adapter compiles Python and JavaScript sandboxes into WebAssembly modules during the build step. When you call run_python() or run_javascript(), the adapter invokes these pre-built sandboxes using Capsule's runner with the code you provide.

Learn more about Capsule.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

capsule_run_adapter-0.1.3.tar.gz (20.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

capsule_run_adapter-0.1.3-py2.py3-none-any.whl (20.5 MB view details)

Uploaded Python 2Python 3

File details

Details for the file capsule_run_adapter-0.1.3.tar.gz.

File metadata

  • Download URL: capsule_run_adapter-0.1.3.tar.gz
  • Upload date:
  • Size: 20.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for capsule_run_adapter-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d6ba7aa5ad7da2a374ad17410f1501c014cfd244f5dccabe772645b699f64ba5
MD5 0f9fe863d7e8f1a1c3eab74a0dc55efb
BLAKE2b-256 0783b5d576c1fb35a95d829ba4f3d9c219bf7a9d6613b74c86f2c12d6ad4fb26

See more details on using hashes here.

File details

Details for the file capsule_run_adapter-0.1.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for capsule_run_adapter-0.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 aa971a36ef01c5414f83d8a12cf0d19fbd89f744875fff638c857a508b2ac792
MD5 05f928280d989782de4a786326e1619b
BLAKE2b-256 242064bdc4c3fadb4ca5a4dd75b468828ab2ad0a41cf0c4d1ef15209b51cb76f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page