Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I call OCaml functions from a Python program?

Tags:

python

ocaml

I've got a large legacy program that is written in OCaml, and I'd like to be able to call some OCaml functions from my Python program.

How can I do this the easiest way?

like image 755
ymn Avatar asked Dec 10 '12 05:12

ymn


3 Answers

Directly, no. However, if you create a C API for your Ocaml library, you can call that API via. Python's ctypes module or similar. Likewise, if you expose a network service for your OCaml application, Python can call into that.

like image 165
Yann Ramin Avatar answered Sep 22 '22 23:09

Yann Ramin


You might find useful Pycaml, a Python-OCaml interface allowing to call OCaml functions from Python and vice versa.

Be sure to look for the 2011 or later version, which is based on a 2002 version.

like image 42
jrouquie Avatar answered Sep 20 '22 23:09

jrouquie


Pycaml is no more maintained: nowadays there is pyml and lymp to do that.

pyml: http://pyml.gforge.inria.fr lymp: https://github.com/dbousque/lymp

Both of them are available in opam (opam install pyml lymp). I have not tried them yet, but since I know the author of pyml is very competent, I would bet on that one.

like image 39
ligand Avatar answered Sep 22 '22 23:09

ligand