Skip to content
Compile Nim Extensions for Python On Import!
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Added feature to always build Dec 18, 2019
.gitignore Add gitignore: Nov 30, 2019
LICENSE Licensing update Dec 13, 2019 Add option for speed Feb 11, 2020 Releasing new version Dec 26, 2019



Compile Nim extensions for Python on import automatically!

With Nimporter, you can simply import Nim source code files as if they were Python modules, and use them seamlessly with Python code. The compiler is invoked to build a Python-compatible extension module and it is then placed in the __pycache__ directory, which means that you don't have to add a line to your .gitignore files because (presumably) Git is already ignoring the __pycache__ directory.

Possible Benefits

  • Seamless integration with existing Nim code by using the Nimpy library.
  • Very low effort to create high-performance Python extensions using Nim.
  • Leverage both language's ecosystems: Python for breadth, Nim for performance.


  1. Nim Compiler
  2. Nimpy library
  3. Nimporter library (this library).


# Windows
$ pip install nimporter  # Nimporter library
$ nimble install nimpy  # Nimpy library

# Everything Else
$ pip3 install nimporter  # Nimporter library
$ nimble install nimpy  # Nimpy library


# nim_math.nim

import nimpy

proc add(a: int, b: int): int {.exportpy.} =
    return a + b
import nimporter

import nim_math

print(nim_math.add(2, 4))  # 6


For tutorials, advanced usage, and more, head over to the Wiki.

Distributing Libraries Using Nimporter

Libraries that require Nim source files can easily distribute those files by adding the following to their file:

    name='Foo',                     # Keep your existing arguments
    package_data={'': ['*.nim']},   # Distribute Nim source files
    install_requires=['nimporter']  # Depends upon Nimporter

When creating a source distribution, the Nim source files will be included along with the normal Python files it uses.

Stargazers over time

Stargazers over time

Made using

You can’t perform that action at this time.