Historical Note

This page was migrated from the original p-nand-q.com site which was last updated in 2015. The content has been preserved exactly as it was, with only formatting updated for modern browsers. Over the coming days and weeks, the content will be reviewed and may be updated for accuracy and relevance. If you find any issues, please contact me.

NAPYR 2.0 - Not A Python Runtime REBOOTED

NAPYR is an acronym for "Not a Python runtime". I wrote the first version back in 2002 and it was a stillborn idea even then, but I am a fighter and not giving up, so here is version 2.0 :)

Motivation

I was reviewing talk proposals on Euro Python 14, and I saw that there were a several tasks on Python and C/C++ integration. There seem to be two mainstream ideas on how to go about that:

  1. Use cython
  2. Use boost.python

Neither of these options works for me:

Plus, a quick peek around this website will tell you that whatever p-nand-q.com is about, it is not "about mainstream programming ideas".

Introducing NAPYR 2.0

NAPYR 2.0 is designed to be small, fast, and no-nonsense integration of Python code in C/C++ code. It is easy to use. It doesn't produce tons of code. If you learned C++ 20 years ago and still do it, but like anyone sensible you use only the good bits and eschew monster templates, then this is for you. But it is freeware: if you don't like it, simply don't use it!

Typical Scenario

The typical NAPYR scenario is Python for embedded scripting:

So the main flow looks like this:

Things you do not need

  1. Write .PYDs. You have an existing infrastructure that you want to be called. If you write a PYD, then you have essentially another DLL that still needs to call your existing infrastructure.
  2. Write .PYDs in Cython by extension of (1).
  3. Drowning in compiler errors and build times that make a grown man weep
  4. setuptools, py2exe or the McMillan installer. Chances are that if you have an existing product, you have an existing setup infrastructure and you just want to extend that, rather than have a separate component with a separate toolchain.
  5. a compiler version that is several years outdated, or that doesn't interact with other technologies on Windows. Python as available is compiled with really old Microsoft Visual Studio versions, and if your application uses a newer version, you're in for a ride. And I mean come on guys, seriously, who is developing major business applications on Windows for Windows using cygwin?

Things you do need

  1. Support for multithreading / multicore programming.
  2. Code that you can debug easily
  3. Build infrastructure that allows you to package the python code

NAPYR makes all this really easy.

So how does it look?