package pyml_bindgen

  1. Overview
  2. Docs
Generate pyml bindings from OCaml value specifications

Install

Dune Dependency

Authors

Maintainers

Sources

0.2.0.tar.gz
md5=4d65d6e7e749ed6cfe16072f1dbf3dfe
sha512=a1c0c6067f5f782f79f51d75721040d65582270fb9cd223c2ff85cb8e80c28dc44fc850768618b24a1bbf76a9715ffbac55f01848088ddf98cb94285fbdd7187

Description

Published: 04 Feb 2022

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

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.

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)

  1. ocaml >= "4.08.0"
  2. stdio >= "v0.12"
  3. re2 >= "v0.12"
  4. ppx_string >= "v0.12"
  5. ppx_sexp_conv >= "v0.12"
  6. ppx_let >= "v0.12"
  7. cmdliner >= "1.0"
  8. base >= "v0.12" & < "v0.17.0"
  9. angstrom >= "0.15.0"
  10. dune >= "2.8"

Dev Dependencies (13)

  1. odoc with-doc
  2. core_bench >= "v0.12" & dev
  3. core >= "v0.12" & dev
  4. bisect_ppx dev
  5. pyml with-test
  6. ppx_expect >= "v0.12" & with-test
  7. ppx_inline_test >= "v0.12" & with-test
  8. ppx_assert >= "v0.12" & with-test
  9. ocamlformat >= "0.20.0" & < "0.21.0" & with-test
  10. core_kernel >= "v0.12" & with-test
  11. conf-python-3-dev >= "1" & with-test
  12. cmdliner with-test & < "1.1.0"
  13. dune with-test & < "3.0"

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.