Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Python to JavaScript transpiler, supporting multiple inheritance and generating lean, highly readable code

Project description

Recommended: PYCON.DE 2016, Munich, Sun. Oct. 30th, 12:30 Presentation by Gunther Klessinger. https://www.pymunich.com/

Transcrypt is a tool to precompile a fairly extensive subset of Python into compact, readable Javascript. It has the following characteristics:

  • Allows for classical OO programming with multiple inheritance using pure Python syntax, parsed by CPython’s native parser
  • Seamless integration with the universe of high-quality web-oriented JavaScript libraries, rather than the desktop-oriented Python ones
  • Hierarchical URL based module system to prevent name conflicts
  • Simple relation between Python source and generated JavaScript code for easy debugging
  • Multi-level sourcemaps and optional annotation of target code with source references
  • Compact downloads, kB’s rather than MB’s
  • Lightning fast JavaScript code, using memoization (call caching) to optionally bypass the prototype lookup chain
  • Operator overloading can be switched on and off locally to facilitate use for numerical math that’s both readable and efficient
Logo

Transcription once used to be manual labour

Documentation with code examples

Take a look at the documentation with code examples at the Transcrypt website: http://www.transcrypt.org .

Status of latest release

Release: Athens (PyPi v3.5.229, GitHub #12)

This release is mainly a bug fix release for Athens v3.5.222, which contains:

  • Improved support for the new, redesigned core of Numscrypt. While Numscrypt is still in its infancy, its scope has been widened from merely educational to general use for computations in the browser. A number of optimizations have been put in place, resulting in performance comparable to pure JS numerical libraries. The difference is that Transcrypt (or rather Python), with its facilities for operator overloading, allows a much more concise and readable notation of numerical algorithms. Plans are to gradually build out Numscrypt with more functionality.
  • Optional static type validation (experimental) using type annotations. Static type validation is activated simply by a command switch. Internally it relies on the mypy project. While this project is still in flux, the resulting productivity improvement is already impressive. Since static type validation is optional and cannot break your code, you can get 90% of the benefits from it rightnow without risk. Even only statically typing the interfaces between modules immediately pays off, especially when working with a team. Don’t believe it, try it!
  • Div. fixes.

Thanks to everyone who contributed!

Jacques de Hooge

What’s new in the latest commits

  • Fix for issue #140: commandline –help / -h switch broken
  • Enhancement for issue #128: metaclasses (only __new__ overridable) + test case / doc example
  • Enhancement for issue #136: dict.get not implemented
  • Fix for issue #134: %= operator translated incorrectly
  • Enhancement for issue #130: Add pragma to optionally handle % the JS way
  • Fix for issue #127: Can’t use key ‘keys’ in a dict
  • Enhancement issue #113: Use for … of pervasively for js6 + autotest
  • Fix for issue #125: strings not iterable (js6 only) + autotest
  • Release 12
  • Local classes now arbitrarily nestable, issue #120
  • Operator % has now Python rather than JS behaviour, issue #123 + autotest
  • Slicing bug fixed (stop beyond list end), issue #122 + autotest
Plotly demo

Plotly demo

  • Plotly.js demo added: lim (Numscrypt -> Maturity) Transcrypt + Numscrypt + Plotly = Live Science Demos in the Browser with native JS performance, all Plotly.js plot types are supported
  • __pragma__ (‘jskeys’/’nojskeys’) added make Plotly.js code match Plotly.js docs for convenience, locally voiding the need for quotes around dir keys
  • ‘Star us on GitHub’ command line option added
  • Fix for ‘unexpected indent’ when rebuilding
  • Fix for accidentally deleting current path from sys.path in some installations
  • Fix for ‘cannot import __symbols__’ bug when using -r with autotest.
  • Exception hierarchy improved, all Transcrypt runtime exceptions now derive from Exception
  • Non-standard attribute ‘stack’ added to Exception to obtain stack trace in de-facto JavaScript compatible way
  • Attempt to iterate over non-iterable now results in exception (only when using -e 6 switch) (see issue #112))
  • Iterating over TypedArrays and other non-list iterables fixed (only needed for when using -e 6 switch) (see issue #112)
  • Release 9
  • Truthyness of instances of custom classes fixed (see issue #110)
  • Source map generation bug fixed (see issue #104)
  • Optional static type validation using mypy (experimental)
  • Small doc improvements
  • Some more fixes for Numscrypt
  • Fix to enable Numscrypt development
  • *args now also can be used in calling pure javascript methods (see issue #102)
  • Pragma’s else and elif fixed for use in .py rather than .js files

Known restrictions

  • Only a very limited selection of standard libs have been chosen for inclusion in the Transcrypt distribution. Use or encapsulate the JavaScript ones, that’s part of the concept. Some additional standard libs may be ported in the future though.
  • A few methods of builtin types are currently left out, especially when they (almost) duplicate functionality of other methods. Also method decorators (as opposed to function decorators and class decorators) are not supported, with the exception of @classmethod. This results from a deliberate choice to keep Transcrypt lean and simple.
  • No eval and exec of Python code. This is again part of the concept. Transcrypt code is compiled, optimized and minified in advance to warant fast page loads. In this respect its design goal is fundamentally different from tools that compile on the fly in the browser. Transcrypt is targeted towards building professional, extensive, real world web applications that load and run as fast as their JavaScript counterparts, but offers Pythonically clean, modular structure and maintainability.
  • No threading of any kind. Will probably stay that way as long as JavaScript doesn’t properly support that.

Known bugs

None

Readability

As can be seen below, there’s a simple parallel between the Python and the JavaScript code. So it should be easy to debug. Also, code can be tested from the command prompt using stubs.

Screenshot of Python versus JavaScript code

Classic OO with multiple inheritance in JavaScript

Other packages you might like

Licence

Copyright 2014, 2015, 2016 Jacques de Hooge, GEATEC engineering, www.geatec.com

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Project details


Release history Release notifications

History Node

3.6.101

History Node

3.6.100

History Node

3.6.98

History Node

3.6.97

History Node

3.6.96

History Node

3.6.95

History Node

3.6.94

History Node

3.6.93

History Node

3.6.92

History Node

3.6.91

History Node

3.6.90

History Node

3.6.89

History Node

3.6.88

History Node

3.6.87

History Node

3.6.86

History Node

3.6.85

History Node

3.6.84

History Node

3.6.83

History Node

3.6.82

History Node

3.6.80

History Node

3.6.70

History Node

3.6.69

History Node

3.6.68

History Node

3.6.67

History Node

3.6.66

History Node

3.6.65

History Node

3.6.64

History Node

3.6.63

History Node

3.6.62

History Node

3.6.61

History Node

3.6.60

History Node

3.6.59

History Node

3.6.58

History Node

3.6.57

History Node

3.6.56

History Node

3.6.55

History Node

3.6.54

History Node

3.6.53

History Node

3.6.52

History Node

3.6.51

History Node

3.6.50

History Node

3.6.49

History Node

3.6.47

History Node

3.6.46

History Node

3.6.45

History Node

3.6.44

History Node

3.6.43

History Node

3.6.42

History Node

3.6.41

History Node

3.6.40

History Node

3.6.39

History Node

3.6.38

History Node

3.6.37

History Node

3.6.36

History Node

3.6.35

History Node

3.6.34

History Node

3.6.33

History Node

3.6.32

History Node

3.6.31

History Node

3.6.30

History Node

3.6.29

History Node

3.6.28

History Node

3.6.27

History Node

3.6.26

History Node

3.6.25

History Node

3.6.24

History Node

3.6.22

History Node

3.6.21

History Node

3.6.20

History Node

3.6.19

History Node

3.6.18

History Node

3.6.17

History Node

3.6.16

History Node

3.6.15

History Node

3.6.14

History Node

3.6.13

History Node

3.6.12

History Node

3.6.11

History Node

3.6.10

History Node

3.6.9

History Node

3.6.8

History Node

3.6.7

History Node

3.6.6

History Node

3.6.5

History Node

3.6.4

History Node

3.6.3

History Node

3.6.1

History Node

3.6.0

History Node

3.5.238

History Node

3.5.237

History Node

3.5.236

History Node

3.5.235

This version
History Node

3.5.234

History Node

3.5.233

History Node

3.5.232

History Node

3.5.231

History Node

3.5.230

History Node

3.5.229

History Node

3.5.227

History Node

3.5.226

History Node

3.5.225

History Node

3.5.224

History Node

3.5.223

History Node

3.5.222

History Node

3.5.221

History Node

3.5.220

History Node

3.5.219

History Node

3.5.218

History Node

3.5.217

History Node

3.5.216

History Node

3.5.215

History Node

3.5.213

History Node

3.5.207

History Node

3.5.206

History Node

3.5.205

History Node

3.5.204

History Node

3.5.203

History Node

3.5.202

History Node

3.5.201

History Node

3.5.200

History Node

3.5.199

History Node

3.5.198

History Node

3.5.197

History Node

3.5.196

History Node

3.5.194

History Node

3.5.193

History Node

3.5.192

History Node

3.5.191

History Node

3.5.189

History Node

3.5.188

History Node

3.5.187

History Node

3.5.186

History Node

3.5.185

History Node

3.5.184

History Node

3.5.183

History Node

3.5.182

History Node

3.5.181

History Node

3.5.178

History Node

3.5.177

History Node

3.5.176

History Node

3.5.175

History Node

3.5.174

History Node

3.5.173

History Node

3.5.172

History Node

3.5.171

History Node

3.5.170

History Node

3.5.169

History Node

3.5.168

History Node

3.5.167

History Node

3.5.166

History Node

3.5.165

History Node

3.5.164

History Node

3.5.162

History Node

3.5.161

History Node

3.5.160

History Node

3.5.159

History Node

3.5.158

History Node

3.5.157

History Node

3.5.156

History Node

3.5.155

History Node

3.5.151

History Node

3.5.150

History Node

3.5.149

History Node

3.5.148

History Node

3.5.146

History Node

3.5.145

History Node

3.5.144

History Node

3.5.143

History Node

3.5.142

History Node

3.5.141

History Node

3.5.140

History Node

3.5.139

History Node

3.5.138

History Node

3.5.137

History Node

3.5.136

History Node

3.5.135

History Node

3.5.134

History Node

3.5.133

History Node

3.5.132

History Node

3.5.131

History Node

3.5.130

History Node

3.5.129

History Node

3.5.128

History Node

3.5.127

History Node

3.5.126

History Node

3.5.125

History Node

3.5.124

History Node

3.5.123

History Node

3.5.122

History Node

3.5.120

History Node

3.5.118

History Node

3.5.117

History Node

3.5.116

History Node

3.5.115

History Node

3.5.114

History Node

3.5.113

History Node

3.5.112

History Node

3.5.111

History Node

3.5.110

History Node

3.5.109

History Node

3.5.106

History Node

3.5.105

History Node

3.5.104

History Node

3.5.103

History Node

3.5.102

History Node

3.5.101

History Node

3.5.97

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
Transcrypt-3.5.234.zip (15.6 MB) Copy SHA256 hash SHA256 Source None Oct 29, 2016

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page