OCaml-Python Bindings Generator
Generate Python bindings with pyml directly from OCaml value specifications.
While you could write all your Python bindings by hand, it can be tedious and it gets old real quick. While
pyml_bindgen can't yet auto-generate all the bindings you may need, it can definitely take care of a lot of the tedious and repetitive work you need to do when writing bindings for a big Python library!! 💖
You have a Python class you want to bind and use in OCaml. (Filename:
class Adder: @staticmethod def add(x, y): return x + y
To do so, you write OCaml value specifications for the class and methods you want to bind. (Filename:
val add : x:int -> y:int -> unit -> int
Then, you run
$ pyml_bindgen val_specs.txt adder Adder --caml-module Adder > lib.ml
Now you can use your generated functions in your OCaml code. (Filename:
open Lib let () = Py.initialize () let result = Adder.add ~x:1 ~y:2 () let () = assert (result = 3)
Finally, set up a dune file and run it.
(executable (name run) (libraries pyml))
$ dune exec ./run.exe
For information on installing and using
pyml_bindgen, check out the docs.
Copyright (c) 2021 Ryan M. Moore.
Licensed under the Apache License, Version 2.0 or the MIT license, at your option. This program may not be copied, modified, or distributed except according to those terms.