|
| 1 | +"""Import a CSV file into Sift.""" |
| 2 | + |
| 3 | +import os |
| 4 | + |
| 5 | +from dotenv import load_dotenv |
| 6 | +from sift_client import SiftClient |
| 7 | + |
| 8 | +if __name__ == "__main__": |
| 9 | + load_dotenv() |
| 10 | + |
| 11 | + grpc_uri = os.getenv("SIFT_GRPC_URI") |
| 12 | + assert grpc_uri, "expected 'SIFT_GRPC_URI' environment variable to be set" |
| 13 | + |
| 14 | + rest_uri = os.getenv("SIFT_REST_URI") |
| 15 | + assert rest_uri, "expected 'SIFT_REST_URI' environment variable to be set" |
| 16 | + |
| 17 | + apikey = os.getenv("SIFT_API_KEY") |
| 18 | + assert apikey, "expected 'SIFT_API_KEY' environment variable to be set" |
| 19 | + |
| 20 | + asset_name = os.getenv("ASSET_NAME") |
| 21 | + assert asset_name, "expected 'ASSET_NAME' environment variable to be set" |
| 22 | + |
| 23 | + client = SiftClient(api_key=apikey, grpc_url=grpc_uri, rest_url=rest_uri) |
| 24 | + |
| 25 | + # Auto-detect the config and import the file. |
| 26 | + import_job = client.data_import.import_from_path( |
| 27 | + "sample_data.csv", |
| 28 | + asset=asset_name, |
| 29 | + ) |
| 30 | + |
| 31 | + import_job.wait_until_complete() |
| 32 | + |
| 33 | + # If auto-detect doesn't quite match your file, inspect the config and patch |
| 34 | + # it before importing. Common fixes: override a column's data type, change |
| 35 | + # the time column or format, or drop a column that shouldn't be imported. |
| 36 | + # |
| 37 | + # config = client.data_import.detect_config("sample_data.csv") |
| 38 | + # print(config) # inspect what was auto-detected |
| 39 | + # |
| 40 | + # # Example: drop a column from the import |
| 41 | + # config.data_columns = [dc for dc in config.data_columns if dc.name != "channel_0"] |
| 42 | + # |
| 43 | + # import_job = client.data_import.import_from_path( |
| 44 | + # "sample_data.csv", |
| 45 | + # asset=asset_name, |
| 46 | + # config=config, |
| 47 | + # ) |
| 48 | + # import_job.wait_until_complete() |
0 commit comments