Ode to Nimpy
Tags: python, nim
Published: 2019-11-16 17:49:46

---
title: Ode to Nimpy
published: true
description: Kudos to Nimpy & Nim from a Python dev perspective
tags: python, nim
cover_image: https://thepracticaldev.s3.amazonaws.com/i/lo511yzs8fvzh5xd35ub.png
---

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/jkb0ywqgnw7lvquj4w30.png "1 language for the whole stack, run on Frontend, run on Backend")

# The Nim experience

*So far...*

When PIP3 got broken on [Arch Linux](https://www.archlinux.org/),
lots of [Python](http://python.org) modules got broken,
my [Nim](https://nim-lang.org) [Nimpy](https://github.com/yglukhov/nimpy#nimpy-) Python modules continue working.

When Python3 become default on most Linux,
lots of Python modules got broken,
my [Nimpy](https://github.com/yglukhov/nimpy#nimpy-) Python modules continue working.

When "ABI3" of Python3 launched,
some Python modules got broken,
my [Nimpy](https://github.com/yglukhov/nimpy#nimpy-) Python modules continue working.

When Python3.8 become default on Linux,
lots of Python modules got broken,
my [Nimpy](https://github.com/yglukhov/nimpy#nimpy-) Python modules continue working.

[![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/u3wfh0uhohur24bwa3nw.png)](https://nim-lang.org/install.html)

*"Deprecation Warning"* for a year on Nimpy,
my [Nimpy](https://github.com/yglukhov/nimpy#nimpy-) Python modules continue working.

*"Experimental"* features for a year on Nimpy,
my [Nimpy](https://github.com/yglukhov/nimpy#nimpy-) Python modules continue working.

If [Nimble](https://nimble.directory) get broken someday, just use Git or Curl,
Install packages is copy&paste a file.

My [Nimpy](https://github.com/yglukhov/nimpy#nimpy-) Python modules are faster than PyPy,
the most super-optimized Python3.8 code is several orders of magnitude slower than the crappiest unoptimized equivalent on Nim.

Most times I use a lot less lines of code than CPython, without code-golf,
it is not only about more performance but also it uses less code.

[C interop is a lot better than CTypes](https://github.com/juancarlospaco/nim-presentation-slides/blob/master/ejemplos/basico/c/enchufa_stdio.nim), JavaScript too,
you can interoperate with anything that has C/C++ or JS API.

I write a lot less Type Annotations thanks to Type Inference,
but yet [Types are strongly enforced](https://dev.to/juancarlospaco/python-cython-nim-cheatsheet-hjj),
variables are not `None` out of thin air, integers are not float out of thin air.


# Deploy

**Deploy anywhere where you can compile C:**

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/a402cejvekj7lzfs7re9.jpg)

- `scp` the binary to the server & run!, forget installers and prepared environments, those are kludges of the past.


# You can learn today

**Hello World:**
```nim
echo "Hello World"
```

**For Python:**
```nim
import nimpy

proc hello() {.exportpy.} =
  echo "Hello World"
```

- `{.exportpy.}` is a [*Pragma*](https://nim-lang.org/docs/manual.html#pragmas) to export to Python, is like a Decorator.
- `proc` is like `def` of Python, it also has `func` for Pure-Functional.
- You can use [Python Syntax](https://github.com/Yardanico/nimpylib#use), but for this example I go with std lib.

**On Python:**
```python
from module import hello
hello()
```

[Install](https://nim-lang.org/install.html), [Tutorial](https://nim-lang.org/learn.html), [Documentation](https://nim-lang.org/documentation.html), [Manual](https://nim-lang.org/docs/manual.html), [Docker](https://github.com/moigagoo/nimage), [Chat](https://t.me/nim_lang), [Try Nim on the browser](https://play.nim-lang.org), [Nim for Python devs](https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programmers), [Standard Library](https://nim-lang.org/docs/lib.html), [Python integration](https://github.com/yglukhov/nimpy), [Python Syntax](https://github.com/Yardanico/nimpylib#use), [Python/Nim Cheatsheet](https://dev.to/juancarlospaco/python-cython-nim-cheatsheet-hjj).

**Advanced Nimpy Example:**

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/rkm04sivm8bodyb510uj.png)

- Go give Star to Nimpy: https://github.com/yglukhov/nimpy


# Welcome to the Nim

{% youtube P8oJUGVbOlQ %}

50 years on the past you can compile C,
100 years on the future you can compile C.
[Dennis Ritchie](https://en.wikipedia.org/wiki/Dennis_Ritchie) was right.
👑🥰👍