How to import python class into janus?

I have a Python enum named Content defined in a package named lahave.content.

$ python
Python 3.11.9 (main, Mar 22 2025, 14:23:33) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from lahave.content import Content
>>> for i in Content:
...     print(i)
... 
Content.NULL
Content.OPEN
Content.CORRIDOR
Content.DENSE

I am trying to figure out how to access this enum through the library(janus) library.

From the same directory:

$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.2.6)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- use_module(library(janus)).
true.

?- py_call('lahave.content.Content':'Content.DENSE', Content).
% Interactive session; added `.` to Python `sys.path`
Warning: Janus: venv dirrectory '/home/peter/.local/share/virtualenvs/LaHave-zP0WwQMU' does not contain "/home/peter/.local/share/virtualenvs/LaHave-zP0WwQMU/lib/python3.8/site-packages"
ERROR: Python 'ModuleNotFoundError':
ERROR:   No module named 'lahave.content.Content'; 'lahave.content' is not a package
ERROR: In:
ERROR:   [12] janus:py_call('lahave.content.Content':'Content.DENSE',_60286)
ERROR:   [11] toplevel_call(user:user: ...) at /usr/lib/swi-prolog/boot/toplevel.pl:1317
?- 

What am I missing?

Possibly py_import/2 can help. Please share whether that helps. If not, please share something we can use to replicate this.

After some trial-and-error, this worked:

$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.2.9)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- use_module(library(janus)).
true.

?- py_import('lahave.content', []).
% Interactive session; added `.` to Python `sys.path`
Warning: Janus: venv dirrectory '/home/peter/.local/share/virtualenvs/LaHave-zP0WwQMU' does not contain "/home/peter/.local/share/virtualenvs/LaHave-zP0WwQMU/lib/python3.13/site-packages"
true.

?- py_iter(content:'Content', X).
X = 'NULL' ;
X = 'OPEN' ;
X = 'CORRIDOR' ;
X = 'DENSE'.

?- 
1 Like