Calling Julia compiled library from Python


As described in the blog post “” and implemented in PackageCompiler.jl, it is possible to compile Julia programs statically into a shared library. However, are there any examples of then calling this compiled library (.so file) from Python? Would it be the same as Python calling a compiled C library?

My question comes from a place of ignorance. Specifically, I’m unclear about:

  • What a .so file actually is
  • If Python cares about the source language of a .so file
  • What types of interfaces does a .so file allow for

I will be trying to answer these sub-questions myself and have rephrased them as a StackOverflow question, but I thought I would ask here first and document my learning journey.


By now, one mainly needs to figure out how to add a C extension in python I think:

The other issue I run into when creating that PR was likely fixed by:
So the only difference from other .so should be, that you need to make sure to initialize the Julia runtime, which got a lot easier with the above PR!


This is amazing! I don’t fully understand it do my aforementioned ignorance, but hopefully after digging into this topic I’ll be able to review/test the PR and give you meaningful feedback.


If you want to use Python ctypes, I don’t think this PR is enough. See:

For a complete example using Python ctypes, see: AOT compiling using PackageCompiler


Just in case you are not aware of pyjulia. I know it’s not what you asked for but it is the trivial way of calling julia from python.