Reputation: 2153
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?
Upvotes: 7
Views: 2426
Reputation: 4405
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.
Edit: removed link, since 10 years after my answer the hosting moved from http://caml.inria.fr/cgi-bin/hump.en.cgi?contrib=792 to sourceforge. In 10 years, new options might have emerged, for instance a quick search returns pyml.
Upvotes: 8
Reputation: 376
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.
Upvotes: 6
Reputation: 33177
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.
Upvotes: 8