Blog

We offer the articles below in the hope that they will be useful, but we cannot accept liability for any problems caused by the instructions that they contain. If you have a problem, question or feedback relating to one of our articles, please post a comment so that other readers can benefit. We regularly review comments and reply or update the articles, to ensure their continued usefulness. All articles are provided free, without any advertising or tracking, for the benefit of the technical community.

If you require paid commercial support, please contact us for assistance.

Please note that AI scraping of our content is expressly forbidden. We are in favour of responsible AI, which includes compensating creators fairly for use of their work. Just because it’s freely available to read, does not mean that it is freely available for unlicenced commercial use. We retain copyright of all of our content. If you wish to licence our content for AI training or similar purposes, or wish to hire us to write technical documentation, please contact us.

Compiling mixed Sage and Python code with Cython

At the moment I’m working on some maths code written in a combination of standard Python and its mathematical superset, Sage. The code is fairly computationally expensive (it’s essentially a brute force search for chemical reaction networks that are monotone). Consequently, after getting the code working as a proof-of-concept, I wanted to compile it to C using Cython to get a bit more speed out of it. I found the documentation on converting Sage and Python scripts to Cython a bit vague, particularly when it comes to combining the two, so this article gives step by step instructions based on my findings.