|
| 1 | +from _typeshed import Incomplete |
| 2 | +from datetime import datetime |
| 3 | +from httpx import AsyncClient, Client, Response, Timeout |
| 4 | +from httpx._client import BaseClient |
| 5 | +from pyarrow import Table |
| 6 | +from types import TracebackType |
| 7 | +from typing import Any, Generic, TypeVar, TypedDict |
| 8 | + |
| 9 | +DEFAULT_TIMEOUT: Incomplete |
| 10 | + |
| 11 | +class QueryExecutionError(RuntimeError): |
| 12 | + """Raised when the query execution fails on the server.""" |
| 13 | +class QueryRequestError(RuntimeError): |
| 14 | + """Raised when the query request is invalid.""" |
| 15 | + |
| 16 | +class ColumnDetails(TypedDict): |
| 17 | + """The details of a column in the row-oriented JSON-format query results.""" |
| 18 | + name: str |
| 19 | + datatype: Any |
| 20 | + bit_settings: str |
| 21 | + |
| 22 | +class ColumnData(ColumnDetails): |
| 23 | + """The data of a column in the column-oriented JSON-format query results.""" |
| 24 | + values: list[Any] |
| 25 | + |
| 26 | +class QueryResults(TypedDict): |
| 27 | + """The (column-oriented) results of a JSON-format query.""" |
| 28 | + columns: list[ColumnData] |
| 29 | + |
| 30 | +class RowQueryResults(TypedDict): |
| 31 | + """The row-oriented results of a JSON-format query.""" |
| 32 | + columns: list[ColumnDetails] |
| 33 | + rows: list[dict[str, Any]] |
| 34 | +T = TypeVar('T', bound=BaseClient) |
| 35 | +S = TypeVar('S', bound='LogfireQueryClient') |
| 36 | +R = TypeVar('R', bound='AsyncLogfireQueryClient') |
| 37 | + |
| 38 | +class _BaseLogfireQueryClient(Generic[T]): |
| 39 | + base_url: Incomplete |
| 40 | + read_token: Incomplete |
| 41 | + timeout: Incomplete |
| 42 | + client: Incomplete |
| 43 | + def __init__(self, base_url: str, read_token: str, timeout: Timeout, client: type[T], **client_kwargs: Any) -> None: ... |
| 44 | + def build_query_params(self, sql: str, min_timestamp: datetime | None = None, max_timestamp: datetime | None = None, limit: int | None = None, row_oriented: bool = False) -> dict[str, str]: ... |
| 45 | + def handle_response_errors(self, response: Response) -> None: ... |
| 46 | + |
| 47 | +class LogfireQueryClient(_BaseLogfireQueryClient[Client]): |
| 48 | + """A synchronous client for querying Logfire data.""" |
| 49 | + def __init__(self, read_token: str, base_url: str = 'https://logfire-api.pydantic.dev/', timeout: Timeout = ..., **client_kwargs: Any) -> None: ... |
| 50 | + def __enter__(self) -> S: ... |
| 51 | + def __exit__(self, exc_type: type[BaseException] | None = None, exc_value: BaseException | None = None, traceback: TracebackType | None = None) -> None: ... |
| 52 | + def query_json(self, sql: str, min_timestamp: datetime | None = None, max_timestamp: datetime | None = None, limit: int | None = None) -> QueryResults: |
| 53 | + """Query Logfire data and return the results as a column-oriented dictionary.""" |
| 54 | + def query_json_rows(self, sql: str, min_timestamp: datetime | None = None, max_timestamp: datetime | None = None, limit: int | None = None) -> RowQueryResults: |
| 55 | + """Query Logfire data and return the results as a row-oriented dictionary.""" |
| 56 | + def query_arrow(self, sql: str, min_timestamp: datetime | None = None, max_timestamp: datetime | None = None, limit: int | None = None) -> Table: |
| 57 | + """Query Logfire data and return the results as a pyarrow Table. |
| 58 | +
|
| 59 | + Note that pyarrow must be installed for this method to succeed. |
| 60 | +
|
| 61 | + You can use `polars.from_arrow(result)` to convert the returned table to a polars DataFrame. |
| 62 | + """ |
| 63 | + def query_csv(self, sql: str, min_timestamp: datetime | None = None, max_timestamp: datetime | None = None, limit: int | None = None) -> str: |
| 64 | + """Query Logfire data and return the results as a CSV-format string. |
| 65 | +
|
| 66 | + Use `polars.read_csv(StringIO(result))` to convert the returned CSV to a polars DataFrame. |
| 67 | + """ |
| 68 | + |
| 69 | +class AsyncLogfireQueryClient(_BaseLogfireQueryClient[AsyncClient]): |
| 70 | + """An asynchronous client for querying Logfire data.""" |
| 71 | + def __init__(self, read_token: str, base_url: str = 'https://logfire-api.pydantic.dev/', timeout: Timeout = ..., **async_client_kwargs: Any) -> None: ... |
| 72 | + async def __aenter__(self) -> R: ... |
| 73 | + async def __aexit__(self, exc_type: type[BaseException] | None = None, exc_value: BaseException | None = None, traceback: TracebackType | None = None) -> None: ... |
| 74 | + async def query_json(self, sql: str, min_timestamp: datetime | None = None, max_timestamp: datetime | None = None, limit: int | None = None) -> QueryResults: |
| 75 | + """Query Logfire data and return the results as a column-oriented dictionary.""" |
| 76 | + async def query_json_rows(self, sql: str, min_timestamp: datetime | None = None, max_timestamp: datetime | None = None, limit: int | None = None) -> RowQueryResults: |
| 77 | + """Query Logfire data and return the results as a row-oriented dictionary.""" |
| 78 | + async def query_arrow(self, sql: str, min_timestamp: datetime | None = None, max_timestamp: datetime | None = None, limit: int | None = None) -> Table: |
| 79 | + """Query Logfire data and return the results as a pyarrow Table. |
| 80 | +
|
| 81 | + Note that pyarrow must be installed for this method to succeed. |
| 82 | +
|
| 83 | + You can use `polars.from_arrow(result)` to convert the returned table to a polars DataFrame. |
| 84 | + """ |
| 85 | + async def query_csv(self, sql: str, min_timestamp: datetime | None = None, max_timestamp: datetime | None = None, limit: int | None = None) -> str: |
| 86 | + """Query Logfire data and return the results as a CSV-format string. |
| 87 | +
|
| 88 | + Use `polars.read_csv(StringIO(result))` to convert the returned CSV to a polars DataFrame. |
| 89 | + """ |
0 commit comments