Using PlatformIO Core programmatically from within Python without CLI

Hi everyone,

currently, I am working on a a simple Python server (Flask or FastAPI) and I want it to be able to compile C++ code for a certain environment using PlatformIO (the same way as with the command line interface).

Everything I found in the documentation is related to the CLI. While browsing through the code on github, I got the feeling that everything is focused on CLI usage (e.g. all the cli() methods and click package).

Is there a way to programmatically use classes/functions from the platformio Python package to get the same functionality as with the CLI? I guess one could just call the CLI from within Python (e.g. via subprocess), but still I am wondering if there is a native way to use platformio in Python.

Kind regards,
Daniel