SWIG VS Cython

Compare SWIG vs Cython and see what are their differences.

SWIG

SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. (by swig)
Our great sponsors
  • Scout APM - Less time debugging, more time building
  • SonarQube - Static code analysis for 29 languages.
  • SaaSHub - Software Alternatives and Reviews
SWIG Cython
13 40
4,494 7,036
1.9% 1.9%
9.8 9.6
2 days ago 1 day ago
C++ Python
GNU General Public License v3.0 or later GNU General Public License v3.0 or later
The number of mentions indicates the total number of mentions that we've tracked plus the number of user suggested alternatives.
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.

SWIG

Posts with mentions or reviews of SWIG. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2022-03-11.

Cython

Posts with mentions or reviews of Cython. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2022-05-21.
  • OCaml vs Haskell for finance
    3 projects | reddit.com/r/functionalprogramming | 21 May 2022
    Also, Cython has low level and high level typing and even Python also has native typings that you can use statically so you'd be able to do that as well, while Cython would probably express greater performance than Haskell/OCaml for this application since it's closer to the architectural paradigm of C/C++ and so the compilation is simpler and more direct.
  • My Experiences with Julia
    3 projects | news.ycombinator.com | 16 May 2022
    Cython has long been an interesting alternative here - a gradually typed amalgam of Python & C that lets you write/compile Python extension modules without needing to learn much of the CPython API. You can even use --embed to compile your whole script file and -X infer_types.verbose=True to let you know where types are dynamic/implicit rather than declared. Several big core packages like scipy use this as well.

    Personally, I prefer Nim [2] which has more compile-time meta-programming support, is strongly typed from the outset, and has a lot of syntactic flexibility like UFCS, and many other goodies.

    [1] https://cython.org/

    [2] https://nim-lang.org/

  • Python vs. JavaScript: Is It a Fair Comparison?
    3 projects | dev.to | 15 May 2022
    There are ways to optimize Python’s performance by taking advantage of the fact that it uses the C programming language under the hood. For example, NumPy comes with optimized C code that makes Python code faster. Cython is a compiler, and a superset of the Python language that enables developers to build fast C modules that speed up the execution of Python code.
  • For loop vs while loop in Python.
    9 projects | reddit.com/r/ProgrammerHumor | 14 May 2022
  • Python Shouldn't Be the Top Programming Language
    2 projects | news.ycombinator.com | 28 Apr 2022
    It depends on what "graduate" means (I note your "scare quotes"). For some lexical styles matter a lot and it is easier to answer this question with that kind of constraint.

    While its ecosystem is surely much smaller than even Julia's, Nim [1] has a lot of the concise, lexical feel of Python, but semantics more like Modula3/Ada and with Lisp-like syntax macros/metaprogramming to fill in other gaps.

    Another possibility is Cython [2] which is basically a superset of Python with gradual typing.

    [1] https://nim-lang.org/

    [2] https://cython.org/

  • this is a cry for help
    3 projects | reddit.com/r/ProgrammerHumor | 26 Apr 2022
    Cython would like a word...
  • hiding python source code
    2 projects | reddit.com/r/learnpython | 9 Apr 2022
    Either look at Cython, or try obfuscating the code then using pyinstaller to create an executable.
  • How should I structure a Python package that contains Cython code
    1 project | reddit.com/r/codehunter | 29 Mar 2022
    I'd like to make a Python package containing some Cython code. I've got the the Cython code working nicely. However, now I want to know how best to package it.
  • I'm a senior Engine dev and decided to share my in house 2D Game Engine with the world to use it (for free). Can I post it here?
    1 project | reddit.com/r/gamedev | 23 Mar 2022
    Oh no I am aware of that, it was praised for its easiness, readability and "pythonic way", then adopted by data scientists, which in turn took a direction to create more performant compiled code and have the ability to be used as an intermediate scripting layer to lower level languages.
  • Why You Should Use Python For Your Next Project
    7 projects | dev.to | 21 Mar 2022
    Still, it is worth mentioning that some libraries like NumPy, which is a library for scientific computing with Python, have some parts written in C, making it fast. It is always better to do the heavy computation in low-level languages such as C or C++, but their syntax and complexity might not be suitable for large projects. Therefore, some parts of Python libraries are written in C/C++ to make them faster and much more straightforward for data scientists, data analysts, and others. If you are looking for high performance in your code, consider Cython, which gives you C-like performance with code mostly written in Python.

What are some alternatives?

When comparing SWIG and Cython you can also consider the following projects:

cffi

CppSharp - Tools and libraries to glue C/C++ APIs to high-level languages

PyPy

djinni

JavaCPP - The missing bridge between Java and native C++

Pyston - A faster and highly-compatible implementation of the Python programming language.

JNA - Java Native Access

Stackless Python

libffi - A portable foreign-function interface library.

PyCUDA - CUDA integration for Python, plus shiny features

Pyjion

dramatiq - A fast and reliable background task processing library for Python 3.