Skip to main content

A Javascript Sandbox for Python, powered by Deno

Project description

Belgie: A Javascript Sandbox for Python, powered by Deno

Belgie lets you run JavaScript and TypeScript from Python. Deno is bundled — you do not need Node.js or Deno on your PATH.

  • Scripts from Python: Run inline or file-based JS/TS with Runtime and Script, sync or async.
  • Inline dependencies: Import npm, JSR, and URL modules directly from JS/TS source.
  • Isolated packages: Use Environment for lockfiles, custom cache/options, local packages, and commands.
  • CLI tools: Run npm binaries (Vite, esbuild, etc.) through Command.
  • Simple data bridge: Pass JSON-safe dicts, lists, and primitives across the boundary.
  • Pydantic AI & LangChain: Expose a sandboxed run_code tool for JS/TS when Python is not the best fit.

Installation

uv add belgie
uvx library-skills install  # optional: install the use-belgie skill for Cursor, Codex, Claude, etc.

Quick Start

import asyncio

from belgie import Runtime, Script

script = Script[[str], str](
    """
import camelcase from "npm:camelcase@8.0.0";

export default function run(input: string): string {
  return camelcase(input);
}
"""
)

async def main() -> None:
    async with Runtime() as run:
        print(await run(script)("foo-bar"))  # prints: fooBar

asyncio.run(main())

Pydantic AI

Add BelgieCapability() to a Pydantic AI agent to expose a sandboxed run_code tool. The agent can execute TypeScript or JavaScript in belgie's embedded Deno runtime—useful for npm packages, data fetching, and JS-side transforms.

Install with uv add "belgie[pydantic-ai]", set OPENAI_API_KEY, then:

from pydantic_ai import Agent

from belgie.pydantic_ai import BelgieCapability

agent = Agent("openai:gpt-5", capabilities=[BelgieCapability()])

result = agent.run_sync(
    "Convert 'foo-bar' to camelCase using TypeScript and the camelcase npm package.",
)
print(result.output)

See the full runnable project in examples/ai/pydantic-ai.

LangChain

Attach BelgieMiddleware() to a LangChain agent to expose the same sandboxed run_code tool for JS/TS execution. Deno is bundled—no Node install required.

Install with uv add "belgie[langchain]", set OPENAI_API_KEY, then:

from langchain.agents import create_agent

from belgie.langchain import BelgieMiddleware

agent = create_agent(
    model="openai:gpt-5",
    tools=[],
    middleware=[BelgieMiddleware()],
    system_prompt="You can execute JS/TS in a Deno sandbox with run_code.",
)

result = agent.invoke(
    {
        "messages": [
            (
                "user",
                "Convert 'foo-bar' to camelCase using TypeScript and the camelcase npm package.",
            ),
        ],
    },
)
print(result["messages"][-1].content)

See the full runnable project in examples/ai/langchain.

Examples

Want to learn more about Belgie's features? The examples below are small, runnable projects — each one focuses on a single capability.

Basic

  • simple: Async Runtime with a TypeScript file on disk.
  • inline-deps: Direct npm:, jsr:, and URL imports in a script.
  • jsr-deps: JSR packages declared through an explicit Environment.
  • pyproject: Manage project package dependencies with belgie[cli] and [tool.belgie.dependencies].
  • environment: Sync and async Environment setup with path.
  • commands: npm package binaries via Runtime and Command.

AI

  • pydantic-ai: Pydantic AI agent with BelgieCapability() for sandboxed JS/TS execution.
  • langchain: LangChain agent with BelgieMiddleware() for sandboxed JS/TS execution.

UI

  • mcp: MCP Apps extension with a React widget built through Belgie.
  • shadcn: MCP Apps widget styled with Tailwind CSS and shadcn/ui.

For deeper integration guidance, optionally install the use-belgie skill with uvx library-skills install.

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

belgie-0.32.0.tar.gz (541.2 kB view details)

Uploaded Source

Built Distributions

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

