-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch_metric_async.py
41 lines (29 loc) · 1.04 KB
/
fetch_metric_async.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""Fetch the values of a particular metric over time and display it."""
import asyncio
from argparse import ArgumentParser
from dbtsl.asyncio import AsyncSemanticLayerClient
def get_arg_parser() -> ArgumentParser:
p = ArgumentParser()
p.add_argument("metric", help="The metric to fetch")
p.add_argument("--env-id", required=True, help="The dbt environment ID", type=int)
p.add_argument("--token", required=True, help="The API auth token")
p.add_argument("--host", required=True, help="The API host")
return p
async def main() -> None:
arg_parser = get_arg_parser()
args = arg_parser.parse_args()
client = AsyncSemanticLayerClient(
environment_id=args.env_id,
auth_token=args.token,
host=args.host,
)
async with client.session():
table = await client.query(
metrics=[args.metric],
group_by=["metric_time"],
order_by=["metric_time"],
limit=15,
)
print(table)
if __name__ == "__main__":
asyncio.run(main())