Skip to content

Instantly share code, notes, and snippets.

View EFulmer's full-sized avatar
😄

Eric Fulmer EFulmer

😄
View GitHub Profile
@EFulmer
EFulmer / rust-python-cffi.md
Created April 15, 2018 20:15 — forked from seanjensengrey/rust-python-cffi.md
Calling Rust from Python/PyPy using CFFI (C Foreign Function Interface)

This is a small demo of how to create a library in Rust and call it from Python (both CPython and PyPy) using the CFFI instead of ctypes.

Based on http://harkablog.com/calling-rust-from-c-and-python.html (dead) which used ctypes

CFFI is nice because:

  • Reads C declarations (parses headers)
  • Works in both CPython and PyPy (included with PyPy)
  • Lower call overhead than ctypes