Giter Club home page Giter Club logo

cython's Introduction

Cython

A guide for Python programmers to learn Cython quickly (It does expect that you are comfortable using the Python language, but expects that you are not familiar with C or C++). All the code in this guide can be ran using the Dockerfile in the root of this repository.

  1. Helloworld
  2. C or C++
  3. Functions

What is Cython?

Cython is a superset of Python, which means it looks and feels like Python, but has extra keywords that allow parts of it to be able to be compiled to highly efficient C and/or C++ code. Cython allows parts of your code to be annotated with C/C++ types, allowing for much faster execution but still maintaining interoperability with Python for it's flexibility and abundance of packages.

This means that we could in the same function, write some complex computational code that runs completely in C/C++ giving us large speed gains, and then easily and conveniently use the requests module to make a HTTP request. An example of this might be:

import requests

cdef do_something():
    cdef int i
    cdef int n = 1000000
    cdef int sum = 0
    for i in range(n):
        sum += i

    requests.post("test.com", json={"sum": sum})

Why am I writing this?

I've been using Cython for a while now, and I've found it to be a very useful tool. However, I've also learned that most engineers don't even know it exists, or have got it confused with CPython. I also think that the documentation for Cython is not very comprehensive (maybe the stuff I write here could get in there someday) and it's hard to find good resources to learn it well. So I'm writing this guide to help people learn Cython quickly and easily.

When and why should I use Cython?

Compiling to C and C++ primarily gives speed increases for computationally intensive programs, so if you're building something that is mostly IO bound then Cython isn't going to help much.

cython's People

Contributors

alexdaima avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.