← 输入框|github.com|刷新
Skip to content

Why not .py to .rs #6458

Closed
Closed

Description

@MominIqbal-1234

Summary

Hi RustPython team — thanks for your great work.

I have a question/idea: RustPython runs Python on a Rust-based interpreter. Have you ever considered supporting the reverse workflow — transpiling Python into Rust code, then compiling it with rustc?

Proposed workflow:

Input: Python source code

Step 1: Parse Python → build AST (RustPython already has a parser/AST)

Step 2: Convert Python AST → Rust AST / Rust source code

Step 3: Compile generated Rust with rustc to produce a native binary

Activity

  1. coderabbitai commented on Dec 19, 2025

    @coderabbitai
    Contributor

    📝 CodeRabbit Plan Mode

    Generate an implementation plan and prompts that you can use with your favorite coding agent.

    • Create Plan
    Examples

    🔗 Similar Issues

    Related Issues

    👤 Suggested Assignees

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord or schedule a call!

  2. fanninpm commented on Dec 19, 2025

    @fanninpm
    Contributor

    The problem of trans-piling Python code into Rust is likely beyond the scope of this project.

  3. youknowone commented on Dec 20, 2025

    @youknowone
    Member

    Well, still posible. It is similar to a mypyc approach.
    Rather than generating rust AST, we can pre-compile the python code to native using rustpython-jit at the moment.
    Then it will be more approachable, and be able to fallback to python code when it is not compilable well.

  4. MominIqbal-1234 commented on Dec 20, 2025

    @MominIqbal-1234
    Author

    I found this project: https://github.com/paiml/depyler. It mentions RustPython.
    i appreciate all developers and this effort @youknowone

    Image
  5. changed the title [-]Why not Python to Rust[/-] [+]Why not .py to .rs[/+] on Dec 22, 2025
  6. arihant2math commented on Jan 5, 2026

    @arihant2math
    Contributor

    Couldn't you use cython to generate a C file and then use a combination of pyo3 and c2rust to convert it? At that point it's simpler to just compile the C file though, as you gain no safety or anything from using the rust version.

  7. MominIqbal-1234 commented on Jan 6, 2026

    @MominIqbal-1234
    Author

    I checked Cython code and realized it is not true C, and it does not generate pure C code.
    If Cython could generate pure C code, that would be good. Then I could convert .py to .c, compile it fully natively, achieve true C-level speed, and then connect it back to Python. @arihant2math

  8. youknowone commented on Jan 6, 2026

    @youknowone
    Member

    I really don't want to start this kind of discussion here, so it is not a real question.

    What is true C code? If you have a code import logging; logging.info('hello'), you can turn it into C ast and compile it, but where the logging library come from? That's python library. And thats what Cython and mypyc do. You'd better check out what crystal lang achieved and limited.

    And the goal of RustPython is neither transpiler nor crystal. It is obvious.

  9. fanninpm commented on Jan 12, 2026

    @fanninpm
    Contributor

    What about Nuitka?1

    Footnotes

    1. Currently, Nuitka does not work on Arch Linux due to an incompatibility with Python 3.14. ↩

  10. arihant2math commented on Jan 12, 2026

    @arihant2math
    Contributor

    I'd suggest looking into why python cannot be compiled into C/Rust code. Python has fundamental differences that require it to have a runtime interpreter, meaning it can never actually become C code.

  11. locked and limited conversation to collaborators on Jan 12, 2026
  12. converted this issue into a discussion #6710 on Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions