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
|
from __future__ import annotations
from typing import Any
from ..rest import RestClient, RestClientOptions
from ..types import TimeoutType
class Stats:
"""Auth0 stats endpoints
Args:
domain (str): Your Auth0 domain, e.g: 'username.auth0.com'
token (str): Management API v2 Token
telemetry (bool, optional): Enable or disable Telemetry
(defaults to True)
timeout (float or tuple, optional): Change the requests
connect and read timeout. Pass a tuple to specify
both values separately or a float to set both to it.
(defaults to 5.0 for both)
protocol (str, optional): Protocol to use when making requests.
(defaults to "https")
rest_options (RestClientOptions): Pass an instance of
RestClientOptions to configure additional RestClient
options, such as rate-limit retries.
(defaults to None)
"""
def __init__(
self,
domain: str,
token: str,
telemetry: bool = True,
timeout: TimeoutType = 5.0,
protocol: str = "https",
rest_options: RestClientOptions | None = None,
) -> None:
self.domain = domain
self.protocol = protocol
self.client = RestClient(
jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options
)
def _url(self, action: str) -> str:
return f"{self.protocol}://{self.domain}/api/v2/stats/{action}"
def active_users(self) -> int:
"""Gets the active users count (logged in during the last 30 days).
Returns: An integer.
See: https://auth0.com/docs/api/management/v2#!/Stats/get_active_users
"""
return self.client.get(self._url("active-users"))
def daily_stats(
self, from_date: str | None = None, to_date: str | None = None
) -> list[dict[str, Any]]:
"""Gets the daily stats for a particular period.
Args:
from_date (str, optional): The first day of the period (inclusive) in
YYYYMMDD format.
to_date (str, optional): The last day of the period (inclusive) in
YYYYMMDD format.
See: https://auth0.com/docs/api/management/v2#!/Stats/get_daily
"""
return self.client.get(
self._url("daily"), params={"from": from_date, "to": to_date}
)
|