11import json
22from datetime import datetime , timedelta
33from math import floor
4- from typing import Any , AsyncGenerator , List , Literal , Optional
4+ from typing import Any , Literal
5+ from collections .abc import AsyncGenerator
56
67import httpx
78from pydantic import ValidationError
@@ -23,16 +24,16 @@ class Obelisk(BaseClient):
2324
2425 async def fetch_single_chunk (
2526 self ,
26- datasets : List [str ],
27- metrics : Optional [ List [ str ]] = None ,
28- fields : Optional [ List [ str ]] = None ,
29- from_timestamp : Optional [ int ] = None ,
30- to_timestamp : Optional [ int ] = None ,
31- order_by : Optional [ dict [str , Any ]] = None ,
32- filter_ : Optional [ dict [str , Any ]] = None ,
33- limit : Optional [ int ] = None ,
34- limit_by : Optional [ dict [str , Any ]] = None ,
35- cursor : Optional [ str ] = None ,
27+ datasets : list [str ],
28+ metrics : list [ str ] | None = None ,
29+ fields : list [ str ] | None = None ,
30+ from_timestamp : int | None = None ,
31+ to_timestamp : int | None = None ,
32+ order_by : dict [str , Any ] | None = None ,
33+ filter_ : dict [str , Any ] | None = None ,
34+ limit : int | None = None ,
35+ limit_by : dict [str , Any ] | None = None ,
36+ cursor : str | None = None ,
3637 ) -> QueryResult :
3738 """
3839 Queries one chunk of events from Obelisk for given parameters,
@@ -103,24 +104,24 @@ async def fetch_single_chunk(
103104 except json .JSONDecodeError as e :
104105 msg = f"Obelisk response is not a JSON object: { e } "
105106 self .log .warning (msg )
106- raise ObeliskError (msg )
107+ raise ObeliskError (msg ) from e
107108 except ValidationError as e :
108109 msg = f"Response cannot be validated: { e } "
109110 self .log .warning (msg )
110- raise ObeliskError (msg )
111+ raise ObeliskError (msg ) from e
111112
112113 async def query (
113114 self ,
114- datasets : List [str ],
115- metrics : Optional [ List [ str ]] = None ,
116- fields : Optional [ List [ str ]] = None ,
117- from_timestamp : Optional [ int ] = None ,
118- to_timestamp : Optional [ int ] = None ,
119- order_by : Optional [ dict [str , Any ]] = None ,
120- filter_ : Optional [ dict [str , Any ]] = None ,
121- limit : Optional [ int ] = None ,
122- limit_by : Optional [ dict [str , Any ]] = None ,
123- ) -> List [Datapoint ]:
115+ datasets : list [str ],
116+ metrics : list [ str ] | None = None ,
117+ fields : list [ str ] | None = None ,
118+ from_timestamp : int | None = None ,
119+ to_timestamp : int | None = None ,
120+ order_by : dict [str , Any ] | None = None ,
121+ filter_ : dict [str , Any ] | None = None ,
122+ limit : int | None = None ,
123+ limit_by : dict [str , Any ] | None = None ,
124+ ) -> list [Datapoint ]:
124125 """
125126 Queries data from obelisk,
126127 automatically iterating when a cursor is returned.
@@ -157,8 +158,8 @@ async def query(
157158 to a specified maximum number.
158159 """
159160
160- cursor : Optional [ str ] | Literal [True ] = True
161- result_set : List [Datapoint ] = []
161+ cursor : str | None | Literal [True ] = True
162+ result_set : list [Datapoint ] = []
162163
163164 while cursor :
164165 actual_cursor = cursor if cursor is not True else None
@@ -191,14 +192,14 @@ async def query(
191192
192193 async def query_time_chunked (
193194 self ,
194- datasets : List [str ],
195- metrics : List [str ],
195+ datasets : list [str ],
196+ metrics : list [str ],
196197 from_time : datetime ,
197198 to_time : datetime ,
198199 jump : timedelta ,
199- filter_ : Optional [ dict [str , Any ]] = None ,
200+ filter_ : dict [str , Any ] | None = None ,
200201 direction : Literal ["asc" , "desc" ] = "asc" ,
201- ) -> AsyncGenerator [List [Datapoint ], None ]:
202+ ) -> AsyncGenerator [list [Datapoint ], None ]:
202203 """
203204 Fetches all data matching the provided filters,
204205 yielding one chunk at a time.
@@ -239,7 +240,7 @@ async def query_time_chunked(
239240 async def send (
240241 self ,
241242 dataset : str ,
242- data : List [dict [str , Any ]],
243+ data : list [dict [str , Any ]],
243244 precision : TimestampPrecision = TimestampPrecision .MILLISECONDS ,
244245 mode : IngestMode = IngestMode .DEFAULT ,
245246 ) -> httpx .Response :
0 commit comments