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.

1 Like

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: https://github.com/JuliaLang/PackageCompiler.jl/pull/122
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!

1 Like

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: https://github.com/JuliaLang/PackageCompiler.jl/issues/144

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

2 Likes

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.

I’m interested in whether there’s been any progress on this? Are there any nice introductory guides/blogposts about calling compiled Julia libraries from Python? Is it currently easy or hard to do this?

1 Like

pyjulia works really well. It just doesn’t AOT.