Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

transcrypt
python
javascript
transpiler

What is Transcrypt?

Usman Younas

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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 www.python.org and download Python 3.9.

  • Step 2: Run the command python -m pip install transcrypt in the command prompt to install Transcrypt.

  • Step 3: Make a new folder called hello with the files hello.html and hello.py in it.

  • Step 4: Run the command python -m transcrypt -b -m -n hello.py from inside the new folder.

  • Step 5: Run the command python -m http.server from inside the new folder to start an HTTP server.

  • Step 6: Go to localhost:8000/hello.html in the browser to view the results.

The command would be python39 or python3 rather than python on Windows operating system. You may have to type python3.9 or python3 rather than python on Linux and macOS systems. To compile the test program on some systems, you can just type transcrypt -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>

RELATED TAGS

transcrypt
python
javascript
transpiler

CONTRIBUTOR

Usman Younas
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring