Learning Cython Programming - Second Edition
eBook - ePub

Learning Cython Programming - Second Edition

Philip Herron

Share book
  1. 110 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Learning Cython Programming - Second Edition

Philip Herron

Book details
Book preview
Table of contents
Citations

About This Book

Learn the fundamentals of Cython to extend the legacy of your applicationsAbout This Bookā€¢ Learn how to extend C applications with pure Python codeā€¢ Get more from Python ā€“ you'll not only learn Cython, you'll also unlock a greater understanding of how to harness Pythonā€¢ Packed with tips and tricks that make Cython look easy, dive into this accessible programming guide and find out what happens when you bring C and Python together!Who This Book Is ForThis book is for developers who are familiar with the basics of C and Python programming and wish to learn Cython programming to extend their applications.What You Will Learnā€¢ Reuse Python logging in Cā€¢ Make an IRC bot out of your C applicationā€¢ Extend an application so you have a web server for rest callsā€¢ Practice Cython against your C++ codeā€¢ Discover tricks to work with Python ConfigParser in Cā€¢ Create Python bindings for native librariesā€¢ Find out about threading and concurrency related to GILā€¢ Expand Terminal Multiplexer Tmux with CythonIn DetailCython is a hybrid programming language used to write C extensions for Python language. Combining the practicality of Python and speed and ease of the C language it's an exciting language worth learning if you want to build fast applications with ease.This new edition of Learning Cython Programming shows you how to get started, taking you through the fundamentals so you can begin to experience its unique powers.You'll find out how to get set up, before exploring the relationship between Python and Cython. You'll also look at debugging Cython, before moving on to C++ constructs, Caveat on C++ usage, Python threading and GIL in Cython. Finally, you'll learn object initialization and compile time, and gain a deeper insight into Python 3, which will help you not only become a confident Cython developer, but a much more fluent Python developer too.Style and approachThis practical and a fast-paced guide gives you all the information you need to start programming using Cython.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on ā€œCancel Subscriptionā€ - itā€™s as simple as that. After you cancel, your membership will stay active for the remainder of the time youā€™ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlegoā€™s features. The only differences are the price and subscription period: With the annual plan youā€™ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weā€™ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Learning Cython Programming - Second Edition an online PDF/ePUB?
Yes, you can access Learning Cython Programming - Second Edition by Philip Herron in PDF and/or ePUB format, as well as other popular books in Informatique & Programmation en Python. We have over one million books available in our catalogue for you to explore.

Information

Year
2016
ISBN
9781785289125

Learning Cython Programming Second Edition


Table of Contents

Learning Cython Programming Second Edition
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Cython Won't Bite
Installing Cython
Emacs mode
Getting the code examples
Getting started ā€“ Hello World
Using distutils with Cython
Calling C functions from Python
Type conversion in Cython
Summary
2. Understanding Cython
Linking models
Cython keyword ā€“ cdef
Structs
Enums
Typedef and function pointers
The public keyword
Keyword cpdef
Logging from C/C++ into Python
Using Python ConfigParser from C/C++
Callbacks from Python to C/C++
Cython PXD
Integration with build systems
Python Distutils
GNU/Autotools
Summary
3. Extending Applications
Cython pure Python code
Compiling pure Python code
Avoid Makefiles ā€“ pyximport
Python garbage collector
Extending Tmux
Tmux build system
Embedding Python
Cythonizing struct cmd_entry
Implementing a Tmux command
Hooking everything together
Summary
4. Debugging Cython
Using GDB with Cython
Running cygdb
Cython caveats
Type checking
Dereference operator (*)
Python exceptions
C/C++ iterators
Boolean error
Const keyword
Multiple Cython inputs
Struct initialization
Calling into pure Python modules
Summary
5. Advanced Cython
Cython and C++
Namespaces
Classes
C++ new and del keyword
Exceptions
Bool type
Overloading
Templates
Static class member attribute
Calling C++ functions ā€“ Caveat
Namespaces ā€“ Caveat
Python distutils
Python threading and GIL
Atomic instructions
Read/write lock
Cython keywords
Messaging server
Caveat on GIL
Unit testing the native code
Preventing subclassing
Parsing large amounts of data
Summary
6. Further Reading
Overview
OpenMP support
Compile time preprocessor
Python 3
PyPy
AutoPXD
Pyrex and Cython
SWIG and Cython
Cython and NumPy
Numba versus Cython
Parakeet and Numba
Relevant Links
Summary
Index

Learning Cython Programming Second Edition

Copyright Ā© 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: September 2013
Second Edition: February 2016
Production reference: 1160216
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78355-167-5
www.packtpub.com

Credits

Author
Philip Herron
Reviewer
Namit Kewat
Commissioning Editor
Priya Singh
Acquisition Editor
Indrajit Das
Content Development Editor
Priyanka Mehta
Technical Editor
Murtaza Tinwala
Copy Editor
Yesha Gangani
Project Coordinator
Izzat Contractor
Proofreader
Safis Editing
Indexer
Tejal Daruwale Soni
Production Coordinator
Manu Joseph
Cover Work
Manu Joseph

About the Author

Philip Herron is a developer who focuses his passion toward 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 the optimization of dynamic languages to develop a proof of the concept GCC frontend to compile Python. This project sparked his deep interest in how Python works.
After completing a consecutive year on the same project in 2011, Philip applied to 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 add more high-level interfaces, such as embedding Flask web servers in a REST API to a system-level piece of software, without writing any C code.
Philip currently works as a software consultant for Instil Software based in Northern Ireland. He develops mobile applications with embedded native code for video streaming. Instil has given him a lot of support in becoming a better engineer.
He has written several tutorials for the UK-based Linux Format magazine on Python and loves to share his passion for the Python programming language.

Acknowledgments

To achieve writing this book, I would like to thank many peopleā€”my partner, Kirsty Johnston, for putting up with my late nights and giving me the confidence I needed; she is the best! I would like to thank my mum and dad, who have always supported me my whole lifeā€”thanks for helping me so much. Ian Lance Taylor, my mentor, from Google Summer of Code deserves a special mention. If it wasn't for him, I wouldn't be writing anything like this right now. I would like to thank Robert Bradshaw for mentoring my Cytho...

Table of contents