PLDB
Languages Features Creators Calendar CSV Resources Blog About Donate Add Language
GitHub icon

Cython

< >

Cython is a programming language created in 2007.

#245on PLDB 16Years Old 1.6kUsers
10Books 1Papers 698Repos

Cython is a superset of the Python programming language, designed to give C-like performance with code which is mostly written in Python. Cython is a compiled language that generates CPython extension modules. These extension modules can then be loaded and used by regular Python code using the import statement. Read more on Wikipedia...


Example from Wikipedia:
In [1]: %load_ext Cython In [2]: %%cython ...: def f(n): ...: a = 0 ...: for i in range(n): ...: a += i ...: return a ...: ...: cpdef g(int n): ...: cdef int a = 0, i ...: for i in range(n): ...: a += i ...: return a ...: In [3]: %timeit f(1000000) 42.7 ms ยฑ 783 ยตs per loop (mean ยฑ std. dev. of 7 runs, 10 loops each) In [4]: %timeit g(1000000) 74 ยตs ยฑ 16.6 ns per loop (mean ยฑ std. dev. of 7 runs, 10000 loops each)

Language features

Feature Supported Token Example
Integers โœ“
Floats โœ“
Hexadecimals โœ“
Octals โœ“
Scientific Notation โœ“
Binary Literals โœ“
# 0[bB](?:_?[01])+
Functions โœ“
While Loops โœ“
Case Sensitivity โœ“
Print() Debugging โœ“
Threads โœ“
Line Comments โœ“
# A comment
Dispose Blocks Pattern โœ“
with resource_context_manager() as resource:
   # Perform actions with the resource.
# Perform other actions where the resource is guaranteed to be deallocated.
Zero-based numbering โœ“
Strings โœ“
"hello world"
Inheritance โœ“
class SumComputer(object):
   def __init__(self, a, b):
       self.a = a
       self.b = b
   def transform(self, x):
       raise NotImplementedError
   def inputs(self):
       return range(self.a, self.b)
   def compute(self):
       return sum(self.transform(value) for value in self.inputs())
 class SquareSumComputer(SumComputer):
     def transform(self, x):
         return x * x
 class CubeSumComputer(SumComputer):
     def transform(self, x):
         return x * x * x
Semantic Indentation โœ“
class Person (object):
  def __init__(self, name):
    self.name = name
Operator Overloading โœ“
# Python Program illustrate how  
# to overload an binary + operator 
  
class A: 
    def __init__(self, a): 
        self.a = a 
  
    # adding two objects  
    def __add__(self, o): 
        return self.a + o.a  
ob1 = A(1) 
ob2 = A(2) 
ob3 = A("Geeks") 
ob4 = A("For") 
  
print(ob1 + ob2) 
print(ob3 + ob4)
Multiple Inheritance โœ“
class Base1:
    pass
class Base2:
    pass
class MultiDerived(Base1, Base2):
    pass
# Or multilevel inheritance:
class Base:
    pass
class Derived1(Base):
    pass
class Derived2(Derived1):
    pass
Lists โœ“
myList = [1, 2, 3, 4, 5]
Multiline Strings โœ“
template = """This is the first line.
This is the second line.
This is the third line."""
Mixins โœ“
# https://easyaspython.com/mixins-for-fun-and-profit-cb9962760556
class EssentialFunctioner(LoggerMixin, object):
Iterators โœ“
https://www.w3schools.com/python/python_iterators.asp
Infix Notation โœ“
seven = 3 + 4
File Imports โœ“
import datetime
oTime = datetime.datetime.now()
from my_pkg import my_funcs
Assignment โœ“
name = "John"
Directives โœ“
from __future__ import feature
# coding=
Generators โœ“
https://wiki.python.org/moin/Generators
Constructors โœ“
MultiLine Comments โœ“
''' A comment.
'''
Comments โœ“
# This is a comment
Conditionals โœ“
if True:
 print("Hello world")
Classes โœ“
class Person (object):
  def __init__(self, name):
    self.name = name
Booleans โœ“
Dynamic Properties โœ“
class Person (object):
  def __init__(self, name):
   self.name = name

person = Person("John")
person.age = 50
Symbol Tables โœ“
# https://eli.thegreenplace.net/2010/09/18/python-internals-symbol-tables-part-1
Shebang โœ“
#!/usr/bin/env python
Bitwise Operators โœ“
x << y
Ternary operators โœ“
print(1 if 1 else 0)
Single Dispatch โœ“
Duck Typing โœ“
Disk Output โœ“
with open('helloworld.txt', 'w') as filehandle:
 filehandle.write('Hello, world!\n')
Units of Measure X
Pointers X
Case Insensitive Identifiers X
Regular Expression Syntax Sugar X
Enums X
# Though there is an Enum class in stdlib https://peps.python.org/pep-0435/
Macros X
Variable Substitution Syntax X

Books about Cython on goodreads

title author year reviews ratings rating
Cython: A Guide for Python Programmers Kurt W Smith 2014 4 29 3.97
Learning Cython Programming Philip Herron 2013 3 11 3.91
Learning Cython Programming - Second Edition Philip Herron 0 0 0.0
Learning Cython Programming Second Edition Philip Herron 0 0 0.0

Books about Cython from ISBNdb

title authors year publisher
Learning Cython Programming Herron, Philip 2013 Packt Publishing
Cython Kurt W. Smith 20150121 O'Reilly Media, Inc.
Cython Kurt W. Smith 20150121 O'Reilly Media, Inc.
Learning Cython Programming Philip Herron 2013-09-25 Packt Publishing
Learning Cython Programming Philip Herron 22-02-2016 Packt Publishing
Learning Cython Programming - Second Edition Herron and Philip 2016 Packt Publishing

Publications about Cython from Semantic Scholar

title authors year citations influentialCitations
A Cython Interface to EPICS Channel Access for High-level Python Applications J. Chrin 2017 1 0
netlogo.html ยท cython.html ยท snobol.html

View source

PLDB - Build the next great programming language ยท Search ยท v2023 ยท Day 160 ยท Docs ยท Acknowledgements ยท Traffic Today ยท Traffic Trends ยท Mirrors ยท GitHub ยท feedback@pldb.com