{"id":19031433,"url":"https://github.com/plandes/clj-py4j","last_synced_at":"2025-10-06T13:55:06.512Z","repository":{"id":57478138,"uuid":"110500441","full_name":"plandes/clj-py4j","owner":"plandes","description":"Python to Clojure Bridge using a Py4J Gateway","archived":false,"fork":false,"pushed_at":"2017-12-03T15:59:49.000Z","size":104,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T01:35:21.541Z","etag":null,"topics":["clojure","py4j","python"],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/plandes.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-13T04:33:07.000Z","updated_at":"2023-06-19T12:09:51.000Z","dependencies_parsed_at":"2022-09-18T19:01:14.051Z","dependency_job_id":null,"html_url":"https://github.com/plandes/clj-py4j","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plandes%2Fclj-py4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plandes%2Fclj-py4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plandes%2Fclj-py4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plandes%2Fclj-py4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plandes","download_url":"https://codeload.github.com/plandes/clj-py4j/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249341834,"owners_count":21254195,"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":["clojure","py4j","python"],"created_at":"2024-11-08T21:23:26.467Z","updated_at":"2025-10-06T13:55:01.478Z","avatar_url":"https://github.com/plandes.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python to Clojure Bridge\n\n[![Travis CI Build Status][travis-badge]][travis-link]\n\nPython to Clojure Bridge using a Py4J Gateway.  This simple library aims to\nmake it easy and trivial to invoke [Clojure] from [Python] using the [py4j]\ngateway server and API.\n\nIf you think this sounds convoluted, it is.  However it also solves a lot of\nissues using a JVM API and proxying in the same process.  This method separates\nthe JVM and python in separate processes so they don't step on eachother's feet\n(think memory and resource allocation issues).  On the downside the setup is\nmore complex.\n\nThe end to end request looks like:\n\n1. Invoke the [clojure Python library](python/clojure/api.py).\n2. Marshall the RPC request via the py4j python library\n3. Request is sent via the network\n4. Request received py4j Java Gateway server\n5. `zensols.py4j.gateway` (this library) invokes the actual Clojure request\n6. Return the result back all the way up the chain.\n\n\n\u003c!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc --\u003e\n## Table of Contents\n\n- [Usage](#usage)\n    - [NLP Complex Example](#nlp-complex-example)\n    - [Installing and Running](#installing-and-running)\n- [Obtaining](#obtaining)\n- [Documentation](#documentation)\n- [Binaries](#binaries)\n- [Building](#building)\n- [Changelog](#changelog)\n- [License](#license)\n\n\u003c!-- markdown-toc end --\u003e\n\n\n## Usage\n\nFirst [download, install and run the server](#installing-and-running)\n\n```python\nfrom zensols.clojure import Clojure\n\ndef test():\n    cw = Clojure('taoensso.nippy')\n    try:\n        cw.add_depenedency('com.taoensso', 'nippy', '2.13.0')\n        dat = cw.invoke('freeze', [123, 'strarg', 1.2])\n        thawed = cw.invoke('thaw', dat)\n        for i in thawed:\n            print('thawed item: %s' % i)\n    finally:\n        cw.close()\n\n\u003e\u003e\u003e test()\n\u003e\u003e\u003e thawed item: 123\nthawed item: strarg\nthawed item: 1.2\n```\n\nSee the [test cases](test/python/tests.py) for more examples.\n\n\n### NLP Complex Example\n\nThis example uses the [NLP Clojure Project] parse function.  The `py4jgw`\n(gateway) needs\nthe [models installed](https://github.com/plandes/clj-nlp-parse#setup) and the\nfollowing system property set by adding it to the environment setup script:\n\n```bash\n$ echo 'JAVA_OPTS=\"-Dzensols.model=${HOME}/opt/nlp/model\"' \u003e py4jgw/bin/setupenv\n$ /bin/bash py4jgw/bin/py4jgw\n```\n\nThe following example parses an utterance and prints out what could be used as\nfeatures in a [machine learning](https://github.com/plandes/clj-ml-model)\nmodel:\n\n```python\nimport json\nfrom zensols.clojure import Clojure\n\ndef test():\n    parse = Clojure('zensols.nlparse.parse')\n    cjson = Clojure('clojure.data.json')\n    try:\n        parse.add_depenedency('com.zensols.nlp', 'parse', '0.1.4')\n        cjson.add_depenedency('org.clojure', 'data.json', '0.2.6')\n        panon = parse.invoke('parse', \"\"\"I LOVE Bill Joy and he's the smartest guy in the world!\"\"\")\n        jstr = cjson.invoke('write-str', panon)\n        parsed = json.loads(jstr)\n        print('sentiment: %s' % parsed['sentiment'])\n        ment = parsed['mentions'][0]\n        print(\"'%s' is a %s\" % (ment['text'], ment['ner-tag']))\n        #print(json.dumps(parsed, indent=2, sort_keys=True))\n    finally:\n        parse.close()\n        cjson.close()\n\n\u003e\u003e\u003e test()\n\u003e\u003e\u003e sentiment: 1\n'Bill Joy' is a PERSON\n{\n  \"mentions\": [\n    {\n      \"char-range\": [\n        7, \n        15\n      ], \n\t  ...\n```\n\n\n### Installing and Running\n\n1. Download the binary:\n   `$ wget https://github.com/plandes/clj-py4j/releases/download/v0.0.1/py4jgw.zip`\n2. Extract: `$ unzip py4jgw.zip`\n3. Run the server: `$ /bin/bash ./py4jgw/bin/py4jgw` (or `py4jgw\\bin\\py4jgw.bat`)\n4. Install the Python library: `$ pip install zensols.clojure`\n5. [Hack!](#usage)\n\n\n## Obtaining\n\nIn your `project.clj` file, add:\n\n[![Clojars Project](https://clojars.org/com.zensols.py4j/gateway/latest-version.svg)](https://clojars.org/com.zensols.py4j/gateway/)\n\n### Binaries\n\nThe latest release binaries are\navailable [here](https://github.com/plandes/clj-py4j/releases/latest).\n\n\n## Documentation\n\n* [Clojure](https://plandes.github.io/clj-py4j/codox/index.html)\n* [Java](https://plandes.github.io/clj-py4j/apidocs/index.html)\n\n\n## Building\n\nTo build from source, do the folling:\n\n- Install [Leiningen](http://leiningen.org) (this is just a script)\n- Install [GNU make](https://www.gnu.org/software/make/)\n- Install [Git](https://git-scm.com)\n- Download the source: `git clone https://github.com/plandes/clj-py4j \u0026\u0026 cd clj-py4j`\n- Download the make include files:\n```bash\nmkdir ../clj-zenbuild \u0026\u0026 wget -O - https://api.github.com/repos/plandes/clj-zenbuild/tarball | tar zxfv - -C ../clj-zenbuild --strip-components 1\n```\n- Build the software: `make jar`\n- Build the distribution binaries: `make dist`\n- Build the Python egg/wheel distribution libraries: `make pydist`\n\nNote that you can also build a single jar file with all the dependencies with: `make uber`\n\n\n## Changelog\n\nAn extensive changelog is available [here](CHANGELOG.md).\n\n\n## License\n\nCopyright © 2017 Paul Landes\n\nApache License version 2.0\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n\n\u003c!-- links--\u003e\n\n[NLP Clojure Project]: https://github.com/plandes/clj-nlp-parse\n[py4j]: https://www.py4j.org\n[Clojure]: https://clojure.org\n[Python]: https://www.python.org\n[travis-link]: https://travis-ci.org/plandes/clj-py4j\n[travis-badge]: https://travis-ci.org/plandes/clj-py4j.svg?branch=master\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplandes%2Fclj-py4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplandes%2Fclj-py4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplandes%2Fclj-py4j/lists"}