package py
Build not checkedInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=15063002d47dca99878b0cd8f812f6a05f038126ccd0db67539cc3b8ca579ab2
md5=e924b70d6cfcec304a7416d5bee0500d
Description
Py provides a nice interface for interacting with Python libraries in OCaml
README
py — OCaml interface to Python
%%VERSION%%
py is a ctypes interface to Python 3 for OCaml
py is distributed under the ISC license.
Homepage: https://github.com/zshipko/ocaml-py
Installation
py can be installed with opam:
opam install pyIf you don't use opam consult the opam file for build instructions.
Introduction
Simple conversion from OCaml to Python:
open Py
let s = !$(String "a string")
let f = !$(Float 12.3)
let i = !$(Int 123)See src/py.mli for a full list of types.
Call a function defined in a module and return the result:
let np = PyModule.import "numpy" in
let np_array = np $. (String "array") in
let arr = np_array $ [List [Int 1; Int 2; Int 3]] in
...Which is shorthand for
let np = PyModule.import "numpy" in
let np_array = Object.get_attr_s np "array" in
let arr = run np_array [List [Int 1; Int 2; Int 3]] in
...Evaluate a string and return the result:
let arr = eval "[1, 2, 3]" in
...Get object index:
let a = arr $| Int 0 in
let b = arr $| Int 1 in
let c = arr $| Int 2 in
...Set object index:
let _ = (a_list, Int 0) <-$| Int 123 in
let _ = (a_dict, String "key") <-$| String "value" in
...Execute a string and return true/false depending on the status returned by Python:
if exec "import tensorflow" then
let tf = PyModule.get "tensorflow" in (* Load an existing module *)
...Sample programs
If you installed py with opam sample programs are located in the directory opam var py:doc.
In the distribution sample programs and tests are located in the test directory. They can be built and run with:
topkg build --tests true && topkg test
Dependencies (6)
-
ctypes-foreign
>= "0.4.0" -
ctypes
>= "0.13.0" & < "0.18.0" -
topkg
build & >= "0.9.1" -
ocamlbuild
build -
ocamlfind
build -
ocaml
>= "4.03.0"
Dev Dependencies
None
Optional Dependencies
None
Used by
None
Conflicts
None
Build status
Results of building py with each compiler on check.ci.ocaml.org, run of against opam-repository 78c202b. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
This version is not in the latest run; the versions below are.
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure