transcrypt
Transpile Python code to JavaScript
TLDR
Initialize an unconfigured repository
List the currently encrypted files
Display the credentials of a configured repository
Initialize and decrypt a fresh clone of a configured repository
Rekey to change the encryption cipher or password
SYNOPSIS
transcrypt [options] <source_file.py>
PARAMETERS
-b, --build
Builds (transpiles) the source files.
-m, --minified
Generates minified JavaScript output.
-o <dir>, --output_dir <dir>
Specifies the directory for the generated JavaScript.
-n, --nomin
Disables the generation of minified JavaScript, ensuring readable output.
-r, --reset
Removes the __pycache__ and __target__ directories.
-c, --clean
Cleans the __pycache__ and __target__ directories before building.
-p, --project
Transpiles a complete project rather than just a single file.
--map
Generates source maps, aiding in debugging the transpiled JavaScript.
--standalone
Produces JavaScript suitable for direct inclusion in a web page.
--verbose
Displays detailed information and progress during transpilation.
--amd
Generates JavaScript optimized for Asynchronous Module Definition (AMD).
--cjs
Generates JavaScript optimized for CommonJS module systems.
--es6
Generates JavaScript optimized for ECMAScript 2015 (ES6) module systems.
--target <version>
Specifies the target Python version for compatibility (e.g., 3.9).
--polyglot
Enables polyglot mode, allowing inline JavaScript within Python code.
--help
Shows the help message.
--version
Shows program's version number.
DESCRIPTION
transcrypt is an open-source Python-to-JavaScript transpiler that enables developers to write client-side web applications using Python syntax. It converts Python source code into highly readable and optimized JavaScript code, allowing Python developers to leverage their existing skills for front-end development. transcrypt aims for a high degree of compatibility with Python 3.x, supporting many built-in functions, data types, and standard library modules.
It generates native JavaScript, avoiding heavy runtime dependencies, which contributes to smaller file sizes and faster execution in web browsers. Key features include source map generation for easier debugging, support for various module systems (like CommonJS and ES modules), and the ability to minify the output for production environments. It effectively bridges the gap between Python's powerful ecosystem and the ubiquitous nature of JavaScript in the browser.
CAVEATS
Python Subset: Not all Python features are supported; browser environment limitations apply (e.g., direct file I/O, multiprocessing, C extensions).
Debugging: While source maps help, debugging complex interactions in the transpiled JavaScript can still be challenging.
Performance: For highly performance-critical code, hand-written JavaScript or TypeScript might offer more fine-grained control.
External Libraries: Python libraries with C extensions or deep system integrations cannot be directly used; JavaScript equivalents or transcrypt-compatible versions are required.
INSTALLATION
transcrypt can typically be installed using Python's package manager: pip install transcrypt.
BASIC USAGE EXAMPLE
To transpile a simple Python file named hello.py into the __target__ directory: transcrypt hello.py.
PROJECT STRUCTURE
For larger projects, transcrypt can be run on a directory, automatically transpiling all Python files within it while maintaining relative paths in the output.
HISTORY
Transcrypt was initiated by Jacques de Hooge and first released in 2014. It emerged as a solution for Python developers to target the web browser without the overhead of Emscripten or larger runtime dependencies. Its development has continuously focused on generating clean, efficient, and readable JavaScript, aiming for maximum compatibility with Python 3.x and modern web standards, with ongoing additions of support for new Python features, module systems, and improved tooling like source maps.