1111import os
1212from datetime import datetime , timedelta , timezone
1313
14+ import dotenv
15+
1416from sift_client import SiftClient
1517
1618
@@ -52,7 +54,7 @@ async def main():
5254
5355 # Example 1: List all runs
5456 print ("\n 1. Listing all runs..." )
55- runs = client .runs .list (limit = 5 )
57+ runs = client .runs .list_ (limit = 5 )
5658 print (f" Found { len (runs )} runs:" )
5759 for run in runs :
5860 print (f" - { run .name } (ID: { run .id_ } ), Organization ID: { run .organization_id } " )
@@ -61,7 +63,7 @@ async def main():
6163 print ("\n 2. Testing different filter options..." )
6264
6365 # Get a sample run for testing filters
64- sample_runs = client .runs .list (limit = 3 )
66+ sample_runs = client .runs .list_ (limit = 3 )
6567 if not sample_runs :
6668 print (" No runs available for filter testing" )
6769 return
@@ -71,38 +73,38 @@ async def main():
7173 # 2a: Filter by exact name
7274 print ("\n 2a. Filter by exact name..." )
7375 run_name = sample_run .name
74- runs = client .runs .list (name = run_name , limit = 5 )
76+ runs = client .runs .list_ (name = run_name , limit = 5 )
7577 print (f" Found { len (runs )} runs with exact name '{ run_name } ':" )
7678 for run in runs :
7779 print (f" - { run .name } (ID: { run .id_ } )" )
7880
7981 # 2b: Filter by name containing text
8082 print ("\n 2b. Filter by name containing text..." )
81- runs = client .runs .list (name_contains = "test" , limit = 5 )
83+ runs = client .runs .list_ (name_contains = "test" , limit = 5 )
8284 print (f" Found { len (runs )} runs with 'test' in name:" )
8385 for run in runs :
8486 print (f" - { run .name } " )
8587
8688 # 2c: Filter by name using regex
8789 print ("\n 2c. Filter by name using regex..." )
88- runs = client .runs .list (name_regex = ".*test.*" , limit = 5 )
90+ runs = client .runs .list_ (name_regex = ".*test.*" , limit = 5 )
8991 print (f" Found { len (runs )} runs with 'test' in name (regex):" )
9092 for run in runs :
9193 print (f" - { run .name } " )
9294
9395 # 2d: Filter by exact description
94- print ("\n 2d. Filter by exact description..." )
96+ print ("\n 2d. Filter by description contains ..." )
9597 if sample_run .description :
96- runs = client .runs .list ( description = sample_run .description , limit = 5 )
97- print (f" Found { len (runs )} runs with exact description '{ sample_run .description } ':" )
98+ runs = client .runs .list_ ( description_contains = sample_run .description , limit = 5 )
99+ print (f" Found { len (runs )} runs with description contains '{ sample_run .description } ':" )
98100 for run in runs :
99101 print (f" - { run .name } : { run .description } " )
100102 else :
101103 print (" No description available for testing" )
102104
103105 # 2e: Filter by description containing text
104106 print ("\n 2e. Filter by description containing text..." )
105- runs = client .runs .list (description_contains = "test" , limit = 5 )
107+ runs = client .runs .list_ (description_contains = "test" , limit = 5 )
106108 print (f" Found { len (runs )} runs with 'test' in description:" )
107109 for run in runs :
108110 print (f" - { run .name } : { run .description } " )
@@ -112,8 +114,8 @@ async def main():
112114 # Calculate duration for sample run if it has start and stop times
113115 if sample_run .start_time and sample_run .stop_time :
114116 duration_seconds = int ((sample_run .stop_time - sample_run .start_time ).total_seconds ())
115- runs = client .runs .list ( duration_seconds = duration_seconds , limit = 5 )
116- print (f" Found { len (runs )} runs with duration { duration_seconds } seconds:" )
117+ runs = client .runs .list_ ( duration_greater_than = timedelta ( seconds = duration_seconds ) , limit = 5 )
118+ print (f" Found { len (runs )} runs with duration greater than { duration_seconds } seconds:" )
117119 for run in runs :
118120 if run .start_time and run .stop_time :
119121 run_duration = int ((run .stop_time - run .start_time ).total_seconds ())
@@ -124,18 +126,16 @@ async def main():
124126 # 2g: Filter by client key
125127 print ("\n 2g. Filter by client key..." )
126128 if sample_run .client_key :
127- runs = client .runs .list (client_key = sample_run .client_key , limit = 5 )
128- print (f" Found { len (runs )} runs with client key '{ sample_run .client_key } ':" )
129- for run in runs :
130- print (f" - { run .name } (client_key: { run .client_key } )" )
129+ run = client .runs .get (client_key = sample_run .client_key )
130+ print (f" Found run with client key '{ run .name } '" )
131131 else :
132132 print (" No client key available for testing" )
133133
134134 # 2h: Filter by asset ID
135135 print ("\n 2h. Filter by asset ID..." )
136136 if sample_run .asset_ids :
137137 asset_id = sample_run .asset_ids [0 ]
138- runs = client .runs .list ( asset_id = asset_id , limit = 5 )
138+ runs = client .runs .list_ ( assets = [ asset_id ] , limit = 5 )
139139 print (f" Found { len (runs )} runs associated with asset { asset_id } :" )
140140 for run in runs :
141141 print (f" - { run .name } (asset_ids: { list (run .asset_ids )} )" )
@@ -144,42 +144,42 @@ async def main():
144144
145145 # 2i: Filter by asset name
146146 print ("\n 2i. Filter by asset name..." )
147- runs = client .runs .list ( asset_name = "NostromoLV426" , limit = 5 )
147+ runs = client .runs .list_ ( assets = [ client . assets . find ( name = "NostromoLV426" )] , limit = 5 )
148148 print (f" Found { len (runs )} runs associated with asset 'NostromoLV426':" )
149149 for run in runs :
150150 print (f" - { run .name } " )
151151
152152 # 2j: Filter by created by user ID
153153 print ("\n 2j. Filter by created by user ID..." )
154- created_by_user_id = sample_run .created_by_user_id
155- runs = client .runs .list ( created_by_user_id = created_by_user_id , limit = 5 )
156- print (f" Found { len (runs )} runs created by user { created_by_user_id } :" )
154+ created_by = sample_run .created_by_user_id
155+ runs = client .runs .list_ ( created_by = created_by , limit = 5 )
156+ print (f" Found { len (runs )} runs created by user { created_by } :" )
157157 for run in runs :
158- print (f" - { run .name } (created by: { run .created_by_user_id } )" )
158+ print (f" - { run .name } (created by: { run .created_by } )" )
159159
160160 # 2l: Test ordering options
161161 print ("\n 2l. Testing ordering options..." )
162162
163163 # Order by name ascending
164- runs = client .runs .list (order_by = "name" , limit = 3 )
164+ runs = client .runs .list_ (order_by = "name" , limit = 3 )
165165 print (" First 3 runs ordered by name (ascending):" )
166166 for run in runs :
167167 print (f" - { run .name } " )
168168
169169 # Order by name descending
170- runs = client .runs .list (order_by = "name desc" , limit = 3 )
170+ runs = client .runs .list_ (order_by = "name desc" , limit = 3 )
171171 print (" First 3 runs ordered by name (descending):" )
172172 for run in runs :
173173 print (f" - { run .name } " )
174174
175175 # Order by creation date (newest first - default)
176- runs = client .runs .list (order_by = "created_date desc" , limit = 3 )
176+ runs = client .runs .list_ (order_by = "created_date desc" , limit = 3 )
177177 print (" First 3 runs ordered by creation date (newest first):" )
178178 for run in runs :
179179 print (f" - { run .name } (created: { run .created_date } )" )
180180
181181 # Order by creation date (oldest first)
182- runs = client .runs .list (order_by = "created_date" , limit = 3 )
182+ runs = client .runs .list_ (order_by = "created_date" , limit = 3 )
183183 print (" First 3 runs ordered by creation date (oldest first):" )
184184 for run in runs :
185185 print (f" - { run .name } (created: { run .created_date } )" )
@@ -206,22 +206,22 @@ async def main():
206206 start_time = datetime .now (timezone .utc )
207207 stop_time = start_time + timedelta (minutes = 2 )
208208
209- previously_created_runs = client .runs .list (name_regex = "Example Test Run.*" )
209+ previously_created_runs = client .runs .list_ (name_regex = "Example Test Run.*" )
210210 if previously_created_runs :
211211 print (f" Deleting previously created runs: { previously_created_runs } " )
212212 for run in previously_created_runs :
213213 print (f" Deleting run: { run .name } " )
214214 client .runs .archive (run = run )
215215
216- new_run = client .runs .create (
216+ new_run = client .runs .create (dict (
217217 name = f"Example Test Run { datetime .now (tz = timezone .utc ).strftime ('%Y-%m-%d %H:%M:%S' )} " ,
218218 description = "A test run created via the API" ,
219219 tags = ["api-created" , "test" ],
220220 start_time = start_time ,
221221 stop_time = stop_time ,
222222 # Use a unique client key for each run
223223 client_key = f"example-run-key-{ datetime .now (tz = timezone .utc ).timestamp ()} " ,
224- metadata = metadata ,
224+ metadata = metadata ,)
225225 )
226226 print (f" Created run: { new_run .name } (ID: { new_run .id_ } )" )
227227 print (f" Client key: { new_run .client_key } " )
@@ -257,7 +257,7 @@ async def main():
257257
258258 # Example 6: Associate assets with a run
259259 print ("\n 6. Associating assets with a run..." )
260- ongoing_runs = client .runs .list (
260+ ongoing_runs = client .runs .list_ (
261261 name_regex = "Example Test Run.*" , include_archived = True , is_stopped = False
262262 )
263263 if ongoing_runs :
@@ -283,4 +283,5 @@ async def main():
283283
284284
285285if __name__ == "__main__" :
286+ dotenv .load_dotenv ()
286287 asyncio .run (main ())
0 commit comments