I'm trying out async and while I get the concept I struggle a bit with implementation.
How do you correctly return value from an async function?
I'm trying to grab some data from an API and return it as a dataframe. As I intend to use it via Pyodide I had to use pyfetch - thus if I understand correctly had to make my function async.
Here's what I've come up with:
async def get_data(category: str) -> pd.DataFrame:
url = f"{BASEURL}{category}"
response = await pyfetch(url, method="GET", headers=HEADERS)
output = await response.json()
return pd.DataFrame(output)
membersdf = await get_data("members")
st.write(membersdf)
it works but I'm not sure it's optimal way to do it. Do I have to put those awaits in each of those places?
Any suggestions greatly appreciated.