Home

Awesome

Automatic Python → CoffeeScript (rough) conversion

This project is a rough experiment to see how easily/effectively we can automatically convert Python code into equivalent CoffeeScript code, inspired by the CoffeeScript for Python Programmers guide. The goal is to preserve the existing code's indentation style, comments, etc., but it's still very much a work-in-progress, is not feature complete, and may incorrectly convert some features, so please use with care. Hopefully, if you have some Python code to convert to CoffeeScript, this tool will provide a useful starting point, but you will almost certainly still need to do some manual fixes.

Usage

If your code is in Python 3, the following will convert filename.py to filename.coffee:

python2coffee.py filename.py

If your code is in Python 2, use the following instead:

python2coffee.py -p 2 filename.py

Example

test.py is a simple example of Python code reasonably supported by the converter, which results in test.coffee.

Features Supported So Far

Installation

This project is based on the excellent parso Python parser, which must first be installed. If you want to convert Python 2 files, you should install parso version 0.7.1:

pip3 install parso==0.7.1

Related Work

This is not the first attempt to automatically convert Python to CoffeeScript.