Skip to main content

A minimal, secure javascript runtime for python

Project description

belgie

A minimal, secure JavaScript runtime for Python.

Examples

  • simple: Async Runtime with a TypeScript script loaded from disk.
  • jsr-deps: inline JSR dependency installation through Environment.
  • environment: sync and async Environment package setup.
  • commands: npm package binaries run through Runtime and Command.

Runtime Environments

Use Environment for JavaScript dependencies that should remain isolated from the current Python project. Entering an environment creates temporary Deno config/cache state; call install() on the active sync or async environment to resolve and cache those dependencies explicitly:

from belgie import Environment, Runtime, Script

script = Script(
    """
import { join } from "std_path";

export default function run() {
  return join.name;
}
"""
)

with Environment({"std_path": "jsr:@std/path@^1"}) as env:
    env.install()
    with Runtime(env=env) as runtime:
        assert runtime(script)() == "join"

Async callers can use the matching async methods:

async with Environment({"std_path": "jsr:@std/path@^1"}) as env:
    await env.install()
    async with Runtime(env=env) as runtime:
        assert await runtime(script)() == "join"

The temporary config, lockfile, and Deno cache are removed after the environment exits and any runtimes that were already using it have closed.

Package Operations

Environment package operations are explicit:

  • env.lock(lockfile=None) / await env.lock(...) resolves dependencies and writes the environment lockfile, optionally copying it to a supplied path.
  • env.install() / await env.install() resolves dependencies and installs cache state.
  • env.update(packages=None, latest=False, lockfile_only=False) / await env.update(...) updates dependency specifiers in the environment's synthetic Deno config.

The package mapping key is the JavaScript import alias. Values are either a full npm: / jsr: specifier or an npm version requirement:

Environment(
    {
        "react": "^19",
        "std_path": "jsr:@std/path@^1",
        "pkg_json": "npm:is-number@7.0.0/package.json",
    }
)

A supplied lockfile= is treated as frozen input. install() installs from it, and update() rejects frozen-lockfile environments.

Runtime Roots

Plain Runtime() supports dependency-free inline and file scripts and snapshots the process working directory when it is constructed.

Use Runtime.from_folder(path) only when scripts need a specific root for relative imports:

from belgie import Runtime, Script

script = Script('import { value } from "./value.ts"; export default () => value;')

with Runtime.from_folder("frontend") as runtime:
    result = runtime(script)()

Runtime.from_folder() does not read pyproject.toml, install packages, or manage lockfiles.

Commands

Command resolves npm package binaries from an active dependency environment. The command name may be a dependency alias such as "vite" or an explicit npm specifier. Arguments are forwarded directly without shell parsing, and commands inherit the current process stdio.

from belgie import Command, Environment, Runtime

async with Environment({"vite": "^6"}) as env:
    await env.install()
    async with Runtime(env=env) as runtime:
        await runtime(Command("vite"))("--version")

Relative command working directories resolve from the environment root. Command environments overlay the process environment for that execution. A nonzero exit raises BelgieRuntimeError; successful commands return None.

Async commands run until completion and can be cancelled with asyncio.create_task(). Leaving the runtime context terminates any commands or script invocations that are still active.

Commands are trusted project tooling and execute with unrestricted Deno permissions. Shell pipelines, redirection, arbitrary PATH commands, and output capture are not supported.

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.22.0.tar.gz (126.5 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.22.0-cp312-abi3-win_amd64.whl (50.9 MB view details)

Uploaded CPython 3.12+Windows x86-64

belgie-0.22.0-cp312-abi3-manylinux_2_28_x86_64.whl (58.3 MB view details)

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

belgie-0.22.0-cp312-abi3-manylinux_2_28_aarch64.whl (60.0 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ ARM64

belgie-0.22.0-cp312-abi3-macosx_11_0_arm64.whl (52.9 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

belgie-0.22.0-cp312-abi3-macosx_10_12_x86_64.whl (54.9 MB view details)

Uploaded CPython 3.12+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: belgie-0.22.0.tar.gz
  • Upload date:
  • Size: 126.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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.22.0.tar.gz
Algorithm Hash digest
SHA256 c1528aa872cd3710a0a7ebfd15bde2a2405d1a6072d44623b8b43b55077df04f
MD5 2311eaff092a059d79ed8f4d01cf617f
BLAKE2b-256 4412e50ecd8834deb91f728fdcb5071f29ad6e0494993ff62e86742639767b63

See more details on using hashes here.

File details

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

File metadata

  • Download URL: belgie-0.22.0-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 50.9 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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.22.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f1e4a5aeb4ede4dcc90602e79d57dfc4c31534adb006fa0ba58bead94f25d70a
MD5 c76e4049b6c77a43d73789cf3e1c0b92
BLAKE2b-256 cafebf950dd66eb4c7d2b2a995e45001f8f877fc5b078f6827b9a46f465ed0f6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: belgie-0.22.0-cp312-abi3-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 58.3 MB
  • Tags: CPython 3.12+, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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.22.0-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dc49f774f35530ff5991e4a6140c053116f98ad7a55aa72a79f10e6c7b874235
MD5 e6f14e097932733af1541cdb76963fa9
BLAKE2b-256 18cc65247c17c0e61c769f64ddcfb01046b3a161bee7947c6ab7ea84ba6b43c5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: belgie-0.22.0-cp312-abi3-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 60.0 MB
  • Tags: CPython 3.12+, manylinux: glibc 2.28+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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.22.0-cp312-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c126cec5d34b057d1cd2efd70c2cce68f1eeee48141a2c82a223ba3b83fcb05c
MD5 31bdf68709b2de01e0f90671cf0af4ad
BLAKE2b-256 2f038e02c9a130da97673e3df1560dd3b9735da396a349090516125c00626458

See more details on using hashes here.

File details

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

File metadata

  • Download URL: belgie-0.22.0-cp312-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 52.9 MB
  • Tags: CPython 3.12+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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.22.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 55a4521cfd4f19e6cf579e692b5df81d6a3a35f0c925484d68c606bd2a1e0505
MD5 99207e72e2c0371fc25716d5479bf51d
BLAKE2b-256 96fb014e5d027943eabc99ce800b5fe01a97e4a83f4bbdb189006a0a0f655555

See more details on using hashes here.

File details

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

File metadata

  • Download URL: belgie-0.22.0-cp312-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 54.9 MB
  • Tags: CPython 3.12+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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.22.0-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9d6a4ab245454786a2d75bbe4a722bd5f5d7a0b99398ee2151c921b1d252ca92
MD5 36cc7fb5260e362b76d5f4520009376f
BLAKE2b-256 37008f4f821b849e3d6c073346d39843188866ab904330c6d91c3fe5ce5bf5bc

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