Skip to main content

Python bindings for the Rust crate 'boa', an embeddable JavaScript engine

Project description

boabem

Boabem (/po.a.bɛm/, 'bo-ah-bem') is a Python binding for the Rust crate boa — an embeddable JavaScript engine.

Run small bits of JavaScript from Python, get back plain Python values, and keep state across evaluations.

Install

Python 3.9+ is required.

  • If a prebuilt wheel is available for your platform:
    • pip install boabem
  • Otherwise, build from source.

Quick start

from boabem import Context

ctx = Context()
ctx.eval("var x = 41")
print(ctx.eval("x + 1"))  # 42

print(ctx.eval("'A' + 'B'"))         # 'AB'
print(ctx.eval("[1,2,3].length"))    # 3
print(ctx.eval("JSON.stringify({a:1})"))  # '{"a":1}'

Load code from a file:

from pathlib import Path
from boabem import Context

ctx = Context()
result = ctx.eval_from_filepath(Path("script.js"))

API

  • boabem.Context
    • eval(source: str) -> Any
    • eval_from_bytes(source: str) -> Any (same behavior as eval)
    • eval_from_filepath(path: str | os.PathLike[str]) -> Any
  • boabem.PanicException
    • Exception class exposed for Rust panics (e.g., attempting to use a Context across threads).
  • boabem.Undefined
    • Sentinel type representing JavaScript undefined.
    • String representation: "Undefined".

State persists within a single Context instance between calls. Each Context is isolated from others.

Value mapping (JS -> Python)

  • undefined -> boabem.Undefined
  • null -> None
  • boolean -> bool
  • number -> float (NaN/Infinity preserved as float("nan")/float("inf"))
  • BigInt -> int
  • string -> str
  • Array -> list
  • Object -> dict

Notes:

  • Some JS values (e.g., Symbol) cannot be converted and will raise an error.
  • Each undefined you get back is a distinct Python object, but compares equal to another Undefined.

Object/Array conversion details

When converting composite values (JavaScript Objects and Arrays) to Python dict/list, elements are converted recursively with a few caveats:

  • BigInt inside Objects/Arrays is converted to Python int.
    • Examples: ({ a: 1n, 1: 2n, 2n: 3n }) -> {"a": 1, "1": 2, "2": 3} and [1, 2, 3n] -> [1, 2, 3].
  • NaN and ±Infinity inside Objects/Arrays are preserved as Python floats (float('nan') / float('inf')).
    • Examples: ({ a: NaN, b: Infinity }) -> {"a": nan, "b": inf} and [1, 2, NaN, Infinity] -> [1, 2, nan, inf].
  • undefined inside Objects/Arrays is converted to boabem.Undefined.

Additional notes:

  • JavaScript object property keys are coerced to strings during conversion; for example, a 2n property name becomes the Python key "2".

Note: Top-level primitives are still mapped as documented above (e.g., 10n -> int, NaN/Infinity -> float('nan')/float('inf')). The special rules here apply only to values nested within Objects/Arrays.

Threading and processes

Context is not thread-sendable or picklable:

  • Do not move or use a Context across threads (ThreadPoolExecutor will fail).
  • Do not send a Context to another process (cannot pickle).
  • Create and use a Context only in the thread where it was created.

If you try to use a Context across threads, you'll get a Rust panic surfaced as pyo3_runtime.PanicException (exposed as boabem.PanicException).

Errors

  • JavaScript exceptions (e.g., throw new Error('boom')) raise RuntimeError with the JS message.
  • Syntax/Reference/Type errors surface as RuntimeError messages (e.g., "SyntaxError", "ReferenceError").

License

Dual-licensed under MIT or Apache-2.0.

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

boabem-0.3.0.tar.gz (41.6 kB view details)

Uploaded Source

Built Distributions

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

boabem-0.3.0-cp39-abi3-win_arm64.whl (9.1 MB view details)

Uploaded CPython 3.9+Windows ARM64

boabem-0.3.0-cp39-abi3-win_amd64.whl (9.4 MB view details)

Uploaded CPython 3.9+Windows x86-64

