Skip to main content

Strongly typed Python to C++ transpiler.

Project description

buildstatus coverage

Mys

🚧 🚧 🚧 🚧 🚧 Under construction - DO NOT USE 🚧 🚧 🚧 🚧 🚧

Strongly typed Python to C++17 transpiler.

Project homepage: https://github.com/eerimoq/mys

🚧 🚧 🚧 🚧 🚧 Under construction - DO NOT USE 🚧 🚧 🚧 🚧 🚧

Installation

$ pip install mys

Tutorial

First of all, create a package and enter it. This package is used in the examples below.

$ mys new foo
$ cd foo

The package template creates a hello world appliaction.

def main():
    print('Hello, world!')

Build and run it with mys run.

$ mys run
Hello, world!

Now, replace the src/main.mys contents with the code below.

def foo(a: s32) -> Tuple[s32, str]:
     return 2 * a, 'Bar'

def main(args: List[str]):
    print(foo(s32(args[1])))

Build and run it.

$ mys run
(10, 'Bar')

Goals

  • Blazingly fast programs written in Python.

  • Small statically linked binary.

  • No GIL, mainly to allow threads to run in parallel. However, data races will occur when multiple threads uses a variable at the same time, which will likely make the program crash.

Limitations

  • All elements in a list must have the same type.

  • All items in a dict must have the same key and value types. Key and value may be different types.

  • All items in a set must have the same type.

  • Max 64 bits integers.

  • 32 and 64 bits floats.

  • No decorators.

  • No dynamic properties (getattr, setattr, eval, …).

  • No async.

Types

Using types defined in the standard library typing module where possible.

Variables may all be set to None if declared as Optional.

C++ auto is used in the generated code if the type is omitted.

Python Type

Mys Type

int

u8, u16, u32, u64

int

s8, s16, s32, s64

float

f32, f64

str

str

bytes

bytes

bytearray

bytearray

tuple

Tuple

list

List

dict

Dict

set

Set

Performance

ToDo.

Resources

https://github.com/python/mypy/blob/master/test-data/unit/pythoneval.test

https://medium.com/@konchunas/monkeytype-type-inference-for-transpiling-python-to-rust-64fa5a9eb966

http://blog.madhukaraphatak.com/functional-programming-in-c++/

https://github.com/Instagram/MonkeyType

Similar projects

https://github.com/konchunas/pyrs

https://github.com/lukasmartinelli/py14

https://github.com/shedskin/shedskin

https://github.com/pradyun/Py2C

https://github.com/mbdevpl/transpyle

http://numba.pydata.org/

https://github.com/Nuitka/Nuitka

https://github.com/QQuick/Transcrypt

https://github.com/pyjs/pyjs

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

mys-0.5.0.tar.gz (7.1 kB view details)

Uploaded Source

File details

Details for the file mys-0.5.0.tar.gz.

File metadata

  • Download URL: mys-0.5.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.0

File hashes

Hashes for mys-0.5.0.tar.gz
Algorithm Hash digest
SHA256 0159328025120122e897e145296413859e247b9a48bdde1bb306579e1f366ca2
MD5 140e1efa571abe9991b53ed0b5c0e223
BLAKE2b-256 9a53a22d6903e5593e016d11e02f28b9577d8f0e8f982a659514e4b8a3686e50

See more details on using hashes here.

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