How to call scala from python? - python

I would like to build my project in Scala and then use it in a script in Python for my data hacking (as a module or something like that). I have seen that there are ways to integrate python code into JVM languages with Jython (only Python 2 projects though). What I want to do is the other way around though. I found no information on the net how to do this, but it seems strange that this should not be possible.

General solution -- use some RPC/IPC (sockets, protobuf, whatever).
However, you might want to look at Spark's solution -- how they translate Python code in Scala's APIs (https://www.py4j.org/) .

Recently, scalapy was created to call Python libraries from Scala.
https://github.com/shadaj/scalapy

Related

Is there a way to create Eclipse plugins with Python?

As far as I understand Eclipse doesn't provide user with python bindings by default. Nor any projects of such kind was I able to find with google.
Are there any third-party plugins for that? Any tutorial? May be with Jython?..
As far as I know, you need to use Java. Eclipse is written in Java, and even the vanilla application is made up of several Java components glued together by the core plugin loader. Jython might work if:
you can cross-compile Python to Java bytecode (indeed you can, thanks to sayth for pointing that out), and
you can access the Eclipse APIs inside Jython.
So, here's more or less what your plugin's architecture might look like. If you can get at the Eclipse APIs, then you can write most of it in Jython, and then make a Java wrapper for it with the Embedding Jython instructions.
If you can't get the Eclipse functionality into your Jython, then you can still write some of your code in python, and then have the Eclipse API access happening on your Java layer. This will be annoying in proportion to how evenly split your code is between python and Java. I've worked on a project before where we embedded python into C++ (or it might have been the other way around...), and it's a major headache if you don't plan it out right.

writing an api for python that can be installed using setup.py method

I am new at writing APIs in python, in any language for that matter. I was hoping to get pointers on how i can create an API that can be installed using setup.py method and used in other python projects. Something similar to the twitterapi.
I have already created and coded all the methods i want to include in the API. I just need to know how to implement the installation so other can use my code to leverage ideas they may have. Or if i need to format the code a certain way to facilitate installation.
I learn best with examples or tutorials.
Thanks so much.
It's worth noting that this part of python is undergoing some changes right now. It's all a bit messy. The most current overview I know of is the Hitchhiker's Guide to Packaging: http://guide.python-distribute.org/
The current state of packaging section is important: http://guide.python-distribute.org/introduction.html#current-state-of-packaging
The python packaging world is a mess (like poswald said). Here's a brief overview along with a bunch of pointers. Your basic problem (using setup.py etc.) is solved by reading the distutils guide which msw has mentioned in his comment.
Now for the dirt. The basic infrastructure of the distribution modules which is in the Python standard library is distutils referred to above. It's limited in some ways and so a series of extensions was written on top of it called setuptools. Setuptools along with actually increasing the functionality provided a command line "installer" called "easy_install".
Setuptools maintenance was not too great and so it was forked and a more active branch called "distribute" was setup and it is the preferred alternative right now. In addition to this, a replacement for easy_install named pip was created which was more modular and useful.
Now there's a huge project going which attempts to fold in all changes from distribute and stuff into a unified library that will go into the stdlib. It's tentatively called "distutils2".

Would it be possible to integrate Python or Perl with Ruby?

Would it be possible to integrate Python (and/or Perl) and Ruby? I've looked at http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/ and http://code.google.com/p/ruby-perl/ , but they both seem rather outdated.
Has someone generated a Ruby interface for Python's C API?
Edit: Python can be integrated with many other languages according to http://wiki.python.org/moin/IntegratingPythonWithOtherLanguages . However, that list doesn't include Ruby.
My school (Georgia Tech), along with Bryn Mawr and Microsoft Research, are doing a project right now called Pyjama. Basically, it uses the Microsoft DLR to allow you to freely mix Python and Ruby. I haven't tried it, but it sounds pretty cool.
Here's an example from the website. You enter the class in "Python mode". Then it gets compiled, and you run the command in "Ruby mode".
class PythonClass:
def hello(self, value):
print "Python says hello to", value
pc = python_class().new
pc.hello "Ruby"
Which produces "Python says hello to Ruby".
Integrating dynamic languages is one of the goals of the Parrot project. It's a virtual machine that dynamic language compilers target. Once compiled to the same virtual machine, you should be able to used the "object" form in any of the languages no matter the object's source.
The issue at the moment, however, is stabilizing the virtual machine and finishing off the mostly done compilers. However, that's been the state for a long time. :)
You can write extensions for Ruby in C.
So, if Python has a C API, you can write a C extension for Ruby which uses this API.
I know nothing about the Python API or how large of a piece you want to integrate with, but if it is not too big, this could (possibly) give you a way to run Python code from Ruby.
For a research project I wanted to use the fabulous matplotlib that's available for Python. I also found that library that you referred to. However, it doesn't look like something popular and well tested. So I decided to write the script that generated graphs using pure Python and called it from Ruby via popen. That worked very well for me.
It might by possible, but not very practical. It would be significantly easier to port whatever modules you need from one to the other than it would be to embed one of the interpreters within the other.
If you absolutely have to use both languages in a project, your best option would probably the combination of Jython and Jruby, or IronPython and IronRuby. I'm not sure if you could get them to talk to each other, but at the very least you could host them on the same virtual machine.
Another strategy, as used by Facebook, is to expose APIs via Thrift. You define lightweight service APIs and the RPCs are inter-process.

What's a good library to do computational geometry (like CGAL) in a garbage-collected language?

I need a library to handle computational geometry in a project, especially boolean operations, but just about every feature is useful. The best library I can find for this is CGAL, but this is the sort of project I would hesitate to make without garbage collection.
What language/library pairs can you recommend? So far my best bet is importing CGAL into D. There is also a project for making Python bindings for CGAL, but it's very incomplete.
I would still recommend to proceed with Python and the existing Python binding. When you find it's incomplete, you'll also find that it is fairly easy to extend - Python's C API is designed so that integrating with external libraries is fairly easy (for experienced C programmers).
Perhaps you can look at Shapely for python
http://pypi.python.org/pypi/Shapely/
For Java I would use JTS
For .NET I would use SharpMap or .NETTopologySuite
The CGAL-bindings project provides bindings for CGAL using SWIG. The targeted languages, so far, are Java and Python. The CGAL-bindings project is open source, and supported/founded by two french companies.
JTS is also available in .NET via IKVM.
I've just found this and it seems very promising even if it seems a young project: https://pyrr.readthedocs.org/en/latest/index.html#
Pyrr is a Python mathematical library.
and it is based on numpy!

NHibernate and python

We have an existing C# project based on NHibernate and WPF. I am asked to convert it to Linux and to consider other implementation like Python. But for some reason, they like NHibernate a lot and want to keep it.
Do you know if it's possible to keep the NHibernate stuff and make it work with Python ? I am under the impression that NHibernate is glue code between C# and the DB, so can not be exported to other languages.
Alternative question: can somebody recommend a good python compatible replacement of NHibernate ? The backend DB is Oracle something.
NHibernate is not specific to C#, but it is specific to .NET.
IronPython is a .NET language from which you could use NHibernate.
.NET and NHibernate can run on Linux through Mono. I'm not sure how good Mono's support is for WPF.
I'm not sure if IronPython runs on Linux, but that would seem to be the closest thing to what you are looking for.
There is a Java version of NHibernate (said tongue in cheek) called Hibernate and there are integration points between Java and Python where Linux is very much supported.
I know the Python community has its own ORMs, but as far as I'm aware, those options are not as mature and feature rich as Hibernate/NHibernate.
I would imagine that almost all of the options available to you would support Oracle.
What about running your project under Mono on Linux? Mono seems to support NHibernate, which means you may be able to get away with out rewriting large chunks of your application.
Also, if you really wanted to get Python in on the action, you could use IronPython along with Mono.
SQLAlchemy is the most powerful ORM in Python so far.
Check out Django. They have a nice ORM and I believe it has tools to attempt a reverse-engineer from the DB schema.

Categories

Resources