package pyml_bindgen
Install
Dune Dependency
Authors
Maintainers
Sources
md5=69d7838ad3a32865974aa911d095e114
sha512=e84e7028c8bf573748655dd572c24bbe649641bee97c28976a6d9553ed28d5366f76158c191db466318862b4127bdab6efa7779d900639943034de7f7526a490
Description
Published: 09 Nov 2021
README
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!! 💖
Quick start
You have a Python class you want to bind and use in OCaml. (Filename: adder.py
)
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_specs.txt
)
val add : x:int -> y:int -> unit -> int
Then, you run pyml_bindgen
.
$ pyml_bindgen val_specs.txt adder Adder --caml-module Adder > lib.ml
Now you can use your generated functions in your OCaml code. (Filename: run.ml
)
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
Documentation
For information on installing and using pyml_bindgen
, check out the docs.
License
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.
Dependencies (10)
-
ocaml
>= "4.08.0"
-
stdio
>= "v0.12"
-
re2
>= "v0.12"
-
ppx_string
>= "v0.12"
-
ppx_sexp_conv
>= "v0.12"
-
ppx_let
>= "v0.12"
-
cmdliner
>= "1.0"
-
base
>= "v0.12" & < "v0.17.0"
-
angstrom
>= "0.15.0"
-
dune
>= "2.8"
Dev Dependencies (10)
-
odoc
with-doc
-
bisect_ppx
dev
-
pyml
with-test
-
ppx_expect
>= "v0.12" & with-test
-
ppx_inline_test
>= "v0.12" & with-test
-
ocamlformat
with-test & < "0.20.0"
-
core_kernel
>= "v0.12" & with-test
-
conf-python-3-dev
>= "1" & with-test
-
cmdliner
with-test & < "1.1.0"
-
dune
with-test & < "3.0"
Used by
None
Conflicts
None