# Calling Julia compiled library from Python

**URL:** <https://discourse.julialang.org/t/calling-julia-compiled-library-from-python/18157>\
**Category:** General Usage\
**Created:** [November 29, 2018, 5:45pm UTC](https://discourse.julialang.org/t/calling-julia-compiled-library-from-python/18157 "2018-11-29T17:45:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seanny123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/seanny123/32/5271_2.png) [@Seanny123](https://discourse.julialang.org/u/Seanny123)\
**Post date:** [November 29, 2018, 5:45pm UTC](https://discourse.julialang.org/t/calling-julia-compiled-library-from-python/18157/1 "2018-11-29T17:45:54Z")

</div>

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](https://stackoverflow.com/q/53545638/1079075), but I thought I would ask here first and document my learning journey.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [November 29, 2018, 7:00pm UTC](https://discourse.julialang.org/t/calling-julia-compiled-library-from-python/18157/2 "2018-11-29T19:00:15Z")

</div>

By now, one mainly needs to figure out how to add a C extension in python I think:  
[https://github.com/JuliaLang/PackageCompiler.jl/pull/26](https://github.com/JuliaLang/PackageCompiler.jl/pull/26)  
The other issue I run into when creating that PR was likely fixed by: [https://github.com/JuliaLang/PackageCompiler.jl/pull/122](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!

---

<div class="post-metadata">

**Author:** ![Seanny123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/seanny123/32/5271_2.png) [@Seanny123](https://discourse.julialang.org/u/Seanny123)\
**Post date:** [November 29, 2018, 7:06pm UTC](https://discourse.julialang.org/t/calling-julia-compiled-library-from-python/18157/3 "2018-11-29T19:06:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [November 30, 2018, 1:40am UTC](https://discourse.julialang.org/t/calling-julia-compiled-library-from-python/18157/4 "2018-11-30T01:40:14Z")

</div>

> [@sdanisch](#):
>
> The other issue I run into when creating that PR was likely fixed by: [https://github.com/JuliaLang/PackageCompiler.jl/pull/122](https://github.com/JuliaLang/PackageCompiler.jl/pull/122)

If you want to use Python ctypes, I don’t think this PR is enough. See: [init\_jl\_runtime does not work with Python ctypes · Issue #144 · JuliaLang/PackageCompiler.jl · GitHub](https://github.com/JuliaLang/PackageCompiler.jl/issues/144)

For a complete example using Python ctypes, see: [AOT compiling using PackageCompiler - #8 by tkf](https://discourse.julialang.org/t/aot-compiling-using-packagecompiler/16911/8)

---

<div class="post-metadata">

**Author:** ![Tero\_Frondelius](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tero_frondelius/32/7629_2.png) [@Tero\_Frondelius](https://discourse.julialang.org/u/Tero_Frondelius)\
**Post date:** [December 1, 2018, 9:28pm UTC](https://discourse.julialang.org/t/calling-julia-compiled-library-from-python/18157/5 "2018-12-01T21:28:05Z")

</div>

Just in case you are not aware of [pyjulia](https://github.com/JuliaPy/pyjulia). I know it’s not what you asked for but it is the trivial way of calling julia from python.

---

<div class="post-metadata">

**Author:** ![drbenvincent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drbenvincent/32/3046_2.png) [@drbenvincent](https://discourse.julialang.org/u/drbenvincent)\
**Post date:** [September 3, 2019, 6:18pm UTC](https://discourse.julialang.org/t/calling-julia-compiled-library-from-python/18157/6 "2019-09-03T18:18:01Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [September 3, 2019, 6:56pm UTC](https://discourse.julialang.org/t/calling-julia-compiled-library-from-python/18157/7 "2019-09-03T18:56:35Z")

</div>

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