What is Cython? An introduction to a supercharged version of Python

Fed up of how slow Python is? If you’re looking for a way to optimise Python code, especially for handling big data, you may want to invest some time in Cython.

Like animals or plants, languages live and die. A language is kept alive by its speakers and can become extinct when those speakers die themselves. Take Latin, for example, which formed the foundations of many modern Western languages but has not been widely spoken for centuries. It’s the same story for programming languages.

Programming languages rise and fall with the waves of innovation. Coding goes through trends; any kind of language evolves and builds, and it’s the same for programming languages, surging in popularity before becoming eventually displaced, confined to the annals of forgotten hard-drives.

Some of the code that developers used in the early days of software is but hieroglyphics on a cave wall in comparison to the code we employ today. Quite famous languages, too, have fallen by the wayside, been developed upon or simply withered in popularity. Pascal led to Delphi, Objective C was replaced by a much cooler Swift and Perl has been in a liminal state for years, in and out of fashion regularly.

Python is being built upon and it’s benefiting data scientists and AI programmers.

What is Cython?

Python is a high-level, general-purpose programming language, created by Dutchman Guido van Rossum in 1991, and named after the eccentric British comedy troupe, Monty Python. Cython is a portmanteau of Python and C/C++, not to be confused with CPython.

Cython has a user-friendly interface, allowing Python to interact with C/C++ code. Cython can massively decrease computing time: that’s the main reason that it has generated hype, as unlike Python, Cython requires code to be “executable”.

Cython takes a little more coding but can have a bigger reward. / Credit: Cardinal Peak

A compiler analyses the source code and can produce a lower machine language of the code that you have written. Generally, this makes the machine language faster and more easily readable for your computer to run. Python is a high machine language. Cython takes complicated instructions that can’t be read by humans and compiles it efficiently so a computer can read it.

Python is almost readable for humans. It is an interpreter rather than a compiler, which means it will convert code into instructions for a computer line-by-line. Translation takes time. Python scans through until it reaches an error and this can be a slow process.

Cython’s speed in comparison to Python depends on the code itself. Computationally heavy loops can be managed quickly and easily by Cython.

How could Cython be used?

Python is commonly used in conjunction with artificial intelligence. For many developers, python is at the spine of machine learning and developers use libraries like Keras, Scikit-learn and TensorFlow. Python is also used for Natural Language Processing (NLP) as it uses simple syntax and rich text processing tools.

The ability that Cython has to speed up your Python workflows makes it extremely appealing. Take an NLP task, for example: imagine that you want to count the number of times a particular word crops up in a dataset. A Python loop can find the answer, but supposing that there are thousands of documents within a dataset, it could a long time to get a result.

In Python, there’s something called a global interpreter lock (GIL). This is essentially a lock that protects access to Python objects, preventing multiple threads from executing Python bytecodes at once. CPython’s memory management is not thread-safe but this lock stabilises Python.

With Cython, this GIL lock is released.


Cython is the programmer’s language of the future when it comes to NLP


Cython code is a little longer – a developer must declare and populate the C structures – but ultimately it runs a lot quicker. Cython code can be up to 2300 times faster than Python implementation; though the traditional assumption with AI is that it’s conducted in laboratories by scientists on super quantum computers, the truth is that you can run Python on Mac, Windows and Linux. This speed update is very much welcome to any kind of programmer.

If there is a significant disadvantage with Cython, it is that some developers prefer not to “contaminate” the code, so to speak. Some prefer Python to stay as Python: confusing the code with C elements can complicate things.

However, in the long run, Cython exists simply to make Python easier, not to make it more complex. Python programs can run Cython with no add-ons or extensions. If you are pre-processing a large dataset or computing analytics, Cython is a relatively easy way to speed up your workflow.

Languages come and go. As recently as 2012, the Cromarty dialect found in Northern Scotland went extinct with the passing of its last sole survivor. Programming languages should be thought of in a similar way: spoken language is developing every day, branching off into different directions as words and other languages are added to each other.

A development like Cython even got its name in the same way that Frenglish, for example – the combination of English and French elements into one tongue – got its title. Cython is the programmer’s language of the future when it comes to NLP. What kind of language will we end up building upon it?

Luke Conrad

Technology & Marketing Enthusiast

Data-Sharing Done Right: Finding the Best Business Approach

Bart Koek • 20th November 2024

To ensure data is not only available, but also accessible to those that need it, businesses recognise that it is vital to focus on collecting, sorting and governing all the data in their organisation. But what happens when data also needs to be accessed and shared across the business? That is where organisations discover a...

Nova: The Ultimate AI-Powered Martech Solution for Boosting Sales, Marketing...

Erin Lanahan • 19th November 2024

Discover how Nova, the AI-powered engine behind Launched, revolutionises Martech by automating sales and marketing tasks, enhancing personalisation, and delivering unmatched ROI. With advanced intent data integration, revenue attribution, and real-time insights, Nova empowers businesses to scale, streamline operations, and outperform competitors like 6Sense and 11x.ai. Experience the future of Martech with Nova’s transformative AI...

How E-commerce Marketers Can Win Black Friday

Sue Azari • 11th November 2024

As new global eCommerce players expand their influence across both European and US markets, traditional brands are navigating a rapidly shifting landscape. These fast-growing Asian platforms have gained traction by offering ultra-low prices, rapid product turnarounds, heavy investment in paid user acquisition, and leveraging viral social media trends to create demand almost in real-time. This...

Why microgrids are big news

Craig Tropea • 31st October 2024

As the world continues its march towards a greener future, businesses, communities, and individuals alike are all increasingly turning towards renewable energy sources to power their operations. What is most interesting, though, is how many of them are taking the pro-active position of researching, selecting, and implementing their preferred solutions without the assistance of traditional...

Is automation the silver bullet for customer retention?

Carter Busse • 22nd October 2024

CX innovation has accelerated rapidly since 2020, as business and consumer expectations evolved dramatically during the Covid-19 pandemic. Now, finding the best way to engage and respond to customers has become a top business priority and a key business challenge. Not only do customers expect the highest standard, but companies are prioritising superb CX to...

Automated Testing Tools and Their Impact on Software Quality

Natalia Yanchii • 09th October 2024

Test automation refers to using specialized software tools and frameworks to automate the execution of test cases, thereby reducing the time and effort required for manual testing. This approach ensures that automation tests run quickly and consistently, allowing development teams to identify and resolve defects more effectively. Test automation provides greater accuracy by eliminating human...