Skip to main content

Wrapper around Kebolla python client to list tables, buckets and upload files to stage

Project description

streamlit-keboola-api

Streamlit custom component wrapping Keboola python client to list tables, buckets, delete table, delete bucket and upload files to stage.

Installation instructions

pip install streamlit-keboola-api

Usage instructions

from io import StringIO
import os
import streamlit as st
from pathlib import Path
import keboola_api as kb

def saveFile(uploaded):
    with open(os.path.join(os.getcwd(),uploaded.name),"w") as f:
        strIo= StringIO(uploaded.getvalue().decode("utf-8"))
        f.write(strIo.read())
        return os.path.join(os.getcwd(),uploaded.name)

def main():
    st.write("# Keboola upload button")
    st.write("## A Streamlit Custom component")
    with st.expander("Keboola Tables"):
        tables=kb.keboola_table_list(
                keboola_URL="https://connection.north-europe.azure.keboola.com",
                keboola_key='<key>',
                # Button Label
                label="GET TABLES",
                # Key is mandatory and has to be unique
                key="zero"
                # if api_only= True than the button is not shown and the api call is fired directly
                api_only=False
        )
        st.selectbox("Tables",options= list(map(lambda v: v['id'], tables)))
    with st.expander("Keboola Buckets"):    
        buckets=kb.keboola_bucket_list(
                keboola_URL="https://connection.north-europe.azure.keboola.com",
                keboola_key='<key>',
                # Button Label
                label="GET BUCKETS",
                # Key is mandatory and has to be unique
                key="one"
                # if api_only= True than the button is not shown and the api call is fired directly
                api_only=False
        )
        st.selectbox("Buckets",options= list(map(lambda v: v['id'], buckets)))
    url = "http://www.dickimaw-books.com/latex/admin/html/examples/booklist.csv"
    st.write("Get a sample CSV here [link](%s)" % url)    
    fl=st.file_uploader("Drop a csv...",type="csv")    
    if hasattr(fl,'name'):
        # Streamlit uploader doesn't save the file to disk, only in mem. 
        # We need to save the file to disk to send it to Keboola python client
        fpath=saveFile(fl)
        with st.expander("Keboola Upload files"):    
            value = kb.keboola_upload(
                keboola_URL="https://connection.north-europe.azure.keboola.com",
                keboola_key='<key>',
                keboola_table_name="test-anthony",
                keboola_bucket_id='in.c-streamlit_output',
                keboola_file_path=fpath,
                keboola_primary_key=['id'],
                # Button Label
                label="UPLOAD FILE",
                # Key is mandatory and has to be unique
                key="two"
                # if api_only= True than the button is not shown and the api call is fired directly
                api_only=False
            )
            value

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit-keboola-api-0.2.0.tar.gz (73.4 kB view hashes)

Uploaded Source

Built Distribution

streamlit_keboola_api-0.2.0-py3-none-any.whl (72.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page