Platformio-core api docs for integration into my own tools

Are there docs anywhere on integrating platformio into my own tool? I use it for development, but I want to also integrate it in a small GUI application for flashing the microcontroller. The app already uses python and kivy so I am guessing adding platformio tools (basically just pio run) would probably not be hard. But I can’t find any api docs. Do they exist?

PlatformIO’s API is the command line interface, i.e. the pio command line tool.

The documentation is here: CLI Guide — PlatformIO latest documentation

Ok, I want to use it from code though, not the cli. I guess that is not an intended use-case maybe, but I managed it anyway :slight_smile:

For those looking for examples, this is what I produced quickly by digging through the code. It’s not complete yet but a good start. Notably there is no error handling in there at all.

"""Provides the platformio API"""
import logging
from multiprocessing import cpu_count
from pathlib import Path

from platformio import fs
from platformio.platform.factory import PlatformFactory
from platformio.project.config import ProjectConfig

    DEFAULT_JOB_NUMS = cpu_count()
except NotImplementedError:
BASEPATH = Path(__file__).parent.resolve()

class PlatformIOApi:
    """PlatformIO API"""

    def __init__(self, code_path=BASEPATH / 'code'):
        self.log = logging.getLogger(self.__class__.__name__)
        self.code_path = code_path

    def compile_sketch(self, name):
        """Compile a sketch.""""Compiling sketch %s", name)

    def pio_run(self, name, target=None):
        """Run a platformio target."""

        if target is None:
            target = []"Running platformio with target %s for env %s", target,
            pio_config = ProjectConfig.get_instance()
            variables = {'pioenv': name, 'project_config': pio_config.path}
            options = pio_config.items(env=name, as_dict=True)
            platform =['platform'])
  , target, False, False, cpu_count())

    def upload_sketch(self, name):
        """Upload a sketch to a device""""Uploading environment %s", name)
        self.pio_run(name, ['upload'])
1 Like