boabem-0.3.0-cp39-abi3-musllinux_1_2_x86_64.whl (11.4 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ x86-64

boabem-0.3.0-cp39-abi3-musllinux_1_2_riscv64.whl (10.8 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ riscv64

boabem-0.3.0-cp39-abi3-musllinux_1_2_aarch64.whl (11.3 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

boabem-0.3.0-cp39-abi3-manylinux_2_31_riscv64.whl (10.7 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.31+ riscv64

boabem-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

boabem-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (11.1 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

boabem-0.3.0-cp39-abi3-macosx_11_0_arm64.whl (8.8 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

boabem-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl (9.1 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file boabem-0.3.0.tar.gz.

File metadata

  • Download URL: boabem-0.3.0.tar.gz
  • Upload date:
  • Size: 41.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for boabem-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c281a34d04a6ff77a2cf993beaa31fdf74cd36538c6da122da5d555dc7f06acc
MD5 4083f43171e1eba364ddef1436e42039
BLAKE2b-256 1832629e29354c1a7853def1a6d9338cbb441bc1d4b5bd027452ae44a2ae28f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.3.0.tar.gz:

Publisher: release.yml on Bing-su/boabem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file boabem-0.3.0-cp39-abi3-win_arm64.whl.

File metadata

  • Download URL: boabem-0.3.0-cp39-abi3-win_arm64.whl
  • Upload date:
  • Size: 9.1 MB
  • Tags: CPython 3.9+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for boabem-0.3.0-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 6c2e473071aa7708cf4e379629c26887d2792ef249f8fbb495df657904d2bd1b
MD5 d1ca688790d74e52d0aac093e4dffcd4
BLAKE2b-256 3c10c70a7d0007624c3e9bf6910a527fde255812c0ab3ec6419ee78b505c58fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.3.0-cp39-abi3-win_arm64.whl:

Publisher: release.yml on Bing-su/boabem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file boabem-0.3.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: boabem-0.3.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 9.4 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for boabem-0.3.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6bf019b41e43829fab71d81f2b3b06650b9b76f0a3ae7c8557dd6ec8947cd3e2
MD5 80a4212400bf5f75c4bf55b7ef445b5b
BLAKE2b-256 d91f6b23716cab612b23931880ccdf148b43706227c982459a7adcd775f29348

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.3.0-cp39-abi3-win_amd64.whl:

Publisher: release.yml on Bing-su/boabem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file boabem-0.3.0-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for boabem-0.3.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5cf9142ef28030cab31c9cfb8f0bc9520011a55051a45dd840f7505edce02f1c
MD5 a51ebf51654f70ac7596b4a914e4c7f8
BLAKE2b-256 574aa0274f5fb81597f474c06ed3374238006bbcdb4753f50029eb1da8665205

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.3.0-cp39-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on Bing-su/boabem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file boabem-0.3.0-cp39-abi3-musllinux_1_2_riscv64.whl.

File metadata

File hashes

Hashes for boabem-0.3.0-cp39-abi3-musllinux_1_2_riscv64.whl
Algorithm Hash digest
SHA256 44f83204fdd52dfa421c56f199ba416ece29e0b3f0171b96fe6c86fba5749fd3
MD5 e44e377e476b1f941b01953cacf9a360
BLAKE2b-256 c6074fa8fc2f9768dd5700b723de9e0179822564eac07d6278d8538fbef9bba1

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.3.0-cp39-abi3-musllinux_1_2_riscv64.whl:

Publisher: release.yml on Bing-su/boabem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file boabem-0.3.0-cp39-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for boabem-0.3.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 72bb8d652af201b2fd0b73f251250a1cac66e3f3fb99150626c72821a77b1ebd
MD5 504291db57b39bf352b95926d831f7e8
BLAKE2b-256 2637bc565aba20642c9db0f3733040e6d4b3e8d7858fe4fbe00570d74e763a4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.3.0-cp39-abi3-musllinux_1_2_aarch64.whl:

Publisher: release.yml on Bing-su/boabem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file boabem-0.3.0-cp39-abi3-manylinux_2_31_riscv64.whl.

File metadata

File hashes

Hashes for boabem-0.3.0-cp39-abi3-manylinux_2_31_riscv64.whl
Algorithm Hash digest
SHA256 534d9b5f3cde34971e9520819c97ed8f057873e3c56628f3b7688cb02b53bd4a
MD5 9dfc62110596d46f0cb7f374ff4cdb20
BLAKE2b-256 d86d1f608a5f5587daf475a1ebffdd99126acf91539e594f39b22ddc70f96670

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.3.0-cp39-abi3-manylinux_2_31_riscv64.whl:

Publisher: release.yml on Bing-su/boabem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file boabem-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for boabem-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 16d5ad4ecee95873423910e6a56593b1c0eccbd28697c66ede0c6591f673c927
MD5 165effa37754b7dcec3f8dc5513d63b6
BLAKE2b-256 dfdc34a588576e5a04f33363799f317c0c12587bbcfec80cbc8e1a436c178422

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Bing-su/boabem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file boabem-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for boabem-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5ca26b1a3493b4cc9b904d2f49265a1162ec425e6e86a77850aed26f82c9a5e5
MD5 f0048e392c23a5789a672f25b6035480
BLAKE2b-256 ea0cdfb4dbdbb96fa968f5ed86a040e78e3a4a073f0068eaef0c0a9ecafab223

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on Bing-su/boabem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file boabem-0.3.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for boabem-0.3.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0e77730508380367605ff432f0108c47ee72fc7697e10cd243f8bfa8deea5292
MD5 7a783eb9db252f1b44b07e5f6095e522
BLAKE2b-256 88aa1147f0e7817cfed84cd7e066d29b270c97769a0542a11277f24ea4f0117a

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.3.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on Bing-su/boabem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file boabem-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for boabem-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3c7b8ee83737f6bba92ded9cfb8f189edf4beb95766d7726ae3c0f27d8ff7006
MD5 fcf7c3cae8700f0522c6b14bf26c1caa
BLAKE2b-256 3c579a642967681721042903747aa7abb86b5e4c07a766fc70c9ab0ab6d3b31f

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on Bing-su/boabem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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