-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
88 lines (64 loc) · 1.78 KB
/
Copy pathmodels.py
File metadata and controls
88 lines (64 loc) · 1.78 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from __future__ import annotations
from typing import Any, List, Literal, Optional, Tuple, TypedDict
# ----------
# Type aliases
# ----------
Metric = str # e.g. "visitors", "pageviews", "bounce_rate", etc.
Dimension = str # e.g. "visit:country_name", "event:page", "time:day", etc.
Direction = Literal["asc", "desc"]
OrderByItem = Tuple[str, Direction] # (dimension_or_metric, direction)
OrderBy = List[OrderByItem]
Filter = List[Any] # Simple or logical filters as per API docs
class IncludeOptions(TypedDict, total=False):
imports: bool
time_labels: bool
total_rows: bool
class Pagination(TypedDict, total=False):
limit: int
offset: int
class StatsQuery(TypedDict, total=False):
site_id: str # REQUIRED
metrics: List[Metric] # REQUIRED
date_range: Any # REQUIRED: string or [start, end] ISO8601 strings
dimensions: List[Dimension]
filters: List[Filter]
order_by: OrderBy
include: IncludeOptions
pagination: Pagination
# ---------
# Responses
# ---------
class QueryResultRow(TypedDict):
metrics: List[Any]
dimensions: List[Any]
class StatsResponse(TypedDict):
results: List[QueryResultRow]
meta: dict
query: dict
# ---------
# Events API
# ---------
class EventPayload(TypedDict, total=False):
domain: str
name: str
url: str
referrer: Optional[str]
props: Optional[dict]
revenue: Optional[dict]
interactive: bool
# ---------
# Sites API shapes (loose)
# ---------
class Site(TypedDict, total=False):
domain: str
timezone: str
custom_properties: List[str]
class SitesListResponse(TypedDict):
sites: List[Site]
meta: dict
class TeamsListResponse(TypedDict):
teams: List[dict]
meta: dict
class GoalsListResponse(TypedDict):
goals: List[dict]
meta: dict