Skip to main content

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.1.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.

The longer-term goal is a binding-aware Python-to-JavaScript translator. v0.1.0 provides the runtime foundation; it does not translate source or execute JavaScript. Prototypes, descriptors, Date, RegExp, Map/Set, typed arrays, browser globals and other unlisted APIs remain future work. Development is tracked in the 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.

Metadata

Release files for Python-JavaScript 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Python-JavaScript 0.1.0
File Size Uploaded
python_javascript-0.1.0.tar.gz 26.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Python-JavaScript 0.1.0
File Interpreter ABI Platform
python_javascript-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 42.4 kB

Release files / python_javascript-0.1.0.tar.gz

Download URL python_javascript-0.1.0.tar.gz
Size 26.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1d3e72381e8dde4b010430acb8d8a19b16caa01f223686c80bd95725fd70b8bb
BLAKE2b-256 checksum
How to use checksums
2bae1c37c637dd7cbd75cfe528f9b25871624d0d9e5a930974bf4896c3fe70b9
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 16, 2026.

Transparency log

Release files / python_javascript-0.1.0-py3-none-any.whl

Download URL python_javascript-0.1.0-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3909129535faa257b58a99b39e40e86c0e88c547c32cb8c111ff9e1b8ebeb564
BLAKE2b-256 checksum
How to use checksums
361baeee3e22938ec9d62b0120a3b63a12b03c31c4d9e6aa9256acecf309a387
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 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page