Skip to content

Commit 02f88c4

Browse files
authored
python(refactor): update CSV import example (#585)
1 parent 565294b commit 02f88c4

10 files changed

Lines changed: 53 additions & 172 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SIFT_GRPC_URI=
2+
SIFT_REST_URI=
3+
SIFT_API_KEY=
4+
ASSET_NAME=

python/examples/data_import/csv/custom/.env-example

Lines changed: 0 additions & 3 deletions
This file was deleted.

python/examples/data_import/csv/custom/main.py

Lines changed: 0 additions & 70 deletions
This file was deleted.

python/examples/data_import/csv/custom/requirements.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
python-dotenv
2-
sift-stack-py
2+
sift-stack-py
File renamed without changes.

python/examples/data_import/csv/simple/.env-example

Lines changed: 0 additions & 3 deletions
This file was deleted.

python/examples/data_import/csv/simple/main.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

python/examples/data_import/csv/simple/sample_data.csv

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)