Skip to content

3 Possible Solutions

Eric Snow edited this page Aug 28, 2018 · 3 revisions

Summary

The following solutions are discussed in more detail below.

  1. Implement Python in Javascript / TypeScript
  2. Transpile Existing Python Implementation to JS/TS
  3. Compile Existing Python Implementation to Webassembly
  4. Transpile Python Modules to JS/TS
  5. Compile Python Modules to WASM
  6. Use a Python-like Language
  7. Platform Emulation
  8. Interact With a Python "Server" Over a Socket/stdio

The easiest would probably be interacting with Python over the network/stdio. However, it's probably the least efficient.

The following "possible" solutions are not options for a variety of reasons, including cross-compatibility issues.

  • Ship native CPython
  • Support Python Natively in the Browser
  • CPython as a Node "Addon"

Possible Solutions

Implement Python in Javascript / TypeScript

Either do this from scratch, build on an existing project, or use an existing project.

See: Batavia

Transpile Existing Python Implementation to JS/TS

...

See: ???

Compile Existing Python Implementation to Webassembly

info on SO

See: Pyodide, MicroPython

Transpile Python Modules to JS/TS

Two approaches:

  • pre-convert & ship JS
  • ship (or GET) .py & convert in browser

See: Brython, Transcrypt

Compile Python Modules to WASM

See: ???

Use a Python-like Language

See: RapydScript

Platform Emulation

See: MicroPython

Interact With a Python "Server" Over a Socket/stdio

  • every web app ever
  • subprocesses

See: ???

Rejected Solutions

Ship Native CPython

Reason Rejected: not cross-platform; not supported in browser

Support Python Natively in the Browser

Reason Rejected: not feasible

Essentially, embed CPython in the browser binary. This is out of most of our hands. Realistically, it's not going to happen.

The easiest would probably be interacting with Python over the network/stdio. However, it's probably the least efficient.

CPython as a Node "Addon"

Reason Rejected: not cross-platform

In the Node.js world there's also the option of using an "addon" to expose Python. CPython has a rich embedding story. A Node module would be written in C which embeds the CPython runtime and wraps select parts in the format that Node understands. That would be compiled to a platform-specific shared object file from which Node could import the exported wrappers.