# Multi-language (Julia + Python) coding : data transfer in a two-step simulation

**URL:** <https://discourse.julialang.org/t/multi-language-julia-python-coding-data-transfer-in-a-two-step-simulation/100649>\
**Category:** New to Julia\
**Created:** [June 21, 2023, 1:10pm UTC](https://discourse.julialang.org/t/multi-language-julia-python-coding-data-transfer-in-a-two-step-simulation/100649 "2023-06-21T13:10:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![amuesser](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amuesser/32/50917_2.png) [@amuesser](https://discourse.julialang.org/u/amuesser)\
**Post date:** [June 21, 2023, 1:10pm UTC](https://discourse.julialang.org/t/multi-language-julia-python-coding-data-transfer-in-a-two-step-simulation/100649/1 "2023-06-21T13:10:39Z")

</div>

Hi everyone,

I’m currently working on coupling two models for lung simulation: a first model coded in Python that calculates the evolution of pressure in the respiratory system using finite elements, and a second model coded in Julia that focuses more specifically on volumic transfers from alveoli to blood.

Thus, in my simulation, an increment proceeds as follows:

- First, the first Python model calculates the pressures at the ends of the respiratory system.
- Then, these pressures are read as initial conditions for the second Julia model, which calculates volumes at the alveoli.
- Finally, the first model is updated with the Julia data, and the next increment can begin.

My problem is that during the same increment, I read a line from a volumes.csv file, calculate with my Python model, write a line to another pressures.csv file, read the pressures.csv file, calculate with my Julia model, and finally write to the volumes.csv file.

Do you know of a more suitable way of storing this data and transferring it from one model to another?

Thanks in advance for your reply, and have a nice day,

---

<div class="post-metadata">

**Author:** ![frylock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frylock/32/50213_2.png) [@frylock](https://discourse.julialang.org/u/frylock)\
**Post date:** [June 21, 2023, 1:18pm UTC](https://discourse.julialang.org/t/multi-language-julia-python-coding-data-transfer-in-a-two-step-simulation/100649/2 "2023-06-21T13:18:05Z")

</div>

If you’re fond of NumPy, you can use the [NPZ.jl](https://github.com/fhs/NPZ.jl) package in Julia to interoperate.

Where I work, we also make extensive use of [NetCDF](https://github.com/JuliaGeo/NetCDF.jl) and [HDF5](https://juliaio.github.io/HDF5.jl/stable/), which are both popular and language-agnostic.

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [June 21, 2023, 1:38pm UTC](https://discourse.julialang.org/t/multi-language-julia-python-coding-data-transfer-in-a-two-step-simulation/100649/3 "2023-06-21T13:38:52Z")

</div>

You should definitely check out [GitHub - cjdoris/PythonCall.jl: Python and Julia in harmony.](https://github.com/cjdoris/PythonCall.jl)

---

<div class="post-metadata">

**Author:** ![xgdgsc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xgdgsc/32/608_2.png) [@xgdgsc](https://discourse.julialang.org/u/xgdgsc)\
**Post date:** [June 21, 2023, 3:11pm UTC](https://discourse.julialang.org/t/multi-language-julia-python-coding-data-transfer-in-a-two-step-simulation/100649/4 "2023-06-21T15:11:57Z")

</div>

Writing a python extension with [GitHub - Suzhou-Tongyuan/jnumpy: Writing Python C extensions in Julia within 5 minutes.](https://github.com/Suzhou-Tongyuan/jnumpy) is very easy, just exchange the numpy array directly.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 21, 2023, 6:27pm UTC](https://discourse.julialang.org/t/multi-language-julia-python-coding-data-transfer-in-a-two-step-simulation/100649/5 "2023-06-21T18:27:15Z")

</div>

> [@amuesser](#):
>
> Do you know of a more suitable way of storing this data and transferring it from one model to another?

Don’t exchange the data via files. Call between languages directly using PyCall or PythonCall.
