Skip to content

jsrun

Modern JavaScript runtime for Python

PyPI

jsrun is a Python library that embeds the V8 JavaScript engine, allowing you to run JavaScript code directly from Python.

Whether you need to run user scripts, integrate JavaScript libraries, execute code for AI agents, or build extensible Python applications, jsrun provides a robust solution.

Highlights

  • ๐Ÿš€ Fast: Powered by V8, the JavaScript engine used in Chrome and Node.js
  • ๐Ÿ”Œ Extensible: Bind Python functions and objects to JavaScript
  • โšก Async First: Support JavaScript Promises and async function in Python asyncio
  • ๐Ÿ”’ Isolated Sandbox: Runtime is a V8 isolate that has no I/O access by default
  • ๐ŸŽ›๏ธ Resource Controls: Prevent abuse by setting per-runtime heap memory limits and execution timeouts
  • ๐Ÿงต Parallelism: Run multiple runtimes in parallel on different Python threads
  • ๐Ÿ“ฆ Module Support: ES modules with custom loaders and resolvers
  • โš™๏ธ WebAssembly: Execute WebAssembly (WASM) directly in native runtime
  • ๐ŸŽฏ Typing: Comprehensive type hints for PyO3 bindings

Quick Example

import jsrun

result = jsrun.eval("2 + 2")
print(result)  # 4

# Bind Python function
jsrun.bind_function("add", lambda a, b: a + b)
print(jsrun.eval("add(2, 3)"))  # 5

Next Steps

  • Quick Start - Get up and running with essential features
  • Core Concepts - Understand the runtime architecture and execution model
  • Type Conversion - Learn how data types map between Python and JavaScript
  • Use Cases - Explore practical examples and real-world applications
  • API Reference - Comprehensive API documentation for all classes and functions