You could recompile python bytecode, then you can keep python syntax. i.e. language frontend as it is. If you wanted great improvement, you may have to change libpython.

Look at pyastra and pymite projects, they do a subset of python and native execution.

Cython can be useful as half-way between python and compilation.

On the larger scale, look at PyPy, Psyco and Unladen Swallow.

Answer from Dima Tisnek on Stack Overflow
🌐
PyCon US
us.pycon.org › 2016 › schedule › presentation › 1995
Presentation: Wrestling Python into LLVM Intermediate Representation | PyCon 2016 in Portland, OR
------------------------ This is the heart of the talk. PyLLVM is a simple, easy to extend, one-pass static compiler that takes in the subset of Python most likely to be used by Tupleware.
🌐
LLVM
llvm.org › docs › tutorial › MyFirstLanguageFrontend › index.html
My First Language Frontend with LLVM Tutorial — LLVM 23.0.0git documentation
Chapter #7: Extending the Language: Mutable Variables - This chapter talks about adding user-defined local variables along with an assignment operator. This shows how easy it is to construct SSA form in LLVM: LLVM does not require your front-end to construct SSA form in order to use it!
Discussions

compiler construction - What thing I will need for creating a front end for Python based on LLVM architecture? - Stack Overflow
The answer of @katriealex (now deleted) does correctly point to the Unladen Swallow project, which bolted an LLVM backend on a Python front-end allowing to execute Python code through LLVM. Check it out ... You could recompile python bytecode, then you can keep python syntax. i.e. language frontend ... More on stackoverflow.com
🌐 stackoverflow.com
May 12, 2017
Mapping Python to LLVM
Yo this looks dope - I'm always excited for anything LLVM , and a python-like compiled languages has been something I've wanted for ages!! Will definitely be following this project closely, and will be looking forwards to how it develops! More on reddit.com
🌐 r/programming
14
80
January 9, 2023
Interest in Python frontend targetting PDL
After talking a bit with @jdd, we are starting to consider a Python-based system for defining ops and performing some relatively simple rewrites. It seems like this is a potential place to leverage PDL. Before diving in, we thought it would be prudent to ask the community: is anyone else interested ... More on discourse.llvm.org
🌐 discourse.llvm.org
0
1
May 11, 2021
Writing a toy language compiler in Python with LLVM—feasible?
It is quite possible. Consider lark or PLY for parsing, and you can emit llvmir directly in text, or use llvmlite (bindings to generate llvm) More on reddit.com
🌐 r/Compilers
18
14
June 2, 2025
🌐
GitHub
github.com › numba › llvmlite
GitHub - numba/llvmlite: A lightweight LLVM python binding for writing JIT compilers · GitHub
A pure Python implementation of the subset of the LLVM IR builder that we need for Numba.
Starred by 2.3K users
Forked by 363 users
Languages   Python 75.4% | C++ 18.9% | Shell 1.9% | CMake 1.7% | Batchfile 1.4% | LLVM 0.6% | C 0.1%
🌐
Python Developer's Guide
devguide.python.org › clang
Dynamic Analysis with Clang - Python Developer's Guide
August 14, 2021 - Clang is the C, C++ and Objective C front-end for the LLVM compiler. The front-end provides access to LLVM’s optimizer and code generator.
🌐
Reddit
reddit.com › r/programming › mapping python to llvm
r/programming on Reddit: Mapping Python to LLVM
January 9, 2023 - I'm yet to read the article, but ... (*) Edit: and that's where I'm wrong apparently, lol. Codon is both an LLVM compiler frontend and a Python language fork....
🌐
GitHub
github.com › topics › llvm-frontend
llvm-frontend · GitHub Topics · GitHub
language programming-language open-source programming compiler llvm programming-languages self-hosting compiler-designs one hacktoberfest compiler-optimization compiler-frontend compiler-tool llvm-compiler llvm-frontend compiler-backend compilers-design one-lang onelang ... LLVM (Low Level Virtual Machine) Guide. Learn all about the compiler infrastructure, which is designed for compile-time, link-time, run-time, and "idle-time" optimization of programs. Originally implemented for C/C++ , though, has a variety of front-ends, including Java, Python, etc.
Find elsewhere
🌐
Llvmpy
llvmpy.org
QuickStart — llvmpy
llvmpy is a Python wrapper around the llvm C++ library which allows simple access to compiler tools.
🌐
Medium
medium.com › @mbednarski › creating-a-programing-language-and-compiler-with-python-and-llvm-689c3b560982
Create a programing language and compiler using Python and LLVM | by Mateusz Bednarski | Medium
June 1, 2022 - But we will not implement everything from scratch. For the back-end, we will use LLVM Compiler Infrastructure. LLVM is very popular — some notable users are C/C++/Swift/Haskell/Julia and more. We will use lark for the lexer and parser — a python package dedicated to it.
🌐
LLVM Discussion Forums
discourse.llvm.org › mlir
Interest in Python frontend targetting PDL - MLIR - LLVM Discussion Forums
May 11, 2021 - After talking a bit with @jdd, we are starting to consider a Python-based system for defining ops and performing some relatively simple rewrites. It seems like this is a potential place to leverage PDL. Before diving in, we thought it would be prudent to ask the community: is anyone else interested in using Python as a frontend to PDL?
🌐
LLVM
llvm.org › docs › GettingStarted.html
Getting Started with the LLVM System — LLVM 23.0.0git documentation
Only needed if you want to run the automated test suite in the llvm/test directory, or if you plan to utilize any Python libraries, utilities, or bindings.
🌐
Python Developer's Guide
devguide.python.org › development-tools › clang
Dynamic analysis with Clang
November 29, 2025 - Clang is the C, C++ and Objective C front-end for the LLVM compiler. The front-end provides access to LLVM’s optimizer and code generator.
🌐
Quora
quora.com › What-is-the-relationship-between-Python-and-LLVM
What is the relationship between Python and LLVM? - Quora
Answer (1 of 3): Python is a programming language, usually implemented by an interpreter. The LLVM is a project that provides lots of useful components to build compilers. There have been projects in the past aiming to compile Python to make it run programs faster. Python, for many reasons, is no...
🌐
Reddit
reddit.com › r/compilers › writing a toy language compiler in python with llvm—feasible?
r/Compilers on Reddit: Writing a toy language compiler in Python with LLVM—feasible?
June 2, 2025 -

