Skip to main content

A local client for working with Python and MotherDuck

Project description

shipyard-motherduck

Installation

python3 -m pip install shipyard-motherduck

Usage

In order to initalize the client, pass the access token to the MotherDuckClient object:

client = MotherDuckClient("<access_token>")

Additionally you can connect to a specifc database by supplying the database to the client:

client = MotherDuckClient("<access_token>", database = 'my_db')

Loading Data

The upload method allows for a quick upload of a file to a table in MotherDuck. If the table does not exist, it will be created. The target table can also be appended to by setting the insert_method to 'append'.

Example:

client.upload(table_name = 'my_new_table', file_path = 'my_data.csv', insert_method = 'replace')

Fetching Data

The fetch method returns the results of a SQL query as a DuckDBPyRelation type. From there, it can be converted to a DataFrame or written to a file.

Example:

results = client.fetch('select * from my_new_table')
df = results.to_df()

Executing a Query

The execute_query method executes a SQL query in MotherDuck. The difference between this and the fetch method is that this does not return results and is intended for ALTER, CREATE, DROP and other DDL queries.

Example:

client.execute_query('DROP TABLE my_new_table')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shipyard_motherduck-0.1.0.tar.gz (4.8 kB view hashes)

Uploaded Source

Built Distribution

shipyard_motherduck-0.1.0-py3-none-any.whl (7.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page