Skip to main content

performance-oriented transpiler for Python

Project description

package version from PyPI build status from Travis CI test coverage from Codecov license

Human-oriented and high-performing transpiler for Python.

The main aim of transpyle is to let everyone who can code well enough in Python, benefit from modern high-performing computer hardware without need to reimplement their application in one of traditional efficient languages such as C or Fortran.

framework design

Framework consists of mainly the following kinds of modules:

  • parser

  • abstract syntax tree (AST) generalizer

  • unparser

  • compiler

  • binder

At least some of the modules are expected to be implemented for each language supported by the framework.

The modules are responsible for transforming the data between the following states:

  • language-specific code

  • language-specific AST

  • extended Python AST

  • compiled binary

  • Python interface for compiled binary

And thus:

  • parser transforms language-specific code into language-specific AST

  • AST generalizer transforms language-specific AST into extended Python AST

  • unparser transforms extended Python AST into language-specific code

  • compiler transforms language-specific code into compiled binary

  • binder transforms compiled binary into Python interface for compiled binary

The intermediate meeting point which effectively allows code to actually be transpiled between languages, is the extended Python AST.

language support

Transpyle intends to support selected subsets of: C++, Fortran, OpenCL, Python.

For each language pair and direction of translation, the set of supported features may differ.

C++ to Python AST

Not implemented yet.

Python AST to C++

Not implemented yet.

Fortran to Python AST

Fortran-specific AST is created via Open Fortran Parser, then that AST is translated into Python AST.

Python AST to Fortran

Currently, the Fortran unparser uses special attribute fortran_metadata attached to selected Python AST nodes, and therefore unparsing raw Python AST created directly from ordinary Python file might not work as expected.

OpenCL to Python AST

Not implemented yet.

Python AST to OpenCL

Not implemented yet.

Python to Python AST

Python 3.6 with whole-line comments outside expressions is fully supported. Presence of end-of-line comments or comments in expressions might result in errors.

Python AST to Python

Python 3.6 with whole-line comments outside expressions is fully supported. Presence of end-of-line comments or comments in expressions might result in errors.

requirements

Python >= 3.5.

Python libraries as specified in requirements.txt.

Building and running tests additionally requires packages listed in dev_requirements.txt.

Optional dependencies that enable support for transpilation from/to specific language are listed in extras_requirements.json and can be installed using the pip extras installation formula pip3 install transpyle[extras] where those extras can be one or more of the following:

  • All supported languages: all

  • C: c

  • C++: cpp

  • Cython: cython

  • Fortran: fortran

  • OpenCL: opencl

Therefore to enable support for all languages, execute pip3 install transpyle[all]. Alternatively, to enable support for C++ and Fortran only, execute pip3 install transpyle[cpp,fortran].

Project details


Download files

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

Source Distribution

transpyle-0.2.0.tar.gz (36.5 kB view hashes)

Uploaded Source

Built Distribution

transpyle-0.2.0-py3-none-any.whl (38.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page