# \[ANN\] ocaml-in-python.0.1.0: Effortless Python bindings for OCaml modules

**URL:** <https://discuss.ocaml.org/t/ann-ocaml-in-python-0-1-0-effortless-python-bindings-for-ocaml-modules/9603>\
**Category:** Ecosystem\
**Tags:** bindings, python, announce\
**Created:** [March 28, 2022, 10:33pm UTC](https://discuss.ocaml.org/t/ann-ocaml-in-python-0-1-0-effortless-python-bindings-for-ocaml-modules/9603 "2022-03-28T22:33:53Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![thierry-martinez](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/thierry-martinez/32/1481_2.png) [@thierry-martinez](https://discuss.ocaml.org/u/thierry-martinez)\
**Post date:** [March 28, 2022, 10:33pm UTC](https://discuss.ocaml.org/t/ann-ocaml-in-python-0-1-0-effortless-python-bindings-for-ocaml-modules/9603/1 "2022-03-28T22:33:53Z")

</div>

I am happy to announce the first release of `ocaml-in-python`: this is a Python package that exposes all OCaml modules as Python libraries, generating bindings on the fly. This can be seen as a dual of [`pyml_bindgen`](https://discuss.ocaml.org/t/ann-pyml-bindgen-a-cli-app-to-generate-python-bindings-directly-from-ocaml-value-specifications/8786): `pyml_bindgen` binds Python libraries in OCaml, while `ocaml-in-python` binds OCaml modules in Python.

It is available from [GitHub](https://github.com/thierry-martinez/ocaml-in-python) or _via_ `opam`: `opam install ocaml-in-python`

Requirements: `OCaml` \>= 4.13, `Python` \>= 3.7.

Once installed _via_ `opam`, the package should be registered in the Python environment:

- either by registering the package with `pip` using the following command (requires Python \>=3.8):

```bash
pip install --editable "`opam var ocaml-in-python:lib`"

```

- or by adding the following definition to the environment:

```bash
export PYTHONPATH="`opam var share`/python/:$PYTHONPATH"

```

Then, we can `import ocaml` in Python and use OCaml modules:

```python
Python 3.10.0 (default, Nov 10 2021, 19:16:14) [GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ocaml
>>> print(ocaml.List.map((lambda x : x + 1), [1, 2, 3]))
[2;3;4]

```

We can for instance compile an OCaml module on the fly from Python.

```python
>>> m = ocaml.compile('let hello x = Printf.printf "Hello, %s!\n%!" x')
>>> m.hello('world')
Hello, world!

```

And we can require and use packages _via_ `findlib`.

```python
>>> ocaml.require("parmap")
>>> from ocaml import Parmap
>>> print(Parmap.parmap(
... (lambda x : x + 1), Parmap.A([1, 2, 3]), ncores=2))
[2;3;4]

```

Details about the conversions are given in [`README.md`](https://github.com/thierry-martinez/ocaml-in-python/blob/main/README.md).

Happy hacking!

---

_[View the full topic](https://discuss.ocaml.org/t/ann-ocaml-in-python-0-1-0-effortless-python-bindings-for-ocaml-modules/9603)._
