Integrating Jython Cpython - python

I am about to begin a project where I will likely use PyQt or Pyside.
I will need to interface with a buggy 3rd party piece of server software that provides C++ and Java APIs. The Java APIs are a lot easier to use because you get Exceptions where with the C++ libraries you get segfaults. Also, the Python bindings to the Java APIs are automatic with Jython whereas the Python bindings for the C++ APIs don't exist.
So, how would a CPython PyQt client application be able to communicate with these Java APIs? How would you go about it?
Would you have another separate Java process on the client that serializes / pickles objects and communicates with the PyQt process over a socket?
I don't want to re-invent the wheel... is there some sort of standard interface for these types of things? Some technology I should look into? RPC, Corba, etc?
Thanks,
~Eric

If you want to maintain complete isolation and increase your robustness (the 3rd party library going down and not taking your client, and if it's buggy I would recommend that) then perhaps something like CORBA is the way forwards. Don't forget that Java comes with a CORBA implementation as standard, so you just need to generate your C proxy from the IDL.
Swig may be of interest if you want to run stuff in-process. It simplifies the binding of components in different languages. Note in particular that it generates bindings for Python and Java.

If the criteria is not reinventing the wheel, there is the SimpleXMLRPCServer and xmlrpclib modules available in the standard library. They should work in Jython too.

Related

Python interface with SWI-Prolog

I want to use a Python script as a frontend to a Prolog program that uses the SWI-PL engine.
So, the components of the setup are:
Python (2.7 or higher)
SWI-PL: website here
I've been looking around for an interface between SWI-PL and Python.
What I found are:
PySwip but it seems to be lacking from what i see from old questions here, and also seems unsupported.
PyLog, which seems newer but also has some activity. Although i don't know how good it is.
What is the recommended way of using Python to communicate with SWI-prolog?
Are there perhaps other ways to accomplish this?
Maybe with another prolog engine?
I'm stuck with the Prolog language and Python because I know them best, so that would be necessary (I know for instance there are also tools for Java).
I've personally used PySWIP successfully. Here's a link to a project I did for my AI class in university in which I used PySWIP.
I think the difference is that PySWIP is a bridge (just send queries to a Prolog database and get responses) whereas PyLog seems to be an implementation of Prolog (or a built-in Prolog engine) in Python, with abstractions on Prolog code using objects.
I have no particular recommendation for you. Choose whichever you deem will suit your project best. Consider the licenses under which these libraries are published if you will need to worry about your code's license.

What is the term for full-fledged packages like PyQt and PySide?

I learned about them for GUIs, and they are indeed my favourite Python option for such purposes. However, they are so much more than that. They implement network sockets, media management, regular expressions, basic geometry, stuff like QVariant is basically a dynamic attribute handler...
I mean, it seems weird to just call them "GUI packages". It can be as little as a GUI, but it can also be pretty much an entire mask on top Python where you never use a naked function and rely on QObjects for everything.
Is there a name for this concept? Are there others that I should be aware about if I'm doing, say, scientific programming?
Frameworks, platforms, toolkits. PyQT calls itself a toolkit. DirectX is a full featured framework like you described, and it is intended to run on platforms like Windows and Xbox. I use the ExpressJS framework for web development, but most of it's core functionality is either in the NodeJS server, which is not officially referred to as a framework AFAIK; it exposes pretty much the whole OS through a javascript interface for server side interweb code. For scientific programming, Matlab and Octave both just call themselves languages, but I would call them platforms because they have a graphical interface and GUI building tools, and a whole ecosystem of modules, and because your code lives inside of their system. OpenGL, scipy and numpy are libraries, by contrast, because they are used as a component inside of your project. And then there are content management systems (CMS) like Wordpress and Drupal, enterprise resource planning systems (ERP) like Tryton, and probably a bunch of other sub-categories of the "framework" and "platform" categories of software.
All in all, it's not easy to categorize software. We need to standardise a taxonomy, and then make new standardized taxonomies to make up for deficiencies in the first one ;)

Can I call external *python* functions from google refine?

I'm investigating Google refine to speed up some of my data work -- never used it before this week, but I like a lot of what I see.
My biggest question so far is whether it's possible to call external python functions from Refine. I know you can call jython internally, but that doesn't provide access to C-based python libraries (e.g. lxml), and I have scripts elsewhere that I'd like to integrate, without lots of copy-paste or rewrite hassle.
What options are there for doing this in Refine? I'm willing to get creative -- I just want a stable, re-usable solution.
As Google Refine Wiki says:
lxml will NOT work in Jython, since lxml has C bindings for CPython (regular Python), hence will not work in Refine which is Jython / Java only, and has no CPython interpreter built-in
But you can try Google Refine Python Client Library to create projects and manipulate your data programmatically.
I'm going to mark reclosedev's answer as accepted, but there's still a litle more to the story.
The other answer to this question is that you can set up your own python-based API. For this project, I was able to set up a django app running on a local server. It only took an hour or so to build the API to my existing library.
More hassle than I'd have liked, but it fit the bill for this project without soaking up too much time.

What Jabber/XMPP libraries are available for PyS60 (Python for Symbian S60) interpreter?

I'm interested in developing a XMPP client on the mobile S60 Symbian platform using the Python interpreter PyS60. I've done a search on Google for possible libraries, but turned up empty.
I'm hoping that by asking this on SO, I can get a definite answer on whether there is actually an existing library that I just hadn't had the luck to find, or if it doesn't really exist. Failing that, I'm thinking of writing my own library. If there is any XML library within PyS60 to make this task easier (I know the normal interpreter has libraries, but they don't appear to be portable to PyS60), that would be good.
The target device is a Nokia N78, Symbian 3rd Edition FP (Feature Pack) 2
It's fairly easy to add native extensions to Python and there are lots of C/C++ libraries for XMPP that would port easily.
The previous pyexpat module is just bindings for native expat on Symbian, which is ported to S60 3rd Edition, so you should be able to get pyexpat working too. Of course you need some ability with native development to do that...
You could try getting started and then ask for help in developer.symbian.org if you get stuck.

What's the best way to use web services in python?

I have a medium sized application that runs as a .net web-service which I do not control,
and I want to create a loose pythonic API above it to enable easy scripting.
I wanted to know what is the best/most practical solution for using web-services in python.
Edit:
I need to consume a complex soap WS
and I have no control over it.
If I have to expose APIs, I prefer doing it as JSON. Python has excellent support for JSON objects (JSON Objects are infact python dictionaries)
Jython and IronPython give access to great Java & .NET SOAP libraries.
If you need CPython, ZSI has been flaky for me, but it could be possible to use a tool like Robin to wrap a good C++ SOAP library such as gSOAP or Apache Axis C++
Most of the packages on python that a SOAP service through them can be called works on python 2.x, but had problems on Python 3.x
The best fit for python 3.x that I've found is suds-jurko

Categories