Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Writing a Python C extension in 2018
Search
Jean-Baptiste Aviat
May 16, 2018
Programming
1.2k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Writing a Python C extension in 2018
Jean-Baptiste Aviat
May 16, 2018
More Decks by Jean-Baptiste Aviat
See All by Jean-Baptiste Aviat
Content Security Policy in your Rails apps in 30s
aviat
0
330
App Security is just a Git flow (with built-in conflicts)
aviat
0
1.1k
Tune your App Perf (and get fit for summer)
aviat
2
550
Other Decks in Programming
See All in Programming
最近”作らせてる” ローカルAIアプリの話
akit37
0
470
npm との違いを手がかりにGo の依存管理を理解したい
optim
0
610
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
220
すこし踏み込む CancellationToken
htkym
2
1.7k
Railsのためのパスキー実践入門 〜マルチテナントSaaSでの意思決定〜
utakaha
2
650
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
380
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
5
3.8k
ジョジョの世界をXRで再現する
mofurune
0
170
當我們開始不讀 Code - AI Agent 時代,Code Review 與 Clean Code 還剩下什麼?
jame2408
1
250
JIS keyboard support in Omarchy
lef237
0
120
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5.2k
Featured
See All Featured
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
630
Typedesign – Prime Four
hannesfritz
42
3.2k
Building AI with AI
inesmontani
PRO
1
1.3k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
330
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
330
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
550
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8.1k
Rails Girls Zürich Keynote
gr2m
96
14k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
270
Transcript
Writing a C Python extension in 2018 Paris.py 2018
Jean-Baptiste Aviat CTO & Co-founder of sqreen.io Former Hacker at
Apple (Red Team) PyMiniRacer author
[email protected]
@jbaviat Who Am I?
Someday… we needed to use V8 from Python. What we
ship: • is public • is widely used • need to have frictionless install $ pip install sqreen —> it just works™!
None
PyMiniRacer: cool JS binding github.com/sqreen/PyMiniRacer
The problem • V8 is C++ • How do you
run C++ in Python? …We need some kind of binding between these 2 worlds.
Many popular packages rely on binary cryptography numpy pymongo psycopg
simplejson lxml sqlalchemy…
People do it! Let’s do it too.
What are our goals? • minimize maintenance • make setup
easy • make testing easy • have great performance • have low memory fingerprint • dev time is a constraint We want to: And (obviously)…
built-in pythonic Python version independant open to other languages high
throughput capable CPython ✔ ✔ ✔ ctypes ✔ ✔ ✔ cffi ✔ ✔ ✔ ✔ Cython ✔ ✔ SWIG ✔ ✔
ctypes Built into Python Binary is Python independant: • can
be used on any Python version • can be used in other languages! No tight integration to Python • not high throughput capable • less Pythonic Complex syntax (C types wrapped in Python…) Not for C++
$ python >>> path = "./hello.so" >>> import ctypes >>>
lib = ctypes.cdll.LoadLibrary(path) >>> lib.hello_world() Hello world! C file Python interface binary object
Overview V8 (C++ interface) C interface to V8 Python interface
3rd party binaries import ctypes class PyMiniRacer(object): … #include <v8.h> int miniracer_init(); … V8 library (libv8.a) V8 headers (v8.h) linking ctypes C/C++ code Python library
How to put this together? $ cat setup.py from distutils.core
import setup, Extension extension = Extension('hello', ['hello.c']) setup(name=‘hello', version='1.0', ext_modules=[extension]) $ python setup.py build running build running build_ext building 'hello' extension clang […] -c hello.c -o hello.o creating build/lib.macosx-10.6-intel-2.7 clang -bundle […] hello.o -o hello.so
None
None
Ship it
Ever had trouble installing packages?
None
(at Sqreen, we are dog friendly) Come get your dog
sticker!
Python packaging history sdist (source distribution) eggs wheels —> manylinux
wheels (built distribution) 2004 2012 2016 Python 2.4 Python 3.3 Python 3.6 ❤
manylinux wheels Python standard: PEP513 / PEP571 Compatible on most
(real world) Linux Only in pip >= 8.1 Need build for all Python versions Binaries need to be built on CentOS 5
CentOS 5?? PEP571 → bumped requirement to CentOS 6!
Wheels vs compilation iso builds (crash can be reproduced) many
packages need maintenance one build per user only one package harder to install…
Best of 2 worlds We can have: ctypes: use a
Python independant binary wheels: ship compiled binaries By combining these… ctypes + wheels = ship only one binary
Thanks! Questions? We’re hiring! https://sqreen.io/jobs