Skip to content

Commit 753fabe

Browse files
authored
python(feat): Sift Client Ingestion (#370)
1 parent 20bd14f commit 753fabe

14 files changed

Lines changed: 1097 additions & 1028 deletions

File tree

.github/workflows/python_ci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ jobs:
1717
working-directory: python
1818
steps:
1919
- name: Checkout code
20-
uses: actions/checkout@v2
20+
uses: actions/checkout@v4
21+
with:
22+
ref: ${{ github.event.pull_request.head.sha }}
2123

2224
- name: Set up Python
2325
uses: actions/setup-python@v2
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "0b202351",
6+
"metadata": {},
7+
"source": [
8+
"# Sift Client Ingestion Basic Example\n",
9+
"\n",
10+
"This notebook demonstrates some examples features of SiftClient ingestion\n",
11+
"- Initializing the Sift client\n",
12+
"- Creating an ingestion config\n",
13+
"- Creating a run\n",
14+
"- Creating and sending flows\n"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": null,
20+
"id": "02268d76",
21+
"metadata": {
22+
"vscode": {
23+
"languageId": "plaintext"
24+
}
25+
},
26+
"outputs": [],
27+
"source": [
28+
"import asyncio\n",
29+
"import random\n",
30+
"import time\n",
31+
"from datetime import datetime, timezone\n",
32+
"\n",
33+
"from sift_client import SiftClient, SiftConnectionConfig\n",
34+
"from sift_client.sift_types import (\n",
35+
" ChannelConfig,\n",
36+
" ChannelDataType,\n",
37+
" FlowConfig,\n",
38+
" IngestionConfigCreate,\n",
39+
" RunCreate,\n",
40+
")\n",
41+
"\n",
42+
"\n",
43+
"async def main():\n",
44+
" connection_config = SiftConnectionConfig(\n",
45+
" api_key=\"my_api_key\",\n",
46+
" grpc_url=\"sift_grpc_url\",\n",
47+
" rest_url=\"sift_rest_url\",\n",
48+
" )\n",
49+
"\n",
50+
" client = SiftClient(connection_config=connection_config)\n",
51+
"\n",
52+
" # Ingestion configs are created using SiftClient types\n",
53+
" ingestion_config = IngestionConfigCreate(\n",
54+
" asset_name=\"sift_rover_1\",\n",
55+
" flows=[\n",
56+
" FlowConfig(\n",
57+
" name=\"onboard_sensors\",\n",
58+
" channels=[\n",
59+
" ChannelConfig(name=\"motor_temp\", unit=\"C\", data_type=ChannelDataType.DOUBLE),\n",
60+
" ChannelConfig(\n",
61+
" name=\"tank_pressure\", unit=\"kPa\", data_type=ChannelDataType.DOUBLE\n",
62+
" ),\n",
63+
" ],\n",
64+
" )\n",
65+
" ],\n",
66+
" )\n",
67+
"\n",
68+
" run = RunCreate(name=\"sift_rover-\" + str(int(time.time())))\n",
69+
"\n",
70+
" async with await client.async_.ingestion.create_ingestion_config_streaming_client(\n",
71+
" ingestion_config=ingestion_config,\n",
72+
" run=run,\n",
73+
" ) as ingest_client:\n",
74+
" while True:\n",
75+
" # Flows can be generated easily from the ingest client\n",
76+
" flow_config = ingest_client.get_flow_config(flow_name=\"onboard_sensors\")\n",
77+
" flow = flow_config.as_flow(\n",
78+
" timestamp=datetime.now(timezone.utc),\n",
79+
" values={\n",
80+
" \"motor_temp\": 50.0 + random.random() * 5.0,\n",
81+
" \"tank_pressure\": 2000.0 + random.random() * 100.0,\n",
82+
" },\n",
83+
" )\n",
84+
" # Ingest the flow with .send()\n",
85+
" await ingest_client.send(flow=flow)\n",
86+
"\n",
87+
" await asyncio.sleep(1)\n",
88+
"\n",
89+
"\n",
90+
"if __name__ == \"__main__\":\n",
91+
" asyncio.run(main())\n"
92+
]
93+
}
94+
],
95+
"metadata": {
96+
"language_info": {
97+
"name": "python"
98+
}
99+
},
100+
"nbformat": 4,
101+
"nbformat_minor": 5
102+
}

0 commit comments

Comments
 (0)