Skip to content

add typing hints for telemetry-python#4

Open
kalradivyanshu wants to merge 1 commit into
telemetry-sh:mainfrom
kalradivyanshu:main
Open

add typing hints for telemetry-python#4
kalradivyanshu wants to merge 1 commit into
telemetry-sh:mainfrom
kalradivyanshu:main

Conversation

@kalradivyanshu

@kalradivyanshu kalradivyanshu commented Oct 6, 2024

Copy link
Copy Markdown
Contributor

This pull request adds typing hints to telemetry-python. Same PR for JS client: telemetry-sh/telemetry#1

from typing import Mapping, TypedDict, Literal, TypeVar, Generic
TelemetryQueryType = TypeVar("TelemetryQueryType", bound=Mapping)

class TelemetryQueryResponse(TypedDict, Generic[TelemetryQueryType]):
    data: list[TelemetryQueryType]
    status: Literal["success"]
    key_order: list[str]

class TelemetryLogResponse(TypedDict):
    status: Literal["success"]
    message: str

So now you can use TypeDict and get typing hints for queries:

from telemetry_sh.telemetry_types import TelemetryQueryResponse

class UberData(TypedDict):
    city: str
    price: float

response: TelemetryQueryResponse[UberData] = await telemetry.query("SELECT city, price from uber_rides");
uber_data = response["data"]
uber_data # is of type UberData.

@kalradivyanshu kalradivyanshu changed the title added typing hints for telemetry-python add typing hints for telemetry-python Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant