Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
PyPI

transpyle 0.8.0

pip install transpyle

Latest version

Released:

performance-oriented transpiler for Python

Verified details

These details have beenverified by PyPI
Maintainers
Avatar for mbdev from gravatar.commbdev

Unverified details

These details havenot been verified by PyPI
Project links
Meta
  • License: Apache Software License (Apache License 2.0)
  • Author:Mateusz Bysiek
  • Maintainer:Mateusz Bysiek
  • Tags compiler, just-in-time, source-to-source, transpilation, transpiler
  • Requires: Python >=3.5

Project description

Human-oriented and high-performing transpiler for Python.

package version from PyPIbuild status from Travis CIbuild status from AppVeyortest coverage from Codecovlicense

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 applicationin 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 languagesupported 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 betweenlanguages, is the extended Python AST.

Features

Using Python AST as the intermediate representation, enables the AST to be directly manipulated,and certain performance-oriented transformations can be applied. Current transpiler implementationaims at:

  • inlining selected calls

  • decorating selected loops with compiler-extension pragmas

More optimizations will be introduced in the future.

Some (if not all) of the above optimizations may have very limited (if not no) performance impactin Python, however when C, C++ or Fortran code is generated, the performance gains can bemuch greater.

Command-line interface

The command-line interface (CLI) of transpyle allows one to translate source code filesin supported languages.

API highlights

The API of transpyle allows using it to make your Python code faster.

The most notable part of the API is thetranspile decorator, which in it’s most basic formis not very different from Numba’sjit decorator.

importtranspyle@transpyle.transpile('Fortran')defmy_function(a:int,b:int)->int:returna+b

Additionally, you can use each of the modules of the transpiler individually, therefore transpylecan support any transformation sequence you are able to express:

importpathlibimporttranspylepath=pathlib.Path('my_script.py')code_reader=transpyle.CodeReader()code=code_reader.read_file(path)from_language=transpyle.Language.find('Python 3.6')to_language=transpyle.Language.find('Fortran 95')translator=transpyle.AutoTranslator(from_language,to_language)fortran_code=translator.translate(code,path)print(fortran_code)

As transpyle is under heavy development, the API might change significantly between versions.

Language support

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

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

C to Python AST

C-specific AST is created via pycparse, and some of elementary C syntax is transformed intoPython AST.

Python AST to C

Not implemented yet.

C++ to Python AST

Parsing declarations, but not definitions (i.e. function signature, not body). And only selectedsubset of basic types and basic syntax is supported.

Python AST to C++

Only very basic syntax is supported currently.

Cython to Python AST

Not implemented yet.

Python AST to Cython

Not implemented yet.

Fortran to Python AST

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

Python AST to Fortran

Currently, the Fortran unparser uses special attributefortran_metadata attachedto selected Python AST nodes, and therefore unparsing raw Python AST created directly from ordinaryPython file might not work as expected.

The above behaviour will change in the future.

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 or later.

Python libraries as specified inrequirements.txt.

Building and running tests additionally requires packages listed indev_requirements.txt.

Support for transpilation from/to specific language requires additional Python packagesspecified inextras_requirements.json, which can be installed using the pip extrasinstallation formulapip3installtranspyle[extras] where thoseextrascan 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, executepip3installtranspyle[all].Alternatively, to enable support for C++ and Fortran only, executepip3installtranspyle[cpp,fortran].

Additionally, full support for some languages requires the following software to be installed:

  • C++:

    • a modern C++ compiler – fully tested with GNU’sg++ versions 7 and 8and partially tested with LLVM’sclang++ version 7

    • SWIG (Simplified Wrapper and Interface Generator) – tested with version 3

  • Fortran:

    • a modern Fortran compiler – fully tested with GNU’sgfortran versions 7 and 8and partially tested with PGI’spgfortran version 2018

The core functionality of transpyle is platform-independent. However, as support of some languagesdepends on presence of additional software, some functionality might be limited/unavailableon selected platforms.

Transpyle is fully tested on Linux, and partially tested on OS X and Windows.

Installation

pip

pip3installtranspyle[all]

Docker image

There is a docker image prepared so that you can easily try the transpiler.

First, download and run the docker container (migth require sudo):

dockerpull"mbdevpl/transpyle"dockerrun-htransmachine-it"mbdevpl/transpyle"

By default, this will download latest more or less stable development build,if you wish to use a specific release, use"mbdevpl/transpyle:version" instead.

Then, in the container:

python3-mjupyternotebook--ip="$(hostname-i)"--port=8080

Open the shown link in your host’s web browser, navigate toexamples.ipynb,and start transpiling!

Project details

Verified details

These details have beenverified by PyPI
Maintainers
Avatar for mbdev from gravatar.commbdev

Unverified details

These details havenot been verified by PyPI
Project links
Meta
  • License: Apache Software License (Apache License 2.0)
  • Author:Mateusz Bysiek
  • Maintainer:Mateusz Bysiek
  • Tags compiler, just-in-time, source-to-source, transpilation, transpiler
  • Requires: Python >=3.5

Download files

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

Source Distribution

transpyle-0.8.0.tar.gz (118.5 kBview details)

UploadedSource

Built Distribution

Filter files by name, interpreter, ABI, and platform.

If you're not sure about the file name format, learn more aboutwheel file names.

Copy a direct link to the current filters

transpyle-0.8.0-py3-none-any.whl (110.6 kBview details)

UploadedPython 3

File details

Details for the filetranspyle-0.8.0.tar.gz.

File metadata

  • Download URL:transpyle-0.8.0.tar.gz
  • Upload date:
  • Size: 118.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for transpyle-0.8.0.tar.gz
AlgorithmHash digest
SHA25696abc649d5bc69405e09c1769a7e4f22e4ffe3ac11a7401b1d653454f953626a
MD55bb0d3c1083537618a0f86fe270630a3
BLAKE2b-256f65e76eff087b4fbf502aa42f924b51715691fa28c5633f9c8363141d79174df

See more details on using hashes here.

File details

Details for the filetranspyle-0.8.0-py3-none-any.whl.

File metadata

  • Download URL:transpyle-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 110.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for transpyle-0.8.0-py3-none-any.whl
AlgorithmHash digest
SHA25636f332b5c8ecbddf23fb78e0822f675db9bab11ea2abc12b405117953da4b270
MD509d1b366143a28b004e6b079ec2d968f
BLAKE2b-256a7a3dac511ec037acbf10c03a2f746d5e00c5b924e0d0e10dc1def353901405b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security SponsorDatadog MonitoringDepot Continuous IntegrationFastly CDNGoogle Download AnalyticsPingdom MonitoringSentry Error loggingStatusPage Status page

[8]ページ先頭

©2009-2025 Movatter.jp