python cffi tutorial (intermediate - advanced) anthony explains #155

preview_player
Показать описание
today I build a sample cffi library, wrapping the `uuid` system module! cffi is a performant alternative to writing error-prone C extensions and performs well with pypy!

==========

I won't ask for subscriptions / likes / comments in videos but it really helps the channel. If you have any suggestions or things you'd like to see please comment below!
Рекомендации по теме
Комментарии
Автор

this seems easier and better than c extensions from what you've shown, are there any downsides to it?

sadhlife
Автор

I always wonder about how this work with C library functions that allocate data with malloc internally.

I _guess_ you wrap it in a class and call the free function in the `__del__` method, but I never see examples dealing with it, though there are a few words about it in the CFFI documentation---words which don't make it totally clear what the optimal way to do this is without manually reasoning about memory lifetimes.

ninjaaron
Автор

hi, i am trying to replicate what you did in the video on windows with dll, but i don't have a header file. what should i do?

ekardonsenior
Автор

Where can I find the uuid.h on a Windows machine?

ZZDryno
Автор

When you set the module name "_uuidcffi" you say that the underscore makes the c module faster. Does that mean that code will actually run faster or will it just compile faster?

ZZDryno
Автор

Great video! I was able to generate a package wrapping my custom DLL to generate a pyd module. I can use the pyd module if I simply copy it (along with the DLL) along side a py module that imports and uses the pyd. However, I can't seem to build a binary wheel to include the pyd module. I do not want to distribute the C code that generates the LIB/DLL/PYD files, just the DLL, headers, and PYD files. Can you do a video that provides this capability? Even a cross-platform method for an "equivalent" shared object would be helpful as well.

stuartdols
Автор

None of your examples compile or run, Anthony. It is really cool to see how successful you are but if I cannot do it what good is it to me?

QuantumWithAnna
Автор

Is it just me or this shit is way too complicated, I find plain ctypes lot more clear

ragnarlothbrok