Learning Cython Programming

Learning Cython Programming
eBook: $19.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 15%!
Print + free eBook + free PacktLib access to the book: $52.98    Print cover: $32.99
save 38%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • Extend C applications with pure Python code
  • Expand low-level C open source projects with pure Python – Tmux
  • Get the most out of highly computational Python code using Cython
  • Integrate your C applications with Python Distutils and Automake/Autoconf

Book Details

Language : English
Paperback : 110 pages [ 235mm x 191mm ]
Release Date : September 2013
ISBN : 1783280794
ISBN 13 : 9781783280797
Author(s) : Philip Herron
Topics and Technologies : All Books, Application Development, Big Data and Business Intelligence, Open Source

Table of Contents

Chapter 1: Cython Won't Bite
Chapter 2: Understanding Cython
Chapter 3: Extending Applications
Chapter 4: Debugging Cython
Chapter 5: Advanced Cython
Chapter 6: Further Reading
  • Chapter 1: Cython Won't Bite
    • What this book is
    • What this book isn't
    • Installing Cython
      • The emacs mode
      • Getting the code examples
    • Hello World
    • Module on your own
      • Calling into your C code
        • Type conversion
    • Summary
    • Chapter 2: Understanding Cython
      • Cython cdef
        • Linking models
        • The public keyword
        • Logging into Python
      • Python ConfigParser
      • Cython cdef syntax and usage reference
        • Structs
        • Enums
      • Typedef and function pointers
      • Scalable asynchronous servers
      • C sockets with libevent
        • What is libevent?
        • Messaging engine
        • Cython callbacks
        • Cython PXD
        • Python messaging engine
      • Integration with build systems
        • Python distutils
        • GNU/Autotools
      • Summary
      • Chapter 3: Extending Applications
        • Cython pure Python code
        • Python bindings
        • Python garbage collector
        • Extending Tmux
          • Tmux build system
        • Embedding Python
        • Cythonizing struct cmd_entry
        • Implementing a Tmux command
        • Hooking everything together
        • Compiling pure Python code
        • Summary
        • Chapter 4: Debugging Cython
          • Using GDB on your code
            • Running cygdb
          • General Cython caveats
            • Type checking
            • No * operator
            • Python exceptions in C
            • For loops on C types
            • Bool type
            • No C const
            • Multiple Cython files
            • Initializing struct
          • Calling into pure Python modules
            • Keeping call stacks small and pure
        • Summary
          • Chapter 5: Advanced Cython
            • C++ constructs
              • Namespaces
              • Classes
              • C++ new keyword and allocation
              • Exceptions
              • Bool type
              • Overloading
              • Templates
              • Static class member attribute
            • Caveat on C++ usage
              • Calling in C and C++ functions
              • Namespaces
              • Python distutils
            • Python threading and GIL
              • Atomic instructions
              • Read/write lock
              • Cython keywords
              • Messaging server revisited
            • More inspiration
              • Messaging server working with SQL
              • Python IRC notifier
              • Unit testing the native code
              • Preventing subclassing
              • Cython typing via annotations
            • Parsing large amounts of data
            • Summary
            • Chapter 6: Further Reading
              • Keyword cpdef
              • OpenMP support
              • Object initialization
              • Compile time
              • Python 3
                • Using PyPy
                • AutoPXD
                • Pyrex versus Cython
                • SWIG versus Cython
                • Cython and NumPy
                • Numba versus Cython
                • Parakeet and Numba
                • GCCPy Python frontend to GCC
                • Links and further reading
              • Summary

              Philip Herron

              Philip Herron is an avid software engineer who focuses his passion towards compilers and virtual machine implementations. When he was first accepted to Google Summer of Code 2010, he used inspiration from Paul Biggar's PhD on optimization of dynamic languages to develop a proof of concept GCC frontend to compile Python. This project sparked his deep interest of how Python works. After completing a consecutive year on the same project in 2011, Philip decided to apply for Cython under the Python foundation to gain a deeper appreciation of the standard Python implementation. Through this, he started leveraging the advantages of Python to control the logic in systems or even to add more high-level interfaces such as embedding Twisted web servers for REST calls to a system-level piece of software without writing any C code. Currently Philip is employed by NYSE Euronext in Belfast Northern Ireland, working on multiprocessing systems. But he spends his evenings hacking on GCCPy, Cython, and GCC. In the past, he has worked with WANdisco as an Apache Hadoop developer and as an intern with SAP Research on cloud computing.
              Sorry, we don't have any reviews for this title yet.

              Code Downloads

              Download the code and support files for this book.

              Submit Errata

              Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.

              Sample chapters

              You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

              Frequently bought together

              Learning Cython Programming +    Mastering Web Application Development with AngularJS =
              50% Off
              the second eBook
              Price for both: $32.95

              Buy both these recommended eBooks together and get 50% off the cheapest eBook.

              What you will learn from this book

              • Reuse Python logging in C
              • Make an IRC bot out of your C application
              • Extend an application to have a web server for rest calls
              • Use Cython against your C++ code
              • Reuse Python ConfigParser in C
              • Create Python bindings to native libraries
              • Learn about threading and concurrency related to the GIL
              • Expand Terminal Multiplexer Tmux with Cython

              In Detail

              Cython is a very powerful combination of Python and C. Using Cython, you can write Python code that calls back and forth from and to C or C++ code natively at any point. It is a language with extra syntax allowing for optional static type declarations. It is also a very popular language as it can be used for multicore programming.

              Learning Cython Programming will provide you with a detailed guide to extending your native applications in pure Python; imagine embedding a twisted web server into your native application with pure Python code. You will also learn how to get your new applications up and running by reusing Python’s extensive libraries such as Logging and Config Parser to name a few.

              With Learning Cython Programming, you will learn that writing your own Python module in C from scratch is not only hard, but is also unsafe. Cython will automatically handle all type-conversion issues as well as garbage collection on your code. You can also still write all your code in Python but have it compiled and called directly in C as if it was just another function or data.

              This book also demonstrates how you can take the open source project Tmux and extend it to add new commands directly in pure Python. With this book, you will learn everything you need to know to get up and running with Cython and how you can reuse examples in a practical way.


              A practical and a fast-paced guide that gives you all the information you need to start programming using Cython.

              Who this book is for

              This book is for developers who love C/C++ for low latency and speed but who also require the ability to add more dynamic features to applications both fast and reliably. It will also show you how you can get new applications off the ground by reusing Python libraries to get started.

              Code Download and Errata
              Packt Anytime, Anywhere
              Register Books
              Print Upgrades
              eBook Downloads
              Video Support
              Contact Us
              Awards Voting Nominations Previous Winners
              Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
              Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software