Python-JavaScript
JavaScript-style objects, methods and functions for Python 3.14+, using the
case-sensitive JavaScript namespace. An alpha compatibility layer with a
documented subset of ECMAScript behavior.
python -m pip install Python-JavaScript==0.2.0
from JavaScript import Array, JSON, Math, Object, String, undefined
people = JSON.parse('[{"name":"Ada","score":8},{"name":"Lin","score":6}]')
names = people.filter(lambda person: person.score >= 7).map(
lambda person: person.name.toUpperCase()
)
assert names.join(", ") == "ADA"
profile = Object({"name": String("Ada"), "scores": Array.of(8, 6)})
assert profile.missing is undefined
assert profile.scores.reduce(lambda total, score: total + score, 0) == 14
assert Math.round(2.5) == 3
assert JSON.stringify(profile) == '{"name":"Ada","scores":[8,6]}'
Explicit Object, Array, String and Number values expose JavaScript names
and behavior. Ordinary Python literals and operators retain Python semantics.
Objects and arrays compare by identity and remain truthy when empty. Use
Boolean(value) or truthy(value) when testing JavaScript truthiness of values
that might include Python containers.
Standalone packages
Installation includes two independently useful dependencies:
| Distribution | Import | Purpose |
|---|---|---|
JavaScript-Fetch-API>=0.2.0,<0.3.0 |
fetch_api |
Standard-library HTTP Fetch and Promise APIs |
JavaScript-JSON>=0.1.0,<0.2.0 |
JSON |
Python-friendly JSON parsing, serialization and dot traversal |
import asyncio
from fetch_api import fetch
from JavaScript import JSON
async def main():
response = await fetch("https://example.com/api/people")
if not response.ok:
raise RuntimeError(f"HTTP {response.status}")
people = JSON.parse(await response.text())
return people
# Run against your own JSON endpoint:
# people = asyncio.run(main())
JavaScript.fetch, Promise, Headers, Request, Response and FetchError
are the same objects exported by fetch_api. Fetch 0.2.0 changes the old
from javascript import fetch spelling to from fetch_api import fetch.
response.json() retains Fetch's standalone JSONObject/list result. Use
JavaScript.JSON.parse(await response.text()) for runtime Object/Array/String
values. Standalone import JSON preserves Python integers and containers;
from JavaScript import JSON uses binary64 numbers and JavaScript serialization
rules for its supported subset.
Supported surface
Core data objects and sparse arrays; UTF-16 String methods; Number predicates and prefix parsers; Boolean conversion; selected Math functions; JSON; and the standalone Fetch/Promise APIs. See the complete compatibility matrix for method lists and limits.
Python keywords require Array.from_, Object.is_, and Promise.finally_.
None represents null; undefined is a separate singleton. Array bracket
indices follow JavaScript rules: values[-1] is a named property, and
values.at(-1) accesses the last element. Array(3) creates three holes;
Array.of(3) creates one element containing 3.
Version 0.2.0 also includes a bounded Python-to-JavaScript compiler: a binding-aware front end, ES module emitter, local-module compiler, async profile and browser worker/host target. Python parses source at build time; generated modules and selected helpers execute on the client. The separate pocket-python interpreter will parse newly entered Python in the browser.
from JavaScript.emitter import compile_source
artifact = compile_source("def count(text):\n return len(text)", filename="counter.py")
# artifact.files contains emitted JavaScript, source map and provenance notice.
This alpha supports the explicit compiler language, not arbitrary Python dependencies or complete ECMAScript. Prototypes, descriptors, Date, RegExp, Map/Set, typed arrays and unlisted APIs remain future work. See 0.2.0 release notes, the implementation plan, issues and Project.
Development
uv sync
uv run python -m unittest discover -s tests -v
uv build
Node.js 24 runs the native ECMAScript differential fixture. That test is skipped when Node is absent locally; CI and release builds require it. Runtime code needs only Python and the two declared companions. Tests make no external network requests.
The compiler emitter produces deterministic ES modules for the approved single-module Python profile. The compiler APIs are included in the 0.2.0 distribution.
The explicit async compiler profile adds lazy coroutines, awaited Promise values, callbacks and context cancellation. The browser target adds named DOM controls, callbacks, native Fetch text and worker stop/restart.
Build the local text_metrics browser example
with uv run python examples/browser_text_metrics.py --output build/browser-text-metrics.
It uses our emitted modules and helpers in a worker; source parsing remains the
separate independent-interpreter milestone.
The compiler has a versioned CPython/Node/browser parity suite with typed results, source-map error checks and explicit unsupported boundaries.
Metadata
Release files for Python-JavaScript 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_javascript-0.2.0.tar.gz | 122.3 kB | With provenance | Details for python_javascript-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_javascript-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for python_javascript-0.2.0-py3-none-any.whl |
Total release size: 174.0 kB
Release files / python_javascript-0.2.0.tar.gz
| Download URL | python_javascript-0.2.0.tar.gz |
|---|---|
| Size | 122.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9ee9153a0c872234a8a6e099088f73af8d94e23dd140206339e8ff625ef108a6
|
|
BLAKE2b-256 checksum How to use checksums |
fa54bf53dc242de72312cd94249901d1c0735f02ce4bfe83392e2eb000966530
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.
Transparency logRelease files / python_javascript-0.2.0-py3-none-any.whl
| Download URL | python_javascript-0.2.0-py3-none-any.whl |
|---|---|
| Size | 51.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
488dcdd2de4c0bd3dd2a1f1430f5372bf78ac983c5da8b017c46bd36b124a8f7
|
|
BLAKE2b-256 checksum How to use checksums |
8fe0bf678624e3a1ec75eaa33ac403dafc27fe15dab22917d92e13cc5d1c6876
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.
Transparency logSecurity for Python-JavaScript 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for python_javascript-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.