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.2.0.tar.gz (33.2 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.2.0-cp39-abi3-win_arm64.whl (8.1 MB view details)

Uploaded CPython 3.9+Windows ARM64

boabem-0.2.0-cp39-abi3-win_amd64.whl (8.4 MB view details)

Uploaded CPython 3.9+Windows x86-64

boabem-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl (8.5 MB view details)

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

boabem-0.2.0-cp39-abi3-musllinux_1_2_riscv64.whl (8.5 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ riscv64

boabem-0.2.0-cp39-abi3-musllinux_1_2_aarch64.whl (8.2 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

boabem-0.2.0-cp39-abi3-manylinux_2_31_riscv64.whl (8.5 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.31+ riscv64

boabem-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.4 MB view details)

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

boabem-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.0 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

boabem-0.2.0-cp39-abi3-macosx_11_0_arm64.whl (8.0 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

boabem-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for boabem-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9197972d9cf35597bb84b0f8efefa7d4e9ec29ddcab918b7d5cb87a03eef6817
MD5 17e7d9bf032f3259f1df7f38775e4f4d
BLAKE2b-256 760e4effbb1c48b6bc5c8a1bad9c5129c33955589d33e9b89d09f379e3d7498b

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.2.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.2.0-cp39-abi3-win_arm64.whl.

File metadata

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

File hashes

Hashes for boabem-0.2.0-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 cab5f27a65c22a2dc858778f5e302fc2f3fd4906c621184990d5741cc7bf57fb
MD5 8951e6704a9660ffe587d70fe3842b99
BLAKE2b-256 6bc8c50c19a8703f6e4e8178111d5836a0ae7a7c69562351bd095c134f32b0d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.2.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.2.0-cp39-abi3-win_amd64.whl.

File metadata

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

File hashes

Hashes for boabem-0.2.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e7bb3742f4232ecb9f847e678865c032a9b12312ff95e3602f56b539d4675e34
MD5 b7ccab066a64a18854f6bcb42d492f08
BLAKE2b-256 2d5b1a8d47fe84512010144ff5bb6f9c6b767a2494fd6bfd704c3621dd5363f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.2.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.2.0-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for boabem-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f1d71bcd9f9c423f7ac88d76ada68350b2da468e288b6e6e0ecf89000aa55095
MD5 29c37b67636c69bd483e6199d3a54c54
BLAKE2b-256 1a57d1d28c9ba2d4f7352cda6a42375b8203f076921e996b871ef6ae8ac8f38e

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.2.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.2.0-cp39-abi3-musllinux_1_2_riscv64.whl.

File metadata

File hashes

Hashes for boabem-0.2.0-cp39-abi3-musllinux_1_2_riscv64.whl
Algorithm Hash digest
SHA256 f3f9144ba92f670f0e8ed78c395adaeba944b9bba36a4533027e5bd87f23b033
MD5 d8b1543a52cf83dddbcddf75308e9331
BLAKE2b-256 e0760e3ac5121e6ea4fd12661cc98f8ab7afb364cd98969a8dd9f91db8b4f900

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.2.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.2.0-cp39-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for boabem-0.2.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f274786c5d6580459db95e5f1a6491a709a521b02c236a4d3b1960d965cad520
MD5 4e3055e151d7137c25a18d6377a5eeca
BLAKE2b-256 f7341a0f6e4f7286a75f45c7e391895145a72b1940d7de83f8ac270c83a1ccba

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.2.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.2.0-cp39-abi3-manylinux_2_31_riscv64.whl.

File metadata

File hashes

Hashes for boabem-0.2.0-cp39-abi3-manylinux_2_31_riscv64.whl
Algorithm Hash digest
SHA256 ec8ab01bc29bc9ad87d91cd319fcc7c9c2fa6cdc6c9e9351824c3eb46963139e
MD5 ff5b4b1109c683ef6eddc34e1efae578
BLAKE2b-256 223d6477767471cf20d576797d8247b927736364104045b5d580066bbad26849

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.2.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.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for boabem-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b414ef11999a2db5efec8b523ac507a36de13f42f5cd31c2a91cd6f82e663f2f
MD5 a4f69b4a2979e51996564f0756ebf1d2
BLAKE2b-256 30bd8b3f87cecbf54bff5d2d65c7610414e5930ed18fd9b8f8cd9d5b4659ea51

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.2.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.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for boabem-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f5dad4c2bee877189712685a883c19ead6a87075966a5c271ee400e6aa769a69
MD5 f10ddbab4284379ede4d3a6b79f38975
BLAKE2b-256 68eb838dbec07d49bd3d5805df1f08dd6e9f45e058c3f8dd4e49b4955e085a53

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.2.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.2.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for boabem-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3bb3bd50af79d5c206bc5f113f6caf96f7c21304b2870c37733ab5704fdcdbad
MD5 58a7fb85ea988a5ec659b90322140eef
BLAKE2b-256 74e11931e02d4e01bc8fc2ce3af5299a04a75ed5b4c063d3c55a9bb779e37969

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.2.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.2.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for boabem-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 624b9ddbeec7b481848416ef81725e3da7fb25d38a3ae88bf32a02402053bc72
MD5 ab73398647912c38d4b0c7067101660a
BLAKE2b-256 e0fa06e599f2ff9e75f3434e09919fbcb0ebacc28acc22b7954a3503accfe141

See more details on using hashes here.

Provenance

The following attestation bundles were made for boabem-0.2.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