Registry / serialization / pscript

pscript

JSON →
library0.8.1pypypi✓ verified 33d 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.

serializationweb-framework
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

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

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 footguns
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.
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.
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.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources