Table of Contents

Python: Swift Integration

Description

The nominalpy API can also be accessed in the Swift programming language via PythonKit. This module can act as an interface layer. A Swift example that uses PythonKit to interface with NominalPy can be found here in the free GitHub repository below. This is included with a setup and installation guide. This repository includes an example of running a Nominal API simulation using the nominalpy Python package via Swift.

GitHub - NominalSystems/swift-nominalpy-example:

Note

This program requires nominalpy to have already been installed onto the same system. If the installation has not been completed, install with the following line:

pip install --upgrade nominalpy

Swift Installation

To run the provided Swift example, you must have Swift installed. There are a few ways to install Swift depending on your operating system: swift.orgswiftlyswiftenv. It is best to install the latest version as it can compile older versions of Swift.


PythonKit

To use PythonKit in Swift, it needs to be added as a dependency to any custom Swift Packages. The provided example already has Python Kit included as a dependency. To learn more about Python Kit, you can find additional documentation Here.


Final Setup

Before executing the Swift example, the Nominal API Access Token must be stored as an Environmental Variable under the name NOMINAL_API_KEY. An optional Environmental Variable can also be configured for the absolute folder path for data export under the name NOMINAL_API_OUTPUT_PATH. To execute the provided example, navigate to the root folder of this repo via the terminal and execute swift run.