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.33.0.tar.gz (636.6 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.33.0-cp312-abi3-win_amd64.whl (53.9 MB view details)

Uploaded CPython 3.12+Windows x86-64

belgie-0.33.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.33.0-cp312-abi3-manylinux_2_28_aarch64.whl (64.5 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.12+macOS 11.0+ ARM64

belgie-0.33.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.33.0.tar.gz.

File metadata

  • Download URL: belgie-0.33.0.tar.gz
  • Upload date:
  • Size: 636.6 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.33.0.tar.gz
Algorithm Hash digest
SHA256 a7099ce422746f83897efffab66cecf46801f23748dbb111a0f99d29981a911a
MD5 b8ebbdf29b8a5f98f06f119aa0c09ad8
BLAKE2b-256 cf2ddae6963433a341d75008099ad5f475836f0bb2b8f857281176a259d4d815

See more details on using hashes here.

File details

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

File metadata

  • Download URL: belgie-0.33.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.33.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 64d11c3abbf2a6323c713045b95f43b4e435d2414727794a5c7f7d82e70ee7ca
MD5 ab4fe4c89cb66e54ed57147a0a8943e5
BLAKE2b-256 64802ee27869242a8d278837fa4c67e27a44ed2ebd7b60376691d2b90e386d85

See more details on using hashes here.

File details

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

File metadata

  • Download URL: belgie-0.33.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.33.0-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bcc0a87c178e2107f114f6fee87d621e0b9755a6f8273e36766e9960f616d882
MD5 583b1cc02ffee008ad1ce0dd331ee9e5
BLAKE2b-256 42c441781baad902bd093e231dc043091df581162bb6cb83aa531799701c06fb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: belgie-0.33.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.33.0-cp312-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 dac72624554fd058e407c0b190a88accd4f0d4b188f88111e3eafe4ab62c5967
MD5 c099621afe41d030f07422f07eabced7
BLAKE2b-256 28bdbaa0eb061494863a73fe49788202fa247400a7e1b2d28615c66242864883

See more details on using hashes here.

File details

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

File metadata

  • Download URL: belgie-0.33.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.33.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2467c183f0d89be17dcc1373a34ca239a5a5ff07a84c86ac2fc094ce15fb61e6
MD5 e745e1c36bf02c33b8e707d1631d5469
BLAKE2b-256 181931d541da7d70d04dcfb8b24987968c14c1e60c6c5724c0c3e18505db4a9e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: belgie-0.33.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.33.0-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a5ebcbd0b608deac22ff0f1d5dcc955f38a4aea28ab9bd22db3e70d2e1fa77b2
MD5 acab82277f2c5781a211393b031cc5ee
BLAKE2b-256 1e2add6026b9ae0c97a73979ca872eebb7c080dd1afb422ba1baaccff7395237

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