Home Ask Login Register

Developers Planet

Your answer is one click away!

particleq February 2016

clojure working with scipy and numpy

Is there any good way to call python from clojure as a means of doing data science with scipy, numpy, scikit-learn, etc.

I know about implementations of clojure which run on python instead of java, but this doeesn't work for me, as I also need to call java libraries in my project. I also know about Jython, but I don't know of a clean way to use this with Clojure.

I want to use Clojure in my projects because I prefer it as a language, but I can't deny that Python has an incredible community, and some of the most beautiful, well-designed libraries around.


LearningStuff February 2016

I'm not directly familiar with it but you can Macgyver a file which closure writes\reads too and that python is reads\writes too. Can pretty much do this to everything.

muhuk February 2016

Instead of trying to get Jython to play well with both Clojure and numpy/scipy, you can use Hy. It is hosted on Python and it somewhat resembles Clojure.

If I really wanted to use numpy/scipy, I would write the backend in Python (or Hy), run it as a separate service. And if I really like ring for instance, or can't live without Instaparse, I would write a frontend in Clojure.

As an aside Python has EDN libs. It would be an interesting project to integrate one of them in Hy, or write one from scratch.

pneumatics February 2016

Give the toolz library a try, it's a functional standard library for Python that was designed to generally adhere to the API of the Clojure standard library.

Apart from that, I'd encourage you to find the seams between your computations, and write individual tools in the Unix way in either Clojure or Python depending on which seems to fit that use case best. Serialize data between the tools, either as text/JSON through pipes or using a binary serialization format like Protobuf, which has standard APIs for both Java and Python.

If you had a gun to my head and told me to build Clojure/Python interop, I'd start with py4j and bridge the two languages through Java interfaces, using implements members in a Python class and reify on the Clojure side.

Post Status

Asked in February 2016
Viewed 2,571 times
Voted 5
Answered 3 times


Leave an answer

Quote of the day: live life