title: How to compile a whole Python library (including dependencies) so that it can be used in C?
body: <p>How to compile a whole Python library along with it's dependencies so that it can be used in C (without invoking Python's runtime). That is, the compiled code has the Python interpreter embedded and Python does not need to be installed on the system.</p>
  
  <p>From my understanding, when Python code is compiled using Cython it:</p>
  
  <ul>
  <li>Does not invoke the python runtime if the <code>--embed</code> argument is used</li>
  <li>Compiles files individually</li>
  <li>Allows for different modules to be called (from the Python runtime / other compiled Cython files)</li>
  </ul>
  
  <p>The question which are still unclear are:</p>
  
  <ul>
  <li>How to use these module files from C? Can the compiled Python files call other compiled Python files when used in C?</li>
  <li>Does only the library entry point need to be declared or do all functions need to be declared? </li>
  <li>How to manage the Python dependencies? how to compile them too (so that the Python runtime is not needed). </li>
  </ul>
  
  <p>A simplified example for a python library called <code>module</code> where <code>__init__.py</code> is an empty file:</p>
  
  <pre><code>module/
  ├── run.py
  ├── http/
  │   ├── __init__.py
  │   ├── http_request.py
  </code></pre>
  
  <p><code>http_requests.py</code> contains:</p>
  
  <pre><code>import requests
  
  def get_ip():
      r = requests.get('https://ipinfo.io/ip')
      print(r.text)
  </code></pre>
  
  <p>and <code>run.py</code> contains the following:</p>
  
  <pre><code>from http import http_request
  
  if __name__ == '__main__':
      http_request.get_ip()
  </code></pre>
  
  <p>How to call the function <code>get_ip</code> from C without using the Python runtime (needing to have Python installed when running the application).</p>
  
  <p>The above example is very simple. The actual use case is collecting/processing robotics data in C at a high sampling rate. Whilst C is great for basic data processing there are excellent Python libraries which allow for much more comprehensive analysis. The objective would be to call the Python libraries on data which has been partially processed in C. This would allow us to get a much more detailed understanding of the data (and process it in "real time"). The data frameworks are way too large for our team to rewrite in C.</p>