# Python Implemention in Julia

**URL:** <https://discourse.julialang.org/t/python-implemention-in-julia/79522>\
**Category:** Offtopic\
**Tags:** question\
**Created:** [April 15, 2022, 8:23am UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522 "2022-04-15T08:23:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [April 15, 2022, 8:23am UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/1 "2022-04-15T08:23:54Z")

</div>

Hi all 🙂

I know about CPython and IronPython and probably a couple more. These are all implementation of python. Is there also such a project in Julia. Using Julia for a python implemention?

Cheers

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [April 15, 2022, 8:27am UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/2 "2022-04-15T08:27:15Z")

</div>

There’s only one Julia implementation, and I’m not aware of any plans for others.

---

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [April 15, 2022, 8:39am UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/3 "2022-04-15T08:39:52Z")

</div>

Sorry, I didn’t mean another Julia implementation. But using Julia to implement python like dotnet is used for IronPython

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [April 15, 2022, 9:14am UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/4 "2022-04-15T09:14:00Z")

</div>

What are your plans of using here?

For example a good integration with VS Code (what I understand IronPython to be for .net at first glance) would be the plugin [Home · Julia in VS Code](https://www.julia-vscode.org/docs/latest/)).

Otherwise maybe it is better to have good interfaces instead of a re-implementatio? For example Python will not be reimplemented in Julia, since there are several packages that allow to call Python Code (same for C code being called from Julia),

For using Julia Code in Python I am sure there is something, but I am not that much using Python myself.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [April 15, 2022, 12:10pm UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/5 "2022-04-15T12:10:55Z")

</div>

> [@Impressium](#):
>
> Sorry, I didn’t mean another Julia implementation. But using Julia to implement python like dotnet is used for IronPython

This is a FAQ: [Why don’t you compile Matlab/Python/R/… code to Julia?](https://docs.julialang.org/en/v1/manual/faq/#Why-don't-you-compile-Matlab/Python/R/%E2%80%A6-code-to-Julia?)

---

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [April 15, 2022, 12:15pm UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/6 "2022-04-15T12:15:39Z")

</div>

I think this isn’t quite the same thing, although I agree it’s linked – I think the IronPython example is a bit more subtle, but I suspect the analogy the person is getting at is:

- C :: CPython
- Java :: Jython
- Julia :: ???

So not transpilation, but literally writing a Python interpreter in Julia.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [April 15, 2022, 12:22pm UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/7 "2022-04-15T12:22:06Z")

</div>

> [@johnmyleswhite](#):
>
> So not transpilation, but literally writing a Python interpreter in Julia.

That only seems worthwhile for languages like Java and C#/.NET that run in a [VM](https://en.wikipedia.org/wiki/Virtual_machine), in which case it’s more painful to call anything that doesn’t run in the same VM.

Julia compiles to the native architecture, not a VM, so it can directly call the native `libpython` from CPython (e.g. via [PyCall.jl](https://github.com/JuliaPy/PyCall.jl) or [PythonCall.jl](https://github.com/cjdoris/PythonCall.jl)), with no additional overhead. So there’s no real advantage to be gained from a Python interpreter written in Julia.

---

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [April 15, 2022, 12:35pm UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/8 "2022-04-15T12:35:04Z")

</div>

I agree the value is likely not there. I’m just trying to clarify what I believe is OP’s intended question.

---

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [April 15, 2022, 2:17pm UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/9 "2022-04-15T14:17:26Z")

</div>

Yeah like an interpreter of python written in pure Julia.

---

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [April 15, 2022, 2:40pm UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/10 "2022-04-15T14:40:08Z")

</div>

Let me try to summarize the thread and address the two themes brought up:

1. There is no interpreter for Python being written in Julia that is widely known about.
2. As @stevengj notes, the reason there is no interpreter for Python being written in Julia is that the value for it is unclear – writing an interpreter in Julia instead of C will not make Python faster and Julia is a “native” language that doesn’t provide privileged interactions with a VM the way that Jython does.

---

<div class="post-metadata">

**Author:** ![sswatson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sswatson/32/5135_2.png) [@sswatson](https://discourse.julialang.org/u/sswatson)\
**Post date:** [April 15, 2022, 2:44pm UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/11 "2022-04-15T14:44:24Z")

</div>

I agree with @stevengj’s take, but I’d point out one notable exception to the general rule that VM considerations drive the development of alternative Python implementations: PyPy, which is written in Python (sort of).

The motivation for PyPy is to offer a different set of tradeoffs. So you can imagine an implementation of Python in Julia if there were promising design choices that would be easier to explore with that approach. I can’t think of what they would be, but I also can’t rule it out.

Regardless, such a project would be a ton of work and would therefore need to offer a big payoff to be worth it.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [April 15, 2022, 2:51pm UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/12 "2022-04-15T14:51:57Z")

</div>

it’s already been done, it’s called:  
[https://numba.pydata.org/](https://numba.pydata.org/)

* * *

I’m only half-joking, because if you use Julia to write a python interpreter, it’s probably gonna compile to the same LLVM IR as Numba (optimally)

---

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [April 15, 2022, 7:27pm UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/13 "2022-04-15T19:27:27Z")

</div>

Didn’t though about the VM. Yes that makes sense

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [April 15, 2022, 7:37pm UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/14 "2022-04-15T19:37:44Z")

</div>

Having another implementation of Python can be useful, e.g.

> RustPython can be embedded into Rust programs to use Python as a scripting language for your application, or it can be compiled to WebAssembly in order to run Python in the browser.

> **[GitHub - RustPython/RustPython: A Python Interpreter written in Rust](https://github.com/RustPython/RustPython)**
>
> A Python Interpreter written in Rust. Contribute to RustPython/RustPython development by creating an account on GitHub.

I don’t think the payoff for Julia would be that great for having yet another way to call Python code since Julia itself can be used as a scripting language if needed.

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [April 15, 2022, 7:48pm UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/15 "2022-04-15T19:48:16Z")

</div>

> [@Impressium](#):
>
> Using Julia for a python implemention?

What do you think would be the magnitude of this project (lines of code or man years)?

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [April 15, 2022, 7:54pm UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/16 "2022-04-15T19:54:42Z")

</div>

RustPython has about 90kloc of Rust.

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [April 15, 2022, 7:59pm UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/17 "2022-04-15T19:59:03Z")

</div>

CPython seems to be more like somewhere between 500kloc and 1Mloc. Sounds like something is missing in RustPython.

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [April 15, 2022, 8:01pm UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/18 "2022-04-15T20:01:21Z")

</div>

CPython has 320kloc C (excluding comments), and Rust has better abstraction power than C so it seems plausible. Much of both implementations are written in Python, e.g. the (large) standard library, and can probably be shared.

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [April 15, 2022, 8:07pm UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/19 "2022-04-15T20:07:59Z")

</div>

> [@jar1](#):
>
> CPython has 320kloc C (excluding comments), and Rust has better abstraction power than C so it seems plausible.

Interesting. I didn’t find any reliable source for this. How did you find this out? Thanks!

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [April 15, 2022, 8:10pm UTC](https://discourse.julialang.org/t/python-implemention-in-julia/79522/20 "2022-04-15T20:10:32Z")

</div>

For counting lines I use [tokei](https://github.com/XAMPPRocky/tokei). For the stdlib, it’s in the [Lib](https://github.com/RustPython/RustPython/tree/main/Lib) directory of RustPython. Though it does look like a bunch of the stdlib is actually missing as you guessed. Compare to the cpython version [https://github.com/python/cpython/tree/main/Lib](https://github.com/python/cpython/tree/main/Lib)

Edit: actually the missing stuff is documented [What’s left](https://rustpython.github.io/pages/whats-left) (but as I said some of these are written in Python and can reuse code from CPython).

[Next page](https://discourse.julialang.org/t/python-implemention-in-julia/79522.md?page=2)
