I’m creating a dashboard with Streamlit where I’m currently connecting to my data warehouse (BigQuery) and the docs show how to cache the connection to BigQuery. However, I can’t seem to find the same option for Firestore? Is this possible?
Thanks for posting!
You can use st.cache_resource
to cache the function that creates the connection to Firestore.
Thank you for responding, Tony.
Does this function look correct to you?
@st.cache_resource
def firestore_connection():
if not firebase_admin._apps:
firebase_admin.initialize_app()
return firestore.Client(credentials=credentials)
The documentation for connecting to Firestore just links to a blog post but I don’t see @st.cache_resource
being used at all in the post so not sure if I am using it correctly.
Yes, your function looks correct. You can control the caching behavior with parameters like ttl
(time-to-live) and max_entries
. If your Firestore client doesn’t need to refresh often, you could set a longer ttl
.
Are you referencing this blog? If yes, there are a good number of releases that have happened after this blog was published in 2021 that would make some parts of the blog outdated.
Please let me know if you run into any other issues.
Yes! That is the blog I’m referring to. Are there plans to create a doc like the other connections listed under Knowledge Base > Tutorials > Connect to data sources ?
Thanks for the check and listing out the parameters.
Am glad you found the solution. Yes, the goal is to eventually populate the tutorials with more data sources. You can actually build and contribute more connections. We have st.connection
as a new easier way to connect to data sources. Check out this example in our docs.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.