What is Transcrypt?
Definition
Transcrypt is a transpiler to compile a reasonably large Python code into compact, readable JavaScript. It takes the Python code that you write and converts it into a JavaScript file. That JS file can then be loaded into a web browser, and the code run.
Notably, no browser plug-in or large JavaScript runtime download is required to run the code. Also, the code is pre-compiled into JavaScript before it is downloaded to the browser, so application performance is not compromised.
Characteristics
It has the following characteristics:
-
It translates relatively large Python scripts into highly readable and easy to debug JavaScript code.
-
It is lightweight.
-
It offers the semantic essence of Python and the clean syntax that the language is famous for.
-
It works seamlessly with the JavaScript world of web-based libraries.
In two words: it’s lean and mean.
Installation required
Transcrypt has been tested under Windows, Linux, and OSX, with Chrome, Internet Explorer and Firefox. Follow the steps outlined below to get started:
-
Step 1: Go to
and download Python 3.9.Python official documentation https://www.python.org/ -
Step 2: Run the command
python -m pip install transcryptin the command prompt to install Transcrypt. -
Step 3: Make a new folder called
hellowith the fileshello.htmlandhello.pyin it. -
Step 4: Run the command
python -m transcrypt -b -m -n hello.pyfrom inside the new folder. -
Step 5: Run the command
python -m http.serverfrom inside the new folder to start an HTTP server. -
Step 6: Go to
localhost:8000/hello.htmlin the browser to view the results.
The command would be
python39orpython3rather thanpythonon Windows operating system. You may have to typepython3.9orpython3rather thanpythonon Linux and macOS systems. To compile the test program on some systems, you can just typetranscrypt -b -m -n hello.py.
Hello, solar system: A test application
We will test a hello, solar system application below. For the sake of simplicity, all the installations required are already performed. All you need to do is just click the “Run” button, and after that click the link given after “Your app can be found at”:
<script type="module">import * as hello from './__target__/hello.js'; window.hello = hello;</script> <h2>Hello demo</h2> <p> <div id = "greet">...</div> <button onclick="hello.solarSystem.greet ()">Click me repeatedly!</button> <p> <div id = "explain">...</div> <button onclick="hello.solarSystem.explain ()">And click me repeatedly too!</button>
Free Resources