项目作者: apahl

项目描述 :
Nim cell magic for JupyterLab or Juypter Python Notebooks.
高级语言: Jupyter Notebook
项目地址: git://github.com/apahl/nim_magic.git
创建时间: 2018-06-18T09:06:20Z
项目社区:https://github.com/apahl/nim_magic

开源协议:MIT License

下载


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:

  1. # In [1]:
  2. %load_ext nim_magic
  3. # In [2]:
  4. %%nim -d:release
  5. proc greet(name: string): string {.exportpy.} =
  6. return "Hello, " & name & "!"
  7. # In [3]:
  8. greet("World")
  9. # Out [3]:
  10. 'Hello, World!'
  11. # In [4] (this will remove temporary dirs created by nim_magic):
  12. %nim_clear

Further examples can be found here.

And there are some gists, too: