Is there a specific reason you need to do it in Python? I'm not even entirely sure you need to communicate with the server. If you're working on AI/machine learning in the game I think all you really need is move data which you can get via the Lua functions. If you're dead set on using Python you can still connect to the server (think like Telnet) and parse move data received by the server.
Ah! Fair enough, I have a better understanding of what you're trying to do now.
If I'm correct, LuaSocket includes a core.dll file that you could potentially inject into toribash.exe. I have absolutely zero experience with that so I couldn't really help you there (and honestly I don't even know if it's technically allowed, but eh), but a little research on DLL injection may point you in the right direction.
Other than that, probably the way that I would do it is a direct socket connection to the game server via Python. As the client-to-server communication is entirely unencrypted, yes it is possible to send and receive data as if you were a Toribash client. You'd have to familiarize yourself with the protocol (it isn't too difficult, use Wireshark or something) but in theory I think it's possible. From what I know there isn't any complete documentation on the server protocol.
As a last resort, maybe you could try some clever workaround using text files (e.g. writing moves as they happen to a text file while running a Python script that reads the file every second or so, does what it needs to, and writes another file that the Lua script could read before executing a move). I realize that both of these options sound pretty tedious, but I don't have much knowledge on this general subject, as in the past most people have generally just worked with what they had.
Image