HIPY is a Python interpreter written in Haskell. It aims to provide a lightweight and functional approach to executing Python code, leveraging Haskell's strong type system and purity to ensure correctness and maintainability.
- ✅ Parsing of Python source code
- ✅ Evaluation of Python expressions and statements
- ✅ Support for basic Python data types (integers, strings, booleans etc.)
- ✅ Support for complex Python data types (lists, dictionaries etc.)
- ✅ Control flow structures (if/else, while, loops)
- ✅ Helpful errors
- ✅ Function definitions and calls
- ✅ Python standard library
- Object Oriented Programming (class, this, etc.)
- Concurrency (async, await etc.)
HIPY will returns short descriptions for the errors it runs into but these do not catch everything due to not implementing certain features. You should therefore only use HIPY to run correct Python code where possible.
The Python standard library has been implemented with a focus on supporting functions that return primitive data types. This means that functions which either 1) return complex objects (e.g., numpy.matrix() creates a numpy.matrix object) or 2) modify variables in place without returning them (e.g., random.shuffle(x) updates x or os.abort()) are currently unsupported. While this limitation restricts the usage of certain libraries—most notably Pandas and NumPy—I’ve consciously chosen not to implement a linker and loader due to the complexity and scope involved. However, the implementation still supports a wide range of highly useful modules, such as random, math, os, time, and crypto, which are now available for use, providing significant functionality for many applications.
To build HIPY, you will need:
- GHC (Glasgow Haskell Compiler) >= 9.0.0
- Cabal for dependency management
git clone https://github.com/coloursplash/hipy.git
cd hipy
cabal build
cabal run . -- example.py
HIPY runs Python scripts passed as command-line arguments:
hipy script.py
Create a Python script:
# script.py
x = 10
y = 20
print(x + y) # Output: 30
Run it with:
hipy script.py
HIPY is released under the MIT License. See LICENSE for details.