Skip to content

patricktrainer/motherduck-connection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Streamlit MotherDuck Connection πŸ¦†

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.

🌟 Features

  • Simple connection establishment to MotherDuck using DuckDB.
  • Execute SQL queries and fetch results as DataFrames.
  • Cache support for repetitive queries to boost performance.

πŸ”§ Installation

pip install motherduck-connection

πŸš€ Usage

Establishing a 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).

Executing Queries

Use the query method of the MotherDuckConnection instance to run SQL queries and fetch results.

πŸ“– Example Application: app.py

This example showcases how you can employ the MotherDuckConnection library in a Streamlit app to query MotherDuck.

🌐 Features:

  1. DuckDB Table Query: Showcases a table from MotherDuck's sample data, displaying the top 20 stories from Hacker News.
  2. Replies to a HN Post: Lets users input a Hacker News post ID and fetches related replies.
  3. Current HN Front Page: Displays the present front page of Hacker News.

πŸƒ Running the Example:

Navigate to the examples directory and run:

streamlit run app.py

πŸ“š Helper Functions: motherduck_sql.py

Offers functions to aid in querying data from MotherDuck and the Hacker News API.

πŸ“‹ Functions:

  1. get_hn_item(id): Fetches the URL to retrieve an item from Hacker News.
  2. get_hn_front_page(): Gets the URL for Hacker News front page items.
  3. query_hn_front_page(conn): Queries Hacker News front page with a MotherDuck connection, returning a DataFrame.
  4. query_hn_items(conn, hn_item_id_input): Fetches an item and its comments from Hacker News based on a given ID.
  5. query_motherduck(conn, table_name): Queries a table from MotherDuck, fetching 'story' type items.

πŸ“œ License

See the LICENSE file for details.

About

A Streamlit connection to MotherDuck πŸ¦†

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages