Getting Started with the STK Python API

About the STK Python API

Historically interacting with STK Desktop and STK Engine from Python has been achieved using the win32com or comtypes Python modules. While these methods still work and are still supported, the STK Python API offers the following advantages:

  • Cross-platform support: Code written using the new API interacting with STK Engine can be used on Windows and on Linux without modifications, assuming the usual cross platform Python guidelines are followed.

  • Usability improvements:

    • STK object model types have built-in support for the Python help function.
    • The new API provides definitions for all enumerations. With win32com, enumerations had to be defined manually based on the corresponding numerical value.
    • Better IDE support through type hints (based on the typing module).
  • Remotable API using gRPC: In addition to traditional OLE communication with STK, the STK Python API has optional gRPC communication for out-of-process or remote interaction with STK.

Prerequisites

The instructions in this section assume that you have a working Python environment on your machine. Python version 3.8 or greater is required. You can download and install Python from https://www.python.org/downloads.

You can install Jupyter Notebooks by downloading an install from https://jupyter.org/install.

It is also assumed that STK Engine is properly installed and licensed. refer to the Installation instructions.

If using the remotable API, modules grpcio and protobuf are required. They can be obtained from PyPI and installed using pip.

Install the wheel file

The STK Python API is packaged as a wheel file that can be installed using pip. The wheel file is included with the STK install in the bin/AgPythonAPI directory.

Using pip may require an SSL certification, please contact your system administration to provide this file.

python -m pip install "<STK installation directory>/bin/AgPythonAPI/agi_stk13-13.0-py3-none-any.whl"

Verify the installation

The final step to ensure a working development setup is to run a simple program that exercises the API. In a Python file, copy and paste the code below and run it. Everything is set up for developing applications with STK.

[Python - STK API]
from agi.stk13.stkengine import STKEngine

stk = STKEngine.StartApplication(noGraphics=True)
print(stk.Version)

This will print the version of STK currently installed on your machine.

Install Jupyter Notebooks

Using a command line you can install Jupyter Notebooks:

python -m pip install notebook

If you want to launch Jupyter Notebooks, you need to do that outside of STK.

Next steps

Once you have completed the installation, refer to the Programmer’s Guide as needed.