{"id":16743945,"url":"https://github.com/zshipko/ocaml-py","last_synced_at":"2025-03-17T01:32:12.754Z","repository":{"id":79820996,"uuid":"93285457","full_name":"zshipko/ocaml-py","owner":"zshipko","description":"Python 3.5+ bindings for OCaml","archived":false,"fork":false,"pushed_at":"2024-03-29T02:07:40.000Z","size":159,"stargazers_count":57,"open_issues_count":1,"forks_count":4,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-02-27T16:38:33.241Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zshipko.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-04T02:30:59.000Z","updated_at":"2024-03-26T03:06:49.000Z","dependencies_parsed_at":"2024-03-29T03:23:53.925Z","dependency_job_id":"7541c560-39d3-4ea5-8118-b837b495889e","html_url":"https://github.com/zshipko/ocaml-py","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zshipko%2Focaml-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zshipko%2Focaml-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zshipko%2Focaml-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zshipko%2Focaml-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zshipko","download_url":"https://codeload.github.com/zshipko/ocaml-py/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243836975,"owners_count":20355805,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T01:42:02.946Z","updated_at":"2025-03-17T01:32:12.468Z","avatar_url":"https://github.com/zshipko.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"py — OCaml interface to Python\n-------------------------------------------------------------------------------\n%%VERSION%%\n\npy is a ctypes interface to Python 3.5+ for OCaml\n\npy is distributed under the ISC license.\n\nHomepage: https://github.com/zshipko/ocaml-py\n\n## Installation\n\npy can be installed with `opam`:\n\n```shell\n$ opam install py\n```\n\nIf your Python installation is not in the typical location you may have to set `OCAML_PY_VERSION` to point to the Python `.so` file.\n\nFor example, one way of finding this path:\n\n```shell\n$ find `python3 -c 'import sys, os; print(os.path.join(sys.prefix, \"lib\"))'` -name 'libpython*.so'\n```\n\n(That seems to be the most straight forward way, but let me know if there's something better!)\n\nIf you'd like to run the tests:\n\n```shell\n$ dune runtest\n```\n\n## Introduction\n\nSimple conversion from OCaml to Python:\n```ocaml\n    open Py\n    let s = !$(String \"a string\")\n    let f = !$(Float 12.3)\n    let i = !$(Int 123)\n```\nSee `src/py.mli` for a full list of types.\n\nCall a function defined in a module and return the result:\n```ocaml\n    let np = PyModule.import \"numpy\" in\n    let np_array = np $. (String \"array\") in\n    let arr = np_array $ [List [Int 1; Int 2; Int 3]] in\n    ...\n```\nWhich is shorthand for\n```ocaml\n    let np = PyModule.import \"numpy\" in\n    let np_array = Object.get_attr_s np \"array\" in\n    let arr = run np_array [List [Int 1; Int 2; Int 3]] in\n    ...\n```\nEvaluate a string and return the result:\n```ocaml\n    let arr = eval \"[1, 2, 3]\" in\n    ...\n```\nGet object index:\n```ocaml\n    let a = arr $| Int 0 in\n    let b = arr $| Int 1 in\n    let c = arr $| Int 2 in\n    ...\n```\nSet object index:\n```ocaml\n    let _ = (a_list, Int 0) \u003c-$| Int 123 in\n    let _ = (a_dict, String \"key\") \u003c-$| String \"value\" in\n    ...\n```\nExecute a string and return true/false depending on the status returned by Python:\n```ocaml\n    if exec \"import tensorflow\" then\n        let tf = PyModule.get \"tensorflow\" in  (* Load an existing module *)\n        ...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzshipko%2Focaml-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzshipko%2Focaml-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzshipko%2Focaml-py/lists"}