Registry / serialization / pscript

pscript

JSON →
library0.8.1pypypi✓ verified 85d ago

pscript is a Python-to-JavaScript compiler that allows developers to write Python code that runs directly in a JavaScript environment, such as a web browser or Node.js. It supports converting Python functions and basic data structures into their JavaScript equivalents, enabling seamless integration of Python logic into web applications. The current version is 0.8.1, with releases occurring periodically, often tied to Python version support updates.

pip install pscript
INSTALL
IMPORT
SIG · PSCRIPT
P
pscript
serializationpythonv0.8.1
Install
1.7s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.8.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.7s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

evaljs
from pscript import evaljs
from pscript import pyscript
evalpy
from pscript import evalpy
from pscript import pyscript
create_js_module
from pscript import create_js_module
from pscript import pyscript

This quickstart demonstrates how to define a Python function decorated with `@pyscript` to automatically generate its JavaScript equivalent. The generated JavaScript source code can then be embedded and executed in a JavaScript runtime environment.

from pscript import pyscript @pyscript def hello_js(name): # This Python code will be transpiled to JavaScript print(f'Hello, {name} from JavaScript!') return f'Greetings, {name}' # The generated JavaScript source code js_code = hello_js.source print(js_code) # Example of using the generated function in a browser context (conceptual) # You would typically inject js_code into an HTML <script> tag # For example, in browser console: # hello_js('World'); // Should print 'Hello, World from JavaScript!' to console
pscript --version
Debug
Known issues
gotchaOnly a subset of Python's standard library and built-in functions are supported for transpilation. Functions from modules like `os`, `sys`, or complex data structures are generally not translated.
fix
Focus on using basic Python types (strings, numbers, lists, dicts) and core operations. Avoid relying on Python-specific library functions that don't have direct JavaScript equivalents.
affects: All versions
gotchapscript generates JavaScript; it does not provide a JavaScript runtime in Python. Code relying on browser APIs (e.g., `document`, `window`) will only work when the generated JS is executed within a browser environment.
fix
Test the generated JavaScript in its target environment (e.g., a web browser's console or Node.js). Do not expect browser-specific APIs to be available when inspecting the generated Python object.
affects: All versions
gotchaPython's scoping rules, especially with closures and `nonlocal` variables, can behave subtly differently when transpiled to JavaScript. This can lead to unexpected variable capture.
fix
Simplify function structures and explicitly pass variables where possible. Test edge cases involving closures and mutable state carefully in the JavaScript output.
affects: All versions
Upgrade
Version history
0.8.1latest on PyPI · released Mar 31, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Resources
pscript — pip install pscript · libregistry