Connections Hackathon

HI team,

Got a quick question, If the streamlit app contains the use of any API (stock, twitter, etc), would this be considered a valid submission? Or does the app needs to have experimental_connection (eg, sqliteDB, MySQL, etc)

Many thanks!

1 Like

Hi @tonykip,

I’m a bit unsure about how to approach creating connections for APIs that already have a good Python client. My understanding is that the main goal of streamlit connections is to streamline secret management and caching. In that case, it could make sense to have a connections factory function that automatically wraps given APIs to manage secrets and add caching to chosen functions.

For example, the connection factory and its application to the elasticsearch Python client would look like:

import streamlit as st
from streamlit.connections import ExperimentalBaseConnection
from collections import ChainMap
from functools import wraps

from elasticsearch import Elasticsearch

def connection_factory(connection_name, python_api_client, func_dict, ttl=60):
    @wraps(python_api_client)
    def _connect(self, **kwargs):
        conn_params = ChainMap(kwargs, self._secrets.to_dict())
        return python_api_client(**conn_params)

    def cached(func):
        @wraps(func)
        @st.cache_data(ttl=ttl)
        def _func(*args, **kwargs):
            return func(*args, **kwargs)

        return _func

    attributes = {}
    attributes["_connect"] = _connect
    for name, func in func_dict.items():
        attributes[name] = cached(func)

    return type(connection_name, (ExperimentalBaseConnection,), attributes)

ElasticsearchConnection = connection_factory("ElasticsearchConnection", Elasticsearch, {
    "get": Elasticsearch.get,
    "search": Elasticsearch.search,
})

The code likely needs to be improved, but this gives a rough description of the idea.

Would this achieve the goals that Streamlit has in mind for its connections, or is there something I’m missing?

2 Likes

I’ve just submitted my Spoonacular connection :balloon:

https://recipedia-app.streamlit.app/

1 Like

Do I have to utilize the secret toml in addition to kwargs? Lastly do I have to use my own api keys to allow the demo to be functional? Thanks

2 Likes

Hi @OlivierBinette, you are on the right track.

Hi @jlonge4, you can store your keys in the secrets.toml to test the connection/app…to avoid any unnecessary costs to you, you can let users enter their keys in your app to use the app. For the hackathon, you can do a screen recording and explain the flow and how it works.

Hi @Pavel401, thanks for sharing, and good luck!

1 Like

Hi @Saurabh_Joshi,

Thanks for posting! If the connection is for an API, then that will be valid; for example a connection for the Twitter API. You would need to create a connection for the API using st.experimental_connection to qualify.

Thanks for sharing @kerbal, and good luck!

Just submitted my first ChromaDB Connection. Checkout my site at https://app-chromadbconnection-mfzxl3nzozmaxh3mrkd6zm.streamlit.app/. Hope y’all have fun building!!!

2 Likes

Hi @tonykip,

Thanks for sharing and good luck!

Submitted my entry on github API search :laughing:

2 Likes

Let’s gooo @mliu! :fire:

1 Like

Thanks, @tonykip, got my entry submitted to the hackathon :slight_smile:

2 Likes

Ayee good luck! :saluting_face:

1 Like

Hey All, sharing my experimental connection Kaggle-Streamlit, which allows a user to import Kaggle datasets in two lines of code :relieved:

https://kaggle-data-connector.streamlit.app/

3 Likes

Hi, @Oleksandr_Arsentiev
Thanks for sharing and good luck!

Hi All, I just submitted my first OpenWeartherMap API Connection. Checkout the app at here

2 Likes

Can you mention the timezone? Will I have to submit the connection on or before 4th August 2023, but what is the time?

1 Like

Yes, by midnight PST on August 4th.