[Mobilitydb-dev] Which approach for the C Python binding ?

Esteban Zimanyi estebanzimanyi at gmail.com
Thu Jun 16 09:11:59 PDT 2022


Dear Krishna

Many thanks for your detailed analysis. We will keep you posted about how
we advance in this endeavor.

Esteban

On Tue, Jun 14, 2022, 19:29 Krishna Chaitanya <bkchaitan94 at gmail.com> wrote:

> Dear Professor,
>
> I must say it's been a while since I worked with Python/C bindings, for
> PyMEOS, I looked more in the C++/Python direction.
> Anyways, from what I remember these the main pros/cons of each:
>
> *ctypes*
> This is generally the recommended way to go. And most libraries are built
> in this approach.
> It is the simplest to understand for people coming mainly from C
> background.
> It is a bit tedious and repetitive work to build interfaces in ctypes
> compared to other approaches, where some of the boring parts are a bit
> automated (although at the cost performance overhead and/or learning curve).
>
> *CFFI*
> This seems to be the newer alternative to ctypes, I haven't explored it in
> detail much before.
>
> *Cython*
> This is the easier approach. It's a bit higher level than ctypes and CFFI.
> It has an intermediate language between python and c through which the
> interfacing happens.
> Shapely was built using Cython. Although performance wise, it is usually
> said that this approach has some overhead compared to other approaches.
>
> *C extension module*
> This is the lowest level interfacing possible and possibly the performant.
> But disadvantage is it would only support developers using the CPython
> compiler. While that covers the majority, some people who use PyPy, jPython
> etc might not be able to use the library.
> Another advantage here is that when dealing with Python data science tools
> like numpy and pandas, you can make operations that work on a collection of
> objects faster by utilizing ufuncs from numpy
> <https://numpy.org/devdocs/user/c-info.ufunc-tutorial.html>. This is the
> approach taken by the library pygeos <https://github.com/pygeos/pygeos>,
> which is now merged into Shapely.
>
> In conclusion, I wouldn't say there is any best approach, I think any
> option is good. If at all I had to pick an option, maybe I would just go
> with either of ctypes/CFFI approaches to start off and to keep it simple
> and balanced for performance.
> Hope that helps. Do let me know if you need anything more.
>
> Thanks,
> Krishna Chaitanya
>
> On Mon, 13 Jun 2022 at 17:53, Esteban Zimanyi <estebanzimanyi at gmail.com>
> wrote:
>
>> Dear Krishna
>>
>> Allow me one quick question. I am discovering the world of Python
>> bindings, e.g.,
>> https://realpython.com/python-bindings-overview/
>>
>> My approach would be to link the libmeos C library to MobilityDB-python
>> https://github.com/MobilityDB/MobilityDB-python
>>
>> Which approach do you recommend ? ctypes, CFF, Cython, other ?
>>
>> Thanks again for you insights
>>
>> Esteban
>>
>> ------------------------------------------------------------
>> Prof. Esteban Zimanyi
>> Department of Computer & Decision Engineering  (CoDE) CP 165/15
>> Universite Libre de Bruxelles
>> Avenue F. D. Roosevelt 50
>> B-1050 Brussels, Belgium
>> fax: + 32.2.650.47.13
>> tel: + 32.2.650.31.85
>> e-mail: esteban.zimanyi at ulb.be
>> Internet: http://cs.ulb.ac.be/members/esteban/
>> ------------------------------------------------------------
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mobilitydb-dev/attachments/20220616/25398fe5/attachment.htm>


More information about the Mobilitydb-dev mailing list