addypy / datagovindia

Python Client for India’s - Open Government Data (OGD) (https://data.gov.in/) platform APIs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stuck on "Latest API meta-data loaded! You may begin."

hearsid opened this issue · comments

The script gets stuck on the step when I try to initialize using DataGovIndia(API_KEY) on second step, "Latest API meta-data loaded! You may begin."
image

from datagovindia import DataGovIndia
import streamlit as st

@st.cache(suppress_st_warning=True)
def getDataGovAdaptor(): 
    return DataGovIndia(API_KEY)

datagovin = getDataGovAdaptor()
result = datagovin.search(description="Wheat",max_results=1,print_results=True)

@hearsid
I was able to reproduce this error. When you initializate the DataGovIndia class with your API_KEY, it downloads the latest meta-data (list of APIs, titles, description etc.) and stores it in memory. Since these are python objects, it is possible that the streamlit cache isn't able to store them.

However, I looked at their documentation, and I was able to make it work by adding an additional kwarg (allow_output_mutation=True) in the @st.cache decorator.

This is what I used -

import os
from datagovindia import DataGovIndia
import streamlit as st
API_KEY = os.environ['DATAGOVIN_API_KEY']
@st.cache(allow_output_mutation=True,suppress_st_warning=True)
def getDataGovAdaptor(): 
    return DataGovIndia(API_KEY)

datagovin = getDataGovAdaptor()
result = datagovin.search(description="Wheat",max_results=1,print_results=True)

Here's the output:

bug3

Hope this solves your issue!

@addypy Thank you for the quick reply, it is working for the first time and then giving this error,
image
I also think and agree that it may be because @st.cache is not able to store the DataGovIndia in memory, I'm also looking for other options to replicate st.cache functionality.

Not sure if this is useful, but if you can't find an alternative, you could try to wrap multiple arguments in the same function - initiate the class with your key, search for the results, and store the output you need.
All the best!