# How to import python class into janus?

**URL:** <https://swi-prolog.discourse.group/t/how-to-import-python-class-into-janus/8905>\
**Category:** General\
**Created:** [March 27, 2025, 3:55pm UTC](https://swi-prolog.discourse.group/t/how-to-import-python-class-into-janus/8905 "2025-03-27T15:55:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![spierepf](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@spierepf](https://swi-prolog.discourse.group/u/spierepf)\
**Post date:** [March 27, 2025, 3:55pm UTC](https://swi-prolog.discourse.group/t/how-to-import-python-class-into-janus/8905/1 "2025-03-27T15:55:03Z")

</div>

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

```prolog
$ 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:

```prolog
$ 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?

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [March 27, 2025, 6:41pm UTC](https://swi-prolog.discourse.group/t/how-to-import-python-class-into-janus/8905/2 "2025-03-27T18:41:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![spierepf](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@spierepf](https://swi-prolog.discourse.group/u/spierepf)\
**Post date:** [March 27, 2025, 7:53pm UTC](https://swi-prolog.discourse.group/t/how-to-import-python-class-into-janus/8905/3 "2025-03-27T19:53:04Z")

</div>

After some trial-and-error, this worked:

```prolog
$ 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'.

?- 

```
