HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
yglukhov
nimpy
Nim2018–2026
yglukhov / nimpy

nimpy

Nim - Python bridge

25Distinct people
34Mentions
0Explicit recommenders
1.6KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

Nim - Python bridge

GitHub

Where it is used

No documented product use was verified in the last source check.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 9–Nov 16 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/16/2026, 12:56:33 AM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year34 dated mentions

Observed mentions: 2018-09-22 12:19:57 UTC to 2026-10-13 15:50:41 UTC.

024682018-01-01 00:00:00 UTC to 2019-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments20182019-01-01 00:00:00 UTC to 2020-01-01 00:00:00 UTC (exclusive): 3 mentions; 0 submissions, 3 comments2020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 4 mentions; 0 submissions, 4 comments2021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 6 mentions; 1 submissions, 5 comments2022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 8 mentions; 0 submissions, 8 comments20222023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 6 mentions; 0 submissions, 6 comments2024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2026-01-01 00:00:00 UTC to 2027-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments. Incomplete calendar period.2026*

* An incomplete calendar period is marked with an outlined bar. Its count is not directly comparable with a full period.

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20182018-01-01 00:00:00 UTC2019-01-01 00:00:00 UTC202
20192019-01-01 00:00:00 UTC2020-01-01 00:00:00 UTC303
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC404
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC615
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC808
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC606
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC202
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC202
2026 (partial)2026-01-01 00:00:00 UTC2027-01-01 00:00:00 UTC101

From the project README

An excerpt from the repository, fetched Nov 13, 2026.

Read the project’s introduction
nimpy Native language integration with Python has never been easier! Implementing a Python Module in Nim # mymodule.nim - file name should match the module name you're going to import from python import nimpy proc greet(name: string): string {.exportpy.} = return "Hello, " & name & "!" # Compile on Windows: nim c --app:lib --out:mymodule.pyd --threads:on --tlsEmulation:off --passL:-static mymodule # Compile on everything else: nim c --app:lib --out:mymodule.so --threads:on mymodule # test.py import mymodule assert mymodule.greet("world") == "Hello, world!" assert mymodule.greet(name="world") == "Hello, world!" Calling Python From Nim import nimpy let os = pyImport("os") echo "Current dir is: ", os.getcwd().to(string) # sum(range(1, 5)) let py = pyBuiltinsModule() let s = py.sum(py.range(0, 5)).to(int) assert s == 10 Note: here nimpy relies on your local python installation. Importing Nim Extensions Directly For a convenient way to import your Nim extension modules directly, you can use Nimporter. Misc The library is designed with ABI compatibility in mind. That is the compiled module doesn't depend on particular Python version, it should properly work with any. The C API symbols are loaded in runtime from whichever process has launched your module. Troubleshooting, Q&A Importing the compiled module from Python fails If you're getting ImportError: dynamic module does not define module export function ... make sure that the module you're importing from Python has exactly the same name as the nim file which the module is implemented in. Nimpy fails to find (proper) libpython The most reliable way to find libpython is find_libpython python package: pip3 install find_libpython python3 -c 'import find_libpython; print(find_libpython.find_libpython())' Then you can specify path to libpython using nimpy.py_lib.pyInitLibPath. Tracking issue: #171. Nim strings are converted to Python bytes instead of string nimpy converts Nim strings to Python strings usually, but since Nim strings are encoding agnostic and may contain invalid utf8 sequences, nimpy will fallback to Python bytes in such cases. Is there any numpy compatibility? nimpy allows manipulating numpy objects just how you would do it in Python, however it is not much more efficient. scinim offers API for performance critical numpy interop, and it is advised to consider it first. Nimpy also exposes lower level Buffer protocol, see raw_buffers.nim. tpyfromnim.nim contains a very basic test for this. Examples to use raw_buffers with numpy Does nim default garbage collector (GC) and ARC/ORC work? Yes. nimpy internally does everything needed to run the GC properly (keeps the stack bottom actual, and appropriate nim references alive), and doesn't introduce any special rules on top. So the GC question boils down to proper GC usage in nim shared libraries, you'd better lookup elsewhere. The following guidelines are by no means comprehensive, but should be enough for the quick start: If it's known there will be only one nimpy module in the process, you should be fine. If there is more than one nimpy module, it is recommended to move nim runtime out to a separate shared library. However it might not be needed if nim references are known to never travel between nim shared libraries. If you hit any GC problems with nimpy, whether you followed these guidelines or not, please report them to nimpy tracker :) Windows, threads and MinGW When compiling with --threads:on Nim will imply --tlsEmulation:on (Windows only) which prevents Nim runtime from initing properly when being called from a foreign thread (which is always the case in case of Python module). Adding --tlsEmulation:off when using MinGW toolchain (Nim's default on Windows) will introduce a dependency on libgcc_s_seh-*.dll, that newer python versions are often unable to find. One way to overcome this is to link with libgcc statically, by passing -static to linker, or --passL:-static to Nim. Exporting Nim types as Python classes Warning! This is experimental. An exported type should be a ref object and inherit PyNimObjectExperimental directly or indirectly. The type will only be exported if at least one exported "method" is defined. A proc will be exported as python type method only if it's first argument is of the corresponding type and is called self. If the first argument is not called self, the proc will exported as a global module function. If you define functions that looks like initTestType, destroyTestType, $, they can be exported as __init__ and __repr__ if the requirements are met. # mymodule.nim type TestType = ref object of PyNimObjectExperimental myField: string proc setMyField(self: TestType, value: string) {.exportpy.} = self.myField = value proc getMyField(self: TestType): string {.exportpy.} = self.myField # test.py import mymodule tt = mymodule.TestType() tt.setMyField("Hello") assert(tt.getMyField() == "Hello") Future directions High level buffer API Stargazers over time
Read the full README on GitHub

