pyml_bindgen

Generate pyml bindings from OCaml value specifications
README

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

First, install pyml_bindgen. It is available on Opam.

$ opam install pyml_bindgen

Say 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.

Additionally, you can find examples in the examples directory. One neat thing about these examples is that you can see how to write Dune rules to automatically generate your pyml bindings.

Installing from sources

If you want to install from sources, e.g., to track the main branch or a development branch, but you do not want to install all the test and development packages, clone the repository, checkout the branch you want to follow and run opam install manually:

$ git clone https://github.com/mooreryan/ocaml_python_bindgen.git
$ git checkout dev
$ opam install .

This will save a lot of install time as it avoids some heavy packages.

Development

If instead, you want to work on pyml_bindgen development, will need to ensure you have the test dependencies, as well as a couple dependencies that are not included in the opam file (core, core_bench, and bisect_ppx.)

E.g.,

$ git clone https://github.com/mooreryan/ocaml_python_bindgen.git
$ opam install . --deps-only --with-doc --with-test
$ opam install core core_bench bisect_ppx
$ dune build

License

Copyright (c) 2021 - 2022 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.

Install
Maintainers
Sources
0.3.1.tar.gz
md5=2bb36f386295245d54f316537a18ee62
sha512=24d89eba6acb6c97fb86bca40d10578a3f65325b04532df3d2bed2458f88bb424ed91802eccf098db050914db8aaff8ba0e15579c5abe9a5a37bee3307ed1b3c
Dependencies
odoc
with-doc
shexp
>= "v0.14" & with-test
pyml
with-test
ppx_expect
>= "v0.12" & with-test
ppx_inline_test
>= "v0.12" & with-test
ppx_assert
>= "v0.12" & with-test
ocamlformat
>= "0.20.0" & < "0.21.0" & with-test
core_kernel
>= "v0.12" & with-test
conf-python-3-dev
>= "1" & with-test
cmdliner
= "1.1.0" & with-test
ocaml
>= "4.08.0"
stdio
>= "v0.12"
re
>= "1.10.0"
ppx_string
>= "v0.12"
ppx_sexp_conv
>= "v0.12"
ppx_let
>= "v0.12"
cmdliner
>= "1.1.0"
base
>= "v0.12"
angstrom
>= "0.15.0"
dune
>= "3.0"
Reverse Dependencies