Streamlit Xata Data Base Connection
Introducing st-xatadb-connection Package!
To further enhance the synergy between Xata and Streamlit, I’ve created the st_xatadb_connection package. This package provides a seamless bridge between the two tools, making it incredibly easy to connect your Streamlit application to your Xata database.The st_xatadb_connection package takes care of all the heavy lifting, allowing you to focus on building your application’s functionality.
Why Use st-xatadb-connection ?
-
Seamless Integration:
- Effortlessly connect and interact with your Xata database using intuitive methods.
-
Comprehensive Functionality:
- Enjoy a rich set of functions, from basic queries to advanced AI interactions and file handling.
-
Secure Credentials Handling:
- Safely manage your Xata API key and database URL using Streamlit’s secrets manager or environment variables.
-
Boosted Productivity:
- Streamline your workflow with efficient data manipulation and advanced search capabilities.
-
Real-time Connectivity:
- Experience real-time interactions with your Xata database, keeping your data up-to-date.
-
AI Integration Made Easy:
- Pose questions to AI models effortlessly and engage in dynamic conversations with askai and askai_follow_up functions.
-
File Handling Simplified:
- Manage files seamlessly, including uploads, retrievals, and deletions with dedicated functions.
-
Data Aggregation and Summarization:
- Aggregate and summarize data effortlessly, gaining insights at your fingertips.
-
Advanced Schema Management:
- Dynamically create, delete, and modify tables and columns with ease.
-
Efficient Bulk Operations:
- Leverage bulk processing and transactions for lightning-fast database operations.
-
Image Transformation Capabilities:
- Transform images on-the-fly with the image_transform function.
-
Pagination for Large Datasets:
- Navigate through large datasets seamlessly with next_page and prev_page functions.
-
Developer-Friendly:
- Designed for developers by developers, ensuring a smooth and intuitive experience.
Features
Data Manipulation Made Easy
methods
- query: Execute queries on specific tables with precision.
- get: Retrieve records using record IDs.
- insert: Seamlessly insert records into tables.
- upsert: Replace records with ease.
- update: Effortlessly update records in your tables.
- delete: Remove records effortlessly.
Advanced Search Capabilities
methods
- search: Discover specific queries in a branch.
- search_on_table: Uncover data in a table using a search query.
- vector_search: Harness the power of vector searches.
Data Aggregation and Summarization
methods
- aggregate: Aggregate data based on queries.
- summarize: Summarize data in tables with precision.
Transaction Management
methods
- transaction: Perform transactions effortlessly.
- sql_query: Execute SQL queries seamlessly.
AI Integration
methods
- askai: Pose questions and receive AI-driven responses.
- askai_follow_up: Engage in dynamic conversations with AI models.
File Handling Made Simple
methods
- upload_file: Upload files to specific tables and records.
- get_file: Retrieve files with ease.
- delete_file: Effortlessly remove files from your database.
Image Transformation
methods
- image_transform: Transform images effortlessly.
Pagination and Schema Management
methods
- next_page: Retrieve the next page of results.
- prev_page: Access the previous page of results.
- get_schema: Explore table schemas dynamically.
Database Administration
methods
- create_table: Create new tables effortlessly.
- delete_table: Remove tables with precision.
- create_column: Add new columns seamlessly.
- delete_column: Effortlessly remove columns.
- get_columns: Retrieve table columns dynamically.
Bulk Operations and API Requests
methods
- bulk_processor: Facilitate bulk processing effortlessly.
- bulk_transaction: Manage bulk transactions seamlessly.
- api_request: Create custom API requests with ease.
Usage
1. Set up your Xata and Streamlit Environment
Create a Xata Account and Database at Xata.io:
- Sign up for Xata and establish your database for a seamless integration experience.
Generate Your API Key:
- Access your Xata account settings to generate a unique API key for secure connections.
Get Your Xata Database URL Endpoint:
- Retrieve the URL endpoint of your Xata database for streamlined connectivity.
Install st_xata_connection Package:
- Run
pip install st-xatadb-connection
.
2. Configure Your Xata Credentials
Securely Store Your Credentials:
- Safeguard your Xata API key and database URL using Streamlit’s secrets manager or environment variables.
Example Configuration:
- Set your Xata API key:
XATA_API_KEY = "YOUR_XATA_API_KEY"
- Define your Xata database URL:
XATA_DB_URL = "YOUR_XATA_DATABASE_URL"
3. Connect to Your Xata Database
Here’s a sneak peek into how incredibly simple it is to use st-xatadb_connection:
import streamlit as st
from st_xatadb_connection import XataConnection
# Connect to your Xata.io database
xata = st.connection('xata', type=XataConnection)
# Query your 'Table_name'
response = xata.query("Table_name")
# Display the query results in your Streamlit app
st.write(response)
The response looks like this:
{
"records": [
{
"id": "rec_c8hng2h26un90p8sr7k0",
"name": "Matrix",
"owner": {
"id": "myid"
},
"xata": {
"version": 0,
"createdAt": "2023-05-15T08:21:31.96526+01:00",
"updatedAt": "2023-05-15T21:58:54.072595+01:00"
}
}
],
"meta": {
"page": {
"cursor": "jMq7DcIwEIDhnjH-2sWRAsItAT2KkOU8bAgB3Zkqyu6IDei_",
"more": false
}
}
}
That’s it! With just a few lines of code, you’ve created a fully functional web application that displays data from your Xatadatabase.
Acknowledgements
I would like to express my gratitude to:
- Xata Team: For providing an exceptional database platform.
Package documentation: Docs
Learn More: Xata Docs
Why wait? Xata offers all these features for FREE!
Unleash your creativity, streamline your development, and build applications that make an impact.
Check Out the Demo Apps Below to See st_xatadb_connection in Action!
Try Xata Now and Build Your Own Apps for FREE!