Connect to MotherDuck from your Streamlit app seamlessly. This library, powered by st.experimental_connection()
, offers a straightforward interface to establish and manage your connection to a MotherDuck database.
- Simple connection establishment to MotherDuck using DuckDB.
- Execute SQL queries and fetch results as DataFrames.
- Cache support for repetitive queries to boost performance.
pip install motherduck-connection
Initiate an instance of the MotherDuckConnection
class from the motherduck_connection
module. Optionally provide a database path. If omitted, it'll connect to the default database (my_db
).
Use the query
method of the MotherDuckConnection
instance to run SQL queries and fetch results.
This example showcases how you can employ the MotherDuckConnection
library in a Streamlit app to query MotherDuck.
- DuckDB Table Query: Showcases a table from MotherDuck's sample data, displaying the top 20 stories from Hacker News.
- Replies to a HN Post: Lets users input a Hacker News post ID and fetches related replies.
- Current HN Front Page: Displays the present front page of Hacker News.
Navigate to the examples
directory and run:
streamlit run app.py
Offers functions to aid in querying data from MotherDuck and the Hacker News API.
- get_hn_item(id): Fetches the URL to retrieve an item from Hacker News.
- get_hn_front_page(): Gets the URL for Hacker News front page items.
- query_hn_front_page(conn): Queries Hacker News front page with a MotherDuck connection, returning a DataFrame.
- query_hn_items(conn, hn_item_id_input): Fetches an item and its comments from Hacker News based on a given ID.
- query_motherduck(conn, table_name): Queries a table from MotherDuck, fetching 'story' type items.
See the LICENSE file for details.