You can modify the snappy.ini file by script.
Change the line
# java_max_mem: 4G
to e.g.
java_max_mem: 6G
The value could be computed by the (Python) script based on the memory available.
There is also the snap-conf-optimiser. Which can be used to find a suitable configuration. But this is not really applicable in your case, because it doesn’t change the configuration of snappy/jpy.