Hi everyone π Iβm working on py2nim, a Python β Nim compiler that generates Nim code embedding CPython. The goal is to run Python libraries (Telethon, Matplotlib, asyncio code, etc.) unchanged inside a compiled Nim binary, instead of rewriting them. Iβd love feedback from Nim users on architecture and runtime design. note: Nim is just the conductor also Startup cost could be higher than pure Python It is a system where Python code becomes a compiled binary without losing Pythonβs ecosystem.
The current architecture is :
Original Python Libraries
So in reality it is to compile Python apps with Nim as runtime host What py2nim is NOT β Not a reimplementation of Python libraries in Nim β Not a Python-to-C transpiler β Not a replacement for CPython
py2nim embeds CPython and executes Python libraries as-is. This is just a simple project and I know the drawbacks of it it is for understanding compiler.
@ghazali
what is your github weblink?
is it:
https://github.com/Niminem/Py2Nim
or a fork from that?
The project You shared is a transpiler my project isn't a transpiler and theoretically it is not possible to build completely complete nim to py transpiler as Python dynamic nature prevent it, Also the project You shared has very few tests and also inactive since 5 years
Currently I am able test this tests : test_01_core.py test_02_oop.py test_03_logic.py test_04_functions.py test_05_closures.py test_06_decorators.py test_07_exceptions.py test_08_with.py test_09_async.py test_10_match.py test_11_stdlib_json.py test_12_stdlib_math.py test_13_recursion.py test_14_mro_complex.py test_15_magic_methods.py test_16_list_comp.py test_17_dict_comp.py test_18_set_comp.py test_19_generators.py test_20_scoping.py test_21_attribute_access.py test_22_type_checking.py test_23_import.py test_24_dynamic_exec.py test_25_complex_numbers.py test_26_bytes_bytearray.py test_27_sys_path.py
Nimpy is a great tool but it is slightly different from mine that Python is boss in nimpy but in my Project nim will be boss my project is small and aim to use python libs in nim. While nimpy I think helps in using nim in python as replacement of c or cpp extension.
Nah, Nimpy let's you use Python libraries from Nim and it's one of its major use cases.
@ghazali
Alltho your arrow-diagram is a good start to explain your architecture it needs further clarification. Further elaborate the objects between the arrows aswel as the arrows (relations) themselves.
Can one somehow embed python-code in Nim which then forms the interface?
We await you github-addition and presentation!
Apologies for confusion I don't mean nimpy can't use py libs I just mean nimpy use py host, I don't mention that nimpy can't use python libs I just said that this project tries to use py libs.
Also I am quite new to Nim(beginner level) and I personally haven't used nimpy if nimpy does similar works like I am trying to do (Nim owning the application lifecycle, deployment, and orchestration, with Python libraries used as embedded logic rather than as the host environment) then do let me know else it will not be fruitful to spend time on making something which is already made.
then do let me know else it will not be fruitful to spend time on making something which is already made.
Well it uses the Python dlls/lib.sos but you can ship them with your program. Maybe that part can be made more convenient so IMO you should spend your efforts with this mature solution.
I have used Nimpy to make Python module implemented in Nim (for considerably faster execution speed while being much MUCH easier than using Rust or C++ to implement python module) and you can also call Python library from Nim.
So far the main issues that I have with Nimpy is that it dynamicaly loads, which makes using the C API of numpy troublesome since it rely on static linking. But that's a super niche use case.
I've even done 'sandwich' architecture where I implemented a Python module in Nim which depended on other Python library.
Based on what You are trying to say I think I should freeze the development here, it looks like this my project is just a portfolio that too for compiler/tooling demands,
Already I am final year medical student and even need to study other subjects besides medicine. Thanks for Your response and explaining about nimpy. I hope nimpy is much more practical solution then, this is just a research or design.
@Clonk what You are referring itβs a design trade-off I think not needed in nimpy, also as a Python developer I won't recommend anyone to use Numpy in other languages as it is not for shiping with application. Yes this CPython embedding can solve this problem (tighter control) but just for this it will not be good to spend much time on it. As I already know less nim.