Chapter 10 Uploads

Import data from Chapter 10 files directly into Sift

Credentials

Before starting this section, ensure you have retrieved your API key and the appropriate Sift URL for your provisioned environment. Instructions on obtaining the API key and URL are available in the authentication section of the documentation.

Import Data from Chapter 10 files using sift-stack-py

Getting started with sift-stack-py

Be sure to visit the Python Quickstart section of the documentation to see how to get started with the Sift Python client library before continuing.

Uploading Chapter 10 files requires implementing a concrete version of BaseCh10File to parse your Chapter 10 file. Please reach out to the Sift team for a specific implementation.

First create or obtain a parser implementation:

from sift_py.data_import.ch10 import BaseCh10File
 
class MyCh10Parser(BaseCh10File):
    """Implements BaseCh10File."""
 
    def __init__(self, path):
        self.file = open(path, "rb")
        self.csv_config_data_columns = None
 
    def initialize_csv_data_columns(self):
        self.csv_config_data_columns = self.process_ch10_computer_f1_packet()
 
    def process_ch10_computer_f1_packet(self) -> Dict[int, dict]:
        # Processes the first Computer F1 packet
        # and returns the measurements as a dict.
        ...
 
    def process_ch10_pcm_packet(self) -> str:
        # Processed the data packets and returns
        # a CSV row.
        ...
 
    def __next__(self) -> str:
        # On all iterations, return data for the CSV file.
        if end_of_file:
            raise StopIteration()
        else:
            return self.process_ch10_data_packet()

Then use the following steps to upload that file into Sift:

from sift_py.data_import.ch10 import Ch10UploadService
 
# Instantiate a Chapter 10 upload service
ch10_upload_service = Ch10UploadService({
    "uri": sift_uri,
    "apikey": apikey,
})
 
ch10_file = MyCh10Parser("sample_data.ch10")
 
# Upload the Chapter 10 file
import_service = ch10_upload_service.upload_ch10(
    ch10_file,
    asset_name,
)
 
# Wait until the upload is complete and store the uploaded file's metadata
# into the 'uploaded_file' variable.
uploaded_file = import_service.wait_until_complete()

For more comprehensive examples you can visit the Sift public repository.