The goal here is to be able to run Python code from Go while keeping everything as simple as possible by not having to spawn external services such as Valkey/Memcache for inter-process communication. We want to be able to ship a single Go binary (the Python code can be embedded in the Go binary with Go embed).
We use several pieces of technologies to achieve this goal:
- Pixi allows us to create a self-contained Conda env. Instead of having to rely on
venv activate
before running our code, we can simplypixi run
and the env in the.pixi
folder will automatically be used. Pixi is also a single binary file that doesn't require system-wide installation. - NATS allows us to start a server that listen to the response from our Python script directly from our Go code (without requiring a separate service)
Simply put, the GO helper code looks like this:
// Put all this code in `app/internal/python/python