Skip to content

Instantly share code, notes, and snippets.

@xoelop
Created February 18, 2021 17:06
Show Gist options
  • Save xoelop/42f89018bd23604b534f225d3739024a to your computer and use it in GitHub Desktop.
Save xoelop/42f89018bd23604b534f225d3739024a to your computer and use it in GitHub Desktop.
# loads the result of a query on Tinybird to a Pandas DataFrame
import pandas as pd
import urllib.parse
def build_tinybird_query_url(query: str, token: str) -> str:
url = f"https://api.tinybird.co/v0/sql?q={urllib.parse.quote(query + ' FORMAT CSVWithNames')}&token={token}"
return url
def df_from_tb(query: str, token: str) -> pd.DataFrame:
url = build_tinybird_query_url(query=query, token=token)
df = pd.read_csv(url, na_values=r'\N')
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment