Jython is a library that allows using Python classes in Java and vice-versa. A couple of weeks ago, I wanted it so I wouldn't need to reimplement a very nice library developed in Python, but I had some difficulties with that.

The default way of acessing Python classes through Jython is by creating a Java interface which shall be implemented by the Python class (yes, in Python code) and with some calls to Jython you get an object assigned to a Java reference with that interface type. This may sound cool, but has some caveats.

1 - You have to change the library code, so the classes you're going to use implement the Java interfaces you need to access the objects. This means you can't easily use new versions of that library and you'll have some work to do every time you choose to update the library.
2 - The library code isn't Python anymore. As you coded those classes to implement Java interfaces, this code will not run anywhere but in Jython and only together with the Java interfaces.
3 - Python coders usually don't care much about encapsulation. As I figured later, the programming language does not provide ways to protect members of a class - everything is 'public' and there are naming conventions to state what shouldn't be used outside the class. So, to access those attributes we have to change the Python code again (we need 'gets' to access those public attributes that hold result of processing)! So that library you wanted to use is now a custom version to be mantained by you... :(

Well, I searched a lot and even posted a question on StackOverflow about those issues, and I found a way to facilitate the use of Jython and isolate the Jython code from the Python library (hint: inheritance and weird reflection). And I created a library on GitHub with that solution.

jythonEasierCoercion library

With this library, there is no need to change the Python library code you're trying to access. If you don't need to access public attributes of Python classes, there is no need to write Python code at all. If not, then you can write some code to expose those variables in separate files from the library. This classes must inherit the target Python class and implement the Java interface. The jythonEasierCoercion library will convert the object from the original class to this new class before assigning it to the Java reference.

The jythonEasierCoercion library can be obtained in this GitHub page: https://github.com/danielgimenes/jythonEasierCoercion

Instructions on usage, installing, license, etc are also on GitHub. The library includes JavaDocs documentation and JUnit unitary tests, so it should be easy and stable to use.