Skip to main content

A lightweight client-server library fluently extending DuckDB's httpserver setup to Python

Project description

DuckBridge

Lightweight Python library enabling fully pythonic interfacing with the DuckDB extension httpserver (extension developed by @quackscience).

PyPI Build codecov

What is duckbridge?

DuckDB's httpserver extension turns databases into HTTP OLAP servers; however, setup and access require unix commands and SQL in order to properly set up authentication, install the extension, and communicate.

duckbridge spans this gap, providing a way to natively use httpserver with full pythonic scripting. The DuckDBServer class acts as the bridge operator, connecting to the database, initializing httpserver, and setting authentication values and read/write privileges. DuckDBClient provides a tidy handler which stores client-side authentication and endpoint information, ensuring one-factor authentication by way of knowledge while returning information as a Pandas DataFrame.

How do I use duckbridge?

Duckbridge is split into two main portions: DuckbridgeServer, which handles extension installation/activation, database connection, and client request processing, and DuckbridgeClient, which formats and sends requests to an assumed endpoint, unmarshalling returned data into a convenient format (currently only a Pandas DataFrame).

Examples of how to set up a server or client can be found in more depth at duckbridge-demo, a repository of tutorials that is constantly being updated.

If you have a use case that you would like to have considered, please open an issue and it will be addressed!

Quick start copy-and-paste

####################
### Server setup ###
####################
from duckbridge import *
import os

my_ssh_key_auth : str = "mySuperSecretSSHString"
ssh_userpass_auth : str = "username:password" # !!!The colon is mandatory!!!
my_host : str = "127.0.0.1" # Replace with 0.0.0.0 for public ip access
my_port : int = 8080

bridge : DuckbridgeServer = DuckbridgeServer()
# Assumes readonly permissions and that the database doesn't have `httpserver` installed yet
# If an empty string is provided for auth_info, then no security will be used
bridge.start(os.cwd() + "/path/to/db.db", host=my_host, port=my_port, auth_info=my_ssh_key_auth)


####################
### Client setup ###
####################
from duckbridge import *
import pandas as pd

my_username : str = "username"
my_password : str = "password"

client : DuckbridgeClient = DuckbridgeClient(my_host, my_port, my_username, my_password, my_ssh_key_auth)
data : pd.DataFrame = client.execute("Select * from concept limit 3;", auth="ssh")

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

duckbridge-0.4.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

duckbridge-0.4.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file duckbridge-0.4.1.tar.gz.

File metadata

  • Download URL: duckbridge-0.4.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for duckbridge-0.4.1.tar.gz
Algorithm Hash digest
SHA256 661984755354b9665050d9bac6c346793fc1f93c550d79c074308e5a0f1d6092
MD5 34ed0e45c9a1ec037c7c065dc4241f00
BLAKE2b-256 1894a32917e0198f4715c732ffd9409d9711691a388eb850257038e5b86555f9

See more details on using hashes here.

File details

Details for the file duckbridge-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: duckbridge-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for duckbridge-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ac70661a842af1b8cbd8aa18f47c1e26e451b4cc1fa095a5640894a2f082167a
MD5 49e0acb2c45c6b7bf082121e68deed3b
BLAKE2b-256 c59c2aeb62d677e742e994397b3145bd93a683bb504ccb5a0a0ebed41e70b50b

See more details on using hashes here.

Supported by

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