# PythonJS **Repository Path**: liangdas/PythonJS ## Basic Information - **Project Name**: PythonJS - **Description**: No description available - **Primary Language**: Unknown - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-23 - **Last Updated**: 2024-06-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Introduction ------------ PythonJS is a transpiler written in Python that converts a python like language into fast JavaScript. It also includes experimental backends that translate to: Dart, Lua, CoffeeScript, and Go. [Syntax Documentation](https://github.com/PythonJS/PythonJS/blob/master/doc/syntax.md) Go backend ---------- The Go backend uses a fully typed subset of Python, mixed with extra syntax inspired by Golang to output Go programs that can be compiled to native executeables, or translated to JavaScript using GopherJS. [Syntax Documentation](https://github.com/PythonJS/PythonJS/blob/master/doc/go_syntax.md) Getting Started =============== PythonJS can be run with regular Python, or fully self-hosted within NodeJS using Empythoned. To get started, you have two options: 1. install NodeJS, python-js package, and write a build script. 2. or install Python2 and use translator.py from this repo directly. 1. Installing NodeJS Package ------------- You can quickly get started with the stable version of PythonJS by installing the NodeJS package, and writing a build script in javascript to compile your python scripts to javascript. (Python2.7 is not required) ``` npm install python-js ``` NodeJS Quick Example -------------- ``` var pythonjs = require('python-js'); var pycode = "a = []; a.append('hello'); a.append('world'); print(a)"; var jscode = pythonjs.translator.to_javascript( pycode ); eval( pythonjs.runtime.javascript + jscode ); ``` Example Projects ---------------- The example projects below, require the NodeJS python-js package. [https://github.com/PythonJS/pythonjs-demo-server-nodejs](https://github.com/PythonJS/pythonjs-demo-server-nodejs) [https://github.com/PythonJS/pypubjs](https://github.com/PythonJS/pypubjs) 2. translator.py -------------------------------------- If you want to run the latest version of the translator, you will need to install Python2.7 and git clone this repo. (the NodeJS package above is not required) Then, to translate your python script, directly run the `translator.py` script in the "pythonjs" directory. You can give it a list of python files to translate at once. It will output the translation to stdout. The default output type is JavaScript. An html file can also be used as input, python code inside a script tag: `