OH3 - Jython and library

Hello,

I’m trying to develop new rules wth Jython on OH3 GUI (3.1.1) and I don’t find the way to install libraries.
For example requests is not present and I need it.
I’ve searched pip and I find it only for py3.9 (pf OpenHABian) when in the GUI the displayed version of Python is 2.7.

Thanks in advance for your support!

Take care & Enjoy :stuck_out_tongue:
Guillain

This isn’t going to be easy.

First of all, I assume you have the correct helper libraries installed.

You’ll need to install Python 2.7 to get access to pip2. Make sure it doesn’t take over your Python 3 as the default. Note, Python 2.7 has been end of life for a couple years now so it may not be available in the packages.

From there you can use pip2 to install the library in a folder and pass a command line argument to openHAB to tell it to look in that folder for libraries. See Adding python modules to jython.

Personally, given the state of Jython I’m not sure I would spend too much time on this. Until such time that someone builds support for GraalVM Python 3 in openHAB you would better off switching to HABApp (if you want to stick with Python) or JSScripting if you are willing to change languages. JSScripting supports installing third party libraries using npm in a standard way without a lot of these work arounds.

What is the reason you need to use requests? I needed it because I needed to send custom headers. I ended up adding this into core so now HTTP actions let you specify custom headers.

I have since abandoned Jython and started using JRuby

1 Like

Thanks a lot for your replies!

Usualy I develop in Python so I think HABApp should be the best approch for me (and if I can stay away of the 2.7 it’s much better ^^)
But I’ve in another hand the automation to deploy and provision OH3 where currently I use the OH3 API (GUI is nice for one shot but I’m a DevOps XD).

At this time I’ve not learnt a lot about HABApp so I think it will be my next doc with the priority to check if it can be deployed and maintain with a nice fashion (API is the must of course but I don’t have find it during my first reading).
Any guidance is really appreciate, thanks again!

Why is an API a must for HABApp? It would be just like you are doing now, drop your rules .py files in the right folders and you’re good.

If you want to deploy and mess with rules using an API, then you need to be looking at JSScripting and UI style rules which, in fact, get created and managed through openHAB’s API.

There is a docker container or you can deploy it in a venv.
The HABApp rules are just .py files in a folder, exactly as @rlkoshak said.

Thanks again for your replies.!

I understand well the concept of the local files but not sure it fit with my needs:

  • if I’ve understood well, OH3 has switched on GUI approch, replacing the local files by json doc objects reachable by API (the std way of developping srv app in 2021 ^^). I presume the futur will be more and more on this way (and so with more API path to allow more jobs :stuck_out_tongue:).
  • the automation can easily handle these two kinds of job which are deployment and update but it’s a longuer process than an app (in Py for ex ^^) which drive the conf through the API. Additionnaly we split clearly the infrasctruture and application installation (generic) vs the configuration (specific).
  • a small thing depending of your infra/network/secu, deploying local files implies to open a TCP port to allow the connexion on the FS, may be not applicable on some context

The HABApp on container seams interesting and, to keep aligned the techno, OH3 (+RaspAP in my case) must be migrated also on container. So to keep the same flexibility on the file mgt we’re reaching EKS (on Rpi in my case) losing the easy way of using OpenHABian.

So at the end and to Keep It Simple & Stupid, I’ll be back on the std Jython rules like @JimT said (at least to check what I can do with til the blocking point and take decision when I’ll be on ^^)

So sorry to be picky :sweat:, I’ve bad habit to think industrialization but it’s also an opportunity for me to grow on OH :smiley:

Have a wonderful day and take care!
Guillain

Note that @JimT is now using Ruby, not Jython.

I am using Jython in OH3, writing my rules in .py files, not the GUI. I’m using the Helper Libraries from here:

As has been mentioned before, however, there are limitations when it comes to using external libraries as a result of Jython being stuck on python 2.7.

No OH 3 added support for a UI approach. Text files for just about everything except MainUI Widgets are and will remain supported through text files. Local files have not been replaced and probably never will be replaced. However, new features that are added to OH may not get a text file equivalent config going forward. For example, there is no text file format where one can define UI widgets. There is no text file equivalent for Rule Templates (yet, I expect and will push for that though to aide in development and testing of templates.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.