joelholder.com - Joel Holder's Code Compendium – A Public Journey of Discovery

Description: A Public Journey of Discovery

Example domain paragraphs

A Public Journey of Discovery

When working in Python, there are times when you need more speed than it can deliver. These times to reach for C/C++. The interop between the languages is clean, minimal, and very fast. Here, I’ll give a quick example with a little commentary to assist with understanding the basics.

First, the basic problem. Let’s say that you’re working in Python, but there’s an excellent library implementing some critical functionality in C that you need. How do you compose it into your application? Fortunately, Python includes ctypes right out of the box. To demonstrate, I’ll show how I’ve directly surfaced the C API of the fantastic libgeohash for consumption in Python.