What Hacker News says

4 sources
> FFI: Can nim use a C++ class and vtables? D does it all the time, nearly every language proclaims to have the best C++ interop but only D seems to be actually able to do it. Templates, classes, structs, and more all work. Well, it depends on how you define "best". Beyond an ABI, FFI is obviously a function of the implementation rather than the language per-se. The main Nim implementation can use C++ as a backend language, and when it does, it can use any C++ construct very easily by way of the .emit and .importcpp directives. For sure, classes, structs, exceptions all work, and IIRC templates do too (although you might need to instantiate a header yourself for each concrete type or something .... haven't done that myself). This implementation also means that it can use any C++17 or C++20 construct, including lambdas and friends. Does D'
Read the rest
s C++ interop support C++17? C++20? Can you guarantee it will support C++27? Nim's implementation already does, on every single platform you'll be able to use C++27 on (as long as C++27 can compile modern C++ code; there had been backward incompatible changes along the C++ history). You can't just #include a C or C++ header and call it a day; You need to have a Nim compatible definition for any symbol (variable, macro, function, class, ...). There are tools that help you and make it almost as easy as #include, such as nimterop[0] and and nimline[1], and "c2nim" which is included with the Nim compiler is enough to generate the Nim definitions from the .h definitions (though it can't do crazy metaprogramming; if D can do that, then D essentially includes a C++ compiler. Which is a fine way to get perfect C++ compatibility - Nim does that) But Nim can also do the same for JS when treating JS as a backend. And it can basically do the same for Python, with nimpy[2] and nimporter, generating a single executable that works with your installed Python DLL (2.7, 3.5, 3.6, 3.7) - which is something not even Python itself can do. There was a similar Lua bridge, but I think that one is no longer maintained. > We also have Mir, which I haven't benchmarked for a while but was faster than OpenBLAS and Eugene There's quite a bit of scientific stack built natively with Nim. It is far from self-sufficient, but the ease with which you can use a C library makes up for it. I haven't used it, but Laser[3] is on par with or exceeds OpenBLAS speedwise, and generalizes to e.g. int32 and int64 matrix multiplication; Arraymancer[4] does not heve all of numpy's functionality but does have quite a few nice bits from scikit-learn, supports CUDA and OpenCL, and you can use numpy through nimpy if all else fails. Also notable is NimTorch[5]. laser and arraymancer are mostly developed by mratsim, who occasionally hangs out here on HN. D is a fine language, I used it a little in the D1 days, and it was indeed a "better C++" but did not deliver enough value to be worth it for me, so I stopped. I know D2 is much better, but I've already found my better C++ (and better Python at the same time!) in Nim, so I haven't looked at it seriously. [0] https://github.com/nimterop/nimterop [1] https://github.com/sinkingsugar/nimline [2] https://github.com/yglukhov/nimpy [3] https://github.com/numforge/laser [4] https://github.com/mratsim/Arraymancer [5] https://github.com/sinkingsugar/nimtorch
In Java is better than C++ for high speed trading systems
> Syntax wise Nim it is a step back. It's hard to read and understand while any C/C++ dev will have next to no effort reading through D code. And of course while D is C ABI compliant it interoperates with C++ well too. On the other hand, people coming from Python, Ruby, Pascal, Ada will appreciate the minimal amount of sigils. > I seriously doubt that Nim or any other language in this regard has better metaprogramming than D. Can you write an Embedded DSL + compiler running at compile-time in D - https://github.com/numforge/laser/tree/master/laser/lux_comp... Can you write a cryptographic library with hex conversion to big integer and modular arithmetic running at compile-time in D? - https://github.com/mratsim/constantine/blob/master/constanti... Can you generate a state machine that lowers down to optimized computed gotos with no dynami
Read the rest
c allocation suitable for multithreading runtimes and embedded devices and able to display the actual graph at compiletime? - https://github.com/mratsim/Synthesis Can you describe x86 opcodes in a declarative way for a JIT assembler and do all the rex/modrm/sib computation at compile-time? - https://github.com/mratsim/photon-jit/blob/master/photon_jit... And the same thing for an emulator? - https://github.com/mratsim/glyph/blob/master/glyph/snes/opco... Can you implement async as a library? Can you emulate classes with ADTs to solve the expression problem, avoid cache misses and multithreading problem due to OOP and the double indirection due to the visitor pattern? - https://github.com/mratsim/trace-of-radiance/blob/master/tra... > Nim might have a speed overhead in certain tasks but that depends on a benchmark. Besides, does Nim have anything similar to NumPy which is actually faster? D does. It does: - https://github.com/mratsim/Arraymancer With CPU, OpenCL and Cuda backends (in differing state of maturity) and it's being used for data analysis for example ancestry prediction: - http://home.chpc.utah.edu/~u6000771/somalier-ancestry.html You can even run a neural network and see its training live: - https://github.com/Vindaar/NeuralNetworkLiveDemo AFAIK D doesn't have any plotting library while Nim has plot.ly integration and a ggplot2 port in pure Nim: - https://github.com/brentp/nim-plotly - https://github.com/Vindaar/ggplotnim And lastly nim can easily call Python: - https://github.com/yglukhov/nimpy or be called from Python: - https://github.com/Pebaz/nimporter
In Ray Tracing in Nim

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.