Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6114237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:57:04+00:00 2026-05-23T14:57:04+00:00

I know there are many ways to interface C function into Python: the Python

  • 0

I know there are many ways to interface C function into Python: the Python C API, scipy.weave, ctypes, pyrex/cython, SWIG, Boost.Python, Psyco… What are each of them best for? Why should I use a given method instead of others? What should be considered when I need to choose a binding between Python and C?

I know some discussions about that, but they all seems incomplete…

  • http://wiki.cython.org/SWIG
  • http://sage.math.washington.edu/tmp/sage-2.8.12.alpha0/doc/prog/node35.html

I know that some questions on StackOverflow are related too. For example:

  • About interfacing an existing C library
  • C API vs Cython
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:57:05+00:00Added an answer on May 23, 2026 at 2:57 pm

    I haven’t used all these methods although I have investigated them all at one point or another…

    The Python C API: For writing C code that compiles to a python module that can be imported in Python. Or for writing a Python module that acts as “glue” code to interface with some C library.

    scipy.weave: Allows you to shove bits of C code into your python code, if you’re using NumPy and SciPy for doing numeric work, look into this. The C code would be as a string, like, weave.inline(‘printf(“%s”, foo)’) for example.

    ctypes: A python module that allows you to call in to C code from your python code. You basically import the shared library then make calls into its API. Some work needed to marshall data in and out of those calls. If you’re looking at using an existing C library that you or someone else wrote, I’d start here.

    pyrex/cython: Allows you to write Python code (using some special syntax) that will get generated into C code (which can be imported as a Python module) and, obviously, run faster than if it was run through the Python interpreter. This is kind of like the “Python C API” route, only it generates the C code for you. Useful if you have some chunk of code that is your bottleneck and is really slow. Rewrite that function using cython and import it from the calling code.

    SWIG: Generates wrapper code for a C/C++ library. You should end up with a python module you can import and use.

    Boost.Python: This is the one I know the least about. Looks to me like it’s similar to SWIG although you write the wrapper layer yourself, but with a lot of help from Boost macros/functions.

    Psyco: Speeds up your python code a bit, I’ve never had much luck with this. I wouldn’t waste your time with it. Profile your code, find your bottlenecks and speed them up using one of the above techniques.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i know that there are many ways to program a deck of poker cards
So I know there are many ways to get the content of an external
I know and I've heard about there are many ways to connect to a
I know, there are many ways. I wish you could give me many ways
First thing first, I know there are many questions regarding python and lxml on
I know there are many tutorials out there for getting started in C. However
I know there are many cases which are good cases to use multi-thread in
I know there are many database design tool, database modeling tool. Example, ER-win ,
NOTE: I know there are many questions that talked about that but I'm still
I know there are already many questions like mine but I found no answer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.