| path | /tutorial-couchbase-streamlit-connector | ||
|---|---|---|---|
| title | Couchbase Connector for Streamlit | ||
| short_title | Couchbase Connector for Streamlit | ||
| description |
|
||
| content_type | tutorial | ||
| filter | sdk | ||
| technology |
|
||
| tags |
|
||
| sdk_language |
|
||
| length | 30 Mins |
This project provides a seamless integration between Streamlit and Couchbase, allowing developers to interact with Couchbase databases effortlessly. It enables users to fetch, insert, update, and delete data within Streamlit applications without needing to switch between different SDKs, enhancing the overall development experience.
For a working demo please checkout src/Demo.py file. You can run it by the command
git clone https://github.com/Couchbase-Ecosystem/couchbase_streamlit_connector.git
cd ./couchbase_streamlit_connector
pip install -r requirements.txt
pip install plotly geopy numpy
streamlit run src/Demo.pyOr you can jave a look at it through this link Demo App
- Ensure you have Python 3.10 or higher (check compatibility with the Couchbase SDK), a Couchbase Capella account (Docs), and an operational cluster created in a project.
- Configured cluster access permissions and allowed IP addresses (Docs)
- Connection string obtained from Couchbase Capella
To install the required dependencies, run:
pip install couchbase-streamlit-connectorYou can set up the Couchbase connection using either of the following methods:
For better security and convenience, store your credentials in a .streamlit/secrets.toml file at the root of your project. Learn more about Streamlit Secrets Management:
[connections.couchbase]
CONNSTR = "<CONNECTION_STRING>"
USERNAME = "<CLUSTER_ACCESS_USERNAME>"
PASSWORD = "<CLUSTER_ACCESS_PASSWORD>"
BUCKET_NAME = "<BUCKET_NAME>"
SCOPE_NAME = "<SCOPE_NAME>"
COLLECTION_NAME = "<COLLECTION_NAME>"Then, initialize the connection in your Streamlit application:
import streamlit as st
from couchbase_streamlit_connector.connector import CouchbaseConnector
connection = st.connection(
"couchbase",
type=CouchbaseConnector
)
st.help(connection)Alternatively, you can pass the connection details as keyword arguments:
import streamlit as st
from couchbase_streamlit_connector.connector import CouchbaseConnector
connection = st.connection(
"couchbase",
type=CouchbaseConnector,
CONNSTR="<CONNECTION_STRING>",
USERNAME="<USERNAME>",
PASSWORD="<PASSWORD>",
BUCKET_NAME="<BUCKET_NAME>",
SCOPE_NAME="<SCOPE_NAME>",
COLLECTION_NAME="<COLLECTION_NAME>"
)
st.help(connection)connection.insert_document("222", {"key": "value"})
st.write(connection.get_document("222"))st.write(connection.get_document("111"))connection.replace_document("222", {"new_key": "new_value"})
st.write(connection.get_document("222"))connection.remove_document("222")
st.write("Document 222 deleted")result = connection.query("SELECT * FROM `travel-sample`.`inventory`.`airline` LIMIT 5;")
st.write(result)Here are some helpful resources for working with Couchbase and Streamlit: