Support for swipl flags

29 views
Skip to first unread message

Federico Forzano

unread,
Jul 23, 2025, 5:54:05 AMJul 23
to pyswip
Hi all, 

I've implemented an initial support for configuring SWI-Prolog flags in PySwip, using either environment variables or a TOML configuration file.

If anyone is interested, you can find this implementation in my fork: https://github.com/FForzano/pyswip

Key features:
- Flags can be set via environment varibles using the pattern `SWIPL_<FLAGNAME>`, for example: `export SWIPL_STACK_LIMIT="512M"`
- Alternatively, you can use a TOML file (`swipl.toml`) with a `[swipl]` section to specify flags.
- Only flags supported by the SWI-Prolog cli are accepted and validated according to the official documentation.
- You can specify a custom configuration file by setting the `SWIPL_CONF_FILE` environment variable.
- Invalid or unsupported flags are ignored with a warning.

Let me know if you have any feedback or questions.

Federico Forzano.

yuce

unread,
Jul 26, 2025, 7:22:09 AMJul 26
to pyswip
Hi Federico,

Thanks for sharing your implementation, that's very cool!

Could you tell a bit about your use case?
Which extra flags do you use from SWI?
Maybe we should make it easier to pass custom initialization flags to PySwip.
So, your code that uses env vars and TOML may be simpler, and people can pass the flags using other methods.

Yüce

Federico Forzano

unread,
Jul 28, 2025, 4:38:06 AMJul 28
to pyswip

Hi Yüce,

The flags I needed to use were stack_limit, table_space, and shared_table_space

I tried to implement the passing of these in a way that seemed reasonably simple and backward-compatible, but if you have ideas to make it cleaner or simpler, I’d be happy to improve the implementation!

Federico

yuce

unread,
Jul 29, 2025, 6:44:35 PMJul 29
to pyswip
Unfortunately, importing pyswip initializes SWI, so ATM there's not a clean way of passing parameters to SWI.
I have a better solution which initializes SWI lazily, but it's not ready yet.

Btw, stack_limit, table_space and shared_table_space can be  set using set_prolog_flag.
The following seems to work OK:

from pyswip import Prolog
next(Prolog.query("set_prolog_flag(stack_limit, 10000000)"))
Reply all
Reply to author
Forward
0 new messages