3 ms·
oscrypto, in attempt to support both CPython and PyPy well, uses cffi or ctypes to interface with the crypto libraries. That said, when cffi is present, only th
by wbond 10y ago
oscrypto, in attempt to support both CPython and PyPy well, uses cffi or ctypes to interface with the crypto libraries. That said, when cffi is present, only the ABI (dlopen) mode is used. No shared libraries are compiled.
My experience using both for the project has lead me to characterize ctypes as something for Python developers wanting to interact with C, and cffi as something for C developers wanting to use their code from Python. ctypes plays nicer with the Python GC. cffi is oriented towards C terminology/semantics, and (even knowing from the beginning that weak refs must be held) was far easier to crash by accidental use-after-free.
- mhashemi 10y agoThat's really useful to hear, especially from you, (presuming you're the same wbond who wrote oscrypto)! Have you written or considered writing a longer-form expansion on these experiences? And yeah, in spite/because of all its simplisticness, ctypes really does seem to win out among those who share Python's aesthetics.
- wbond 10y agoYes, I am the author of oscrypto. Unfortunately one of my unfulfilled interests is longer-form technical writing. Trying to balance open source and family means that for now, that isn't in the cards. I think one of the biggest benefits of ctypes is that it is part of the stdlib. Not requiring a compiler means it opens up a whole swath of users who aren't Python developers, but have Python installed. Part of the reason I'm interested in this is being heavily involved in the Sublime Text community, where every user has Python and ctypes, but requiring a C compiler and Python headers eliminates probably 99% of users. Trying to distribute pre-compiled shared libraries was a path I went down, but gave up on. Having to compile 10 versions of the cryptography package every time a new release came around was a disaster. If you chance upon the cryptography-dev IRC channel, you'll see it is a part time job to get the package compiled reliably, and they have dedicated hardware provided by Rackspace to help them.
- eggy 10y agoI am not too experienced in Python as much as I am in C. In general, do you think Cython might be better middle ground, or am I completely amiss of the various fits between cffi, ctypes and Cython? End use is mainly DSP-like code, neural networks (Darknet in C), and OpenCV and CUDA.
- mivade 10y agoCython is intended for making Python extension modules. So if the end goal is to make something that you interact with only from Python, then Cython is a good choice. You can still use it to simply wrap some existing library, but ctypes or cffi might then be a bit simpler since it they don't require an added compilation step.