belgie-0.32.0-cp312-abi3-win_amd64.whl (53.9 MB view details)

Uploaded CPython 3.12+Windows x86-64

belgie-0.32.0-cp312-abi3-manylinux_2_28_x86_64.whl (60.9 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ x86-64

belgie-0.32.0-cp312-abi3-manylinux_2_28_aarch64.whl (64.5 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ ARM64

belgie-0.32.0-cp312-abi3-macosx_11_0_arm64.whl (55.1 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

belgie-0.32.0-cp312-abi3-macosx_10_12_x86_64.whl (57.1 MB view details)

Uploaded CPython 3.12+macOS 10.12+ x86-64

File details

Details for the file belgie-0.32.0.tar.gz.

File metadata

  • Download URL: belgie-0.32.0.tar.gz
  • Upload date:
  • Size: 541.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for belgie-0.32.0.tar.gz
Algorithm Hash digest
SHA256 b042491e80464ed2533b161c852012b47ec8fa0854fa84fb31c5ab2bfccfdc96
MD5 a5818759069b2aedbc34fe455f4b0c6a
BLAKE2b-256 0f48b6a99c81262ef569eea380967c00471bbe7607432fccfac899721e2a1669

See more details on using hashes here.

File details

Details for the file belgie-0.32.0-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: belgie-0.32.0-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 53.9 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for belgie-0.32.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9754a1f18ddff7e5f18126d98d8c4edc5b810180497bf0fff6abf60ac0ca3e77
MD5 99c7769a07a1cad7ab944b08e53af129
BLAKE2b-256 dad200f3bf255febc989384686ee4cbd8185336cec6786ca3e339a02e1f52704

See more details on using hashes here.

File details

Details for the file belgie-0.32.0-cp312-abi3-manylinux_2_28_x86_64.whl.

File metadata

  • Download URL: belgie-0.32.0-cp312-abi3-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 60.9 MB
  • Tags: CPython 3.12+, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for belgie-0.32.0-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ec54f8d228e05e68368b59750752f91e8c726f4d2474d5d6370a48440f9a0aa0
MD5 f98cbe80bc7d98c03e606a2ed29067e1
BLAKE2b-256 dd45895ede4efbc4b8acf6be7c006655a9d160f721309c85a9cf3925029c96c3

See more details on using hashes here.

File details

Details for the file belgie-0.32.0-cp312-abi3-manylinux_2_28_aarch64.whl.

File metadata

  • Download URL: belgie-0.32.0-cp312-abi3-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 64.5 MB
  • Tags: CPython 3.12+, manylinux: glibc 2.28+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for belgie-0.32.0-cp312-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ab766894f3ac1c0f5e9a342cf93bfc61a8fdffee536338a709f4b33f9ea2c329
MD5 606f3e0a6ab6d96ddf5d08e5706b4f20
BLAKE2b-256 885eb856f3e6fb5176e38b7e6cb46ad1a50e053bc2e75257d6e689a5d0d38582

See more details on using hashes here.

File details

Details for the file belgie-0.32.0-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: belgie-0.32.0-cp312-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 55.1 MB
  • Tags: CPython 3.12+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for belgie-0.32.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ac86392416a263d2de6b714c0605d3d2370ac52989aa1360d90fde37103095e4
MD5 7557fca578012f6bef0fa3701c92551d
BLAKE2b-256 b5eedcffddb577a8d0f41e23d3a610a13114c62ec65dbb7ce7d419060f697554

See more details on using hashes here.

File details

Details for the file belgie-0.32.0-cp312-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: belgie-0.32.0-cp312-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 57.1 MB
  • Tags: CPython 3.12+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for belgie-0.32.0-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cd8a8c0697045437f3c8eff70c9db35686bd27cd02989e5127b66addfdcc10f9
MD5 5e4f1414672df4f14f4a1d4839f4d0ab
BLAKE2b-256 12ae6464ca73925663c30013c3cad70edc6784d50432b07329ffadf632747159

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