Hi everyone!

A while ago, I started writing a C compiler in C—for learning and fun. Now I'm thinking it could be fun to write a compiler for a toy language of my own as well.

The thing is, unlike C, the syntax and structure of this toy language will evolve as I go, so I want to be able to iterate quickly. Writing another compiler entirely in C might not be the best option for this kind of rapid experimentation.

So I'm considering writing the frontend in Python, and then using LLVM via its C API, called from Python, to handle code generation. My questions:

  • Does this sound feasible?

  • Has anyone here done something similar?

  • Are there better approaches or tools you’d recommend for experimenting with toy languages and compiling them down to native code?

Thanks in advance—curious to hear your thoughts and experiences!

🌐
LLVM
llvm.org
The LLVM Compiler Infrastructure Project
The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. Despite its name, LLVM has little to do with traditional virtual machines. The name "LLVM" itself is not an acronym; it is the full name of the project · LLVM began as a research project at the University ...
🌐
GitHub
github.com › SRavit1 › Python-Frontend-Compiler
GitHub - SRavit1/Python-Frontend-Compiler: Compiler to convert Python source code to assembly instructions for RISC-V architecture.
Compiler to convert Python source code to LLVM IR. The motivation behind this project is to create a frontend for a subset of the Python language. This would enable conversion of Python files to executable for any architecture supported by LLVM.
Author   SRavit1
🌐
Exaloop
exaloop.io › blog › mapping-python-to-llvm
Mapping Python to LLVM | Exaloop
Instead, we map each Python variable to a stack-allocated piece of memory: ... alloca is an LLVM IR instruction that allocates space on the current stack frame; alloca i64 allocates space for a 64-bit integer. Treating variables this way is standard practice when compiling to LLVM IR, and C/C++ compilers will do the same (e.g.
🌐
SlideShare
slideshare.net › mdevan › llvmpy-w
Client Challenge
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
LLVM
llvm.org › docs › WritingAnLLVMBackend.html
Writing an LLVM Backend — LLVM 23.0.0git documentation
In this new directory, create a CMakeLists.txt. It is easiest to copy a CMakeLists.txt of another target and modify it. It should at least contain the LLVM_TARGET_DEFINITIONS variable. The library can be named LLVMDummy (for example, see the MIPS target).
🌐
GitHub
github.com › eliben › pykaleidoscope
GitHub - eliben/pykaleidoscope: Implementation of the LLVM tutorial in Python using llvmlite · GitHub
This repository contains a chapter-by-chapter translation of the LLVM tutorial into Python, using the llvmlite package that exposes LLVM to Python.
Starred by 343 users
Forked by 37 users
Languages   Python 99.9% | Vim Script 0.1%