r/pythontips • • Jul 20 '21

Module Speed Up your Python Codebases with C Extensions

We all know Python is slow and C is fast. What if you could combine the power of C with the simplicity of Python?

C extensions are exactly for that. They let you write functions and objects directly in C or C++ and import them from your Python script as they were a module.

The only downside is that they are not very well documented. When I had to learn them, there was little to no resource on how to do so. Old tutorials and even the official documentation were outdated and I had to go on by trial and error and reading lone and unclear forum threads.

This article is comprised of an overview on C extensions and why and where to use them. It also contains a simple working example with source code and the steps to build an extension.

https://betterprogramming.pub/speed-up-your-python-codebases-with-c-extensions-94859875eb70

I hope you will find this resource helpful. And what do you think, should C extensions be the norm in Python codebases?

51 Upvotes

4 comments sorted by

2

u/cyrusmew Jul 20 '21

Thanks a ton! I will certainly follow along this article coming weekend!!

0

u/[deleted] Jul 20 '21

[deleted]

1

u/Obertuba Jul 21 '21

How strange. I've even tried viewing it in incognito mode to make sure everyone, members and not would be able to read it. Did you try to open the link from mobile or PC?

1

u/mysterious_mosaic Jul 21 '21

I can confirm. On android you do not need to sign up

1

u/boilerDownHammerUp Jul 21 '21

I didn’t need to sign up to read…