Skip to content

Nim cell magic for JupyterLab or Juypter Python Notebooks.

License

Notifications You must be signed in to change notification settings

apahl/nim_magic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nim_magic

Nim cell magic for JupyterLab or Jupyter Python Notebooks.

Write Nim modules and use the compiled code directly in the Notebook as extension modules for the Python kernel (similar to e.g. %%cython, but for your favorite language :P ). It builds on @yglukhov 's awesome nimpy library.

Requirements

  • A Nim compiler in your path
  • nimpy package (nimble install nimpy)

Installation

Just put the file nim_magic.py somewhere in Python's import path, e.g. in one of the dirs that is printed by: python3 -c "import sys; print(sys.path)".

Example

In a JupyterLab or Jupyter Notebook running a Python3 kernel:

# In [1]:
%load_ext nim_magic


# In [2]:
%%nim -d:release
proc greet(name: string): string {.exportpy.} =
    return "Hello, " & name & "!"


# In [3]:
greet("World")
    

# Out [3]:
'Hello, World!'


# In [4] (this will remove temporary dirs created by nim_magic):
%nim_clear

Further examples can be found here.

And there are some gists, too:

About

Nim cell magic for JupyterLab or Juypter Python Notebooks.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published