-
Notifications
You must be signed in to change notification settings - Fork 6
Added markdown tutorial for couchbase_streamlit_connector #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2717f8c
added markdown tutorial for couchbase_streamlit_connector
VirajAgarwal1 49b9436
updated markdown tutorial for couchbase_streamlit_connector
VirajAgarwal1 7b4709d
changed streamlit tag
VirajAgarwal1 8ecb6a8
added description
VirajAgarwal1 f2a07e3
Added links to stremalit live demos
VirajAgarwal1 9a668c1
made updates to the markdown based on comments 1
VirajAgarwal1 27bbef8
made updates to the markdown based on comments 2
VirajAgarwal1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| --- | ||
| # frontmatter | ||
| path: "/tutorial-couchbase-streamlit-connector" | ||
| title: Couchbase Connector for Streamlit | ||
| short_title: Couchbase Connector for Streamlit | ||
| description: | ||
| - Learn how to integrate streamlit with Couchbase Capella | ||
| - Example on CRUD and query operations | ||
| content_type: tutorial | ||
| filter: sdk | ||
| technology: | ||
| - capella | ||
| - query | ||
| tags: | ||
| - Streamlit | ||
| sdk_language: | ||
| - python | ||
| length: 30 Mins | ||
| --- | ||
|
|
||
|
|
||
| # [Couchbase Connector for Streamlit](https://couchbase-st-tutorial.streamlit.app/) | ||
|
|
||
| ## 1. Introduction | ||
| 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 | ||
| ```bash | ||
| 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.py | ||
| ``` | ||
| Or you can jave a look at it through this link [Demo App](https://couchbase-connector-demo-app.streamlit.app/) | ||
|
|
||
| ## 2. Prerequisites | ||
| ### System Requirements | ||
| - Python 3.10 or higher installed. | ||
| - Ensure that the Python version is [compatible](https://docs.couchbase.com/python-sdk/current/project-docs/compatibility.html#python-version-compat) with the Couchbase SDK. | ||
| - Couchbase Capella account ([Docs](https://docs.couchbase.com/cloud/get-started/intro.html)) | ||
| - An operational cluster created in a project | ||
| - Configured cluster access permissions and allowed IP addresses ([Docs](https://docs.couchbase.com/cloud/get-started/connect.html#prerequisites)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also 1st point is only system requirement and rest are prerequisites. |
||
| - Connection string obtained from Couchbase Capella | ||
|
|
||
| ### Installing Dependencies | ||
| To install the required dependencies, run: | ||
| ```sh | ||
| git clone https://github.com/Couchbase-Ecosystem/couchbase_streamlit_connector.git | ||
| pip install ./couchbase_streamlit_connector/ | ||
|
||
| ``` | ||
|
|
||
| ## 3. Usage Guide | ||
|
|
||
| ### Initializing the Connector | ||
| You can set up the Couchbase connection using either of the following methods: | ||
|
|
||
| #### **Option 1: Using `secrets.toml` (Recommended)** | ||
| 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](https://docs.streamlit.io/develop/concepts/connections/secrets-management): | ||
|
|
||
| ```toml | ||
shyam-cb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [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: | ||
|
|
||
| ```python | ||
| import streamlit as st | ||
| from couchbase_streamlit_connector.connector import CouchbaseConnector | ||
|
|
||
| connection = st.connection( | ||
| "couchbase", | ||
| type=CouchbaseConnector | ||
| ) | ||
| st.help(connection) | ||
| ``` | ||
|
|
||
| #### **Option 2: Passing Credentials Directly (Alternative)** | ||
| Alternatively, you can pass the connection details as keyword arguments: | ||
|
|
||
| ```python | ||
| 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) | ||
| ``` | ||
|
|
||
| ### Performing CRUD Operations | ||
|
|
||
| #### **Insert a Document** | ||
| ```python | ||
| connection.insert_document("222", {"key": "value"}) | ||
| st.write(connection.get_document("222")) | ||
| ``` | ||
|
|
||
| #### **Fetch a Document** | ||
| ```python | ||
| st.write(connection.get_document("111")) | ||
| ``` | ||
|
|
||
| #### **Replace a Document** | ||
| ```python | ||
| connection.replace_document("222", {"new_key": "new_value"}) | ||
| st.write(connection.get_document("222")) | ||
| ``` | ||
|
|
||
| #### **Delete a Document** | ||
| ```python | ||
| connection.remove_document("222") | ||
| st.write("Document 222 deleted") | ||
| ``` | ||
|
|
||
| #### **Run a Query** | ||
| ```python | ||
| result = connection.query("SELECT * FROM `travel-sample`.`inventory`.`airline` LIMIT 5;") | ||
| st.write(result) | ||
| ``` | ||
shyam-cb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
combine above point and this into one