Skip to main content

Python 3 DB-API and SQLAlchemy dialect to connect to duckdb over http i.e ( Radio-Duck = https://github.com/jaihind213/radio-duck )

Project description

District 5

Python 3 DB-API and SQLAlchemy dialect to connect to duckdb over http i.e ( Radio-Duck )

(inspiried by my favourite movie Mighty ducks - district5 was the original team name for the mighty ducks )

Requirements

cd PROJECT_DIR
mamba create -n district5 python=3.9
mamba activate district5
mamba install poetry
poetry install

Run Tests

#-without integration test
pytest -m "not integration_test" 
#-with integration test
docker run -d -p 8000:8000 -t jaihind213/radio-duck:latest
pytest

Let's try it out:

#python 3.9^
pip install district5
#start the duckdb server i.e. radio-duck
docker run -p 8000:8000 -t jaihind213/radio-duck:latest
#the duckdb starts up with a sample table whose ddl is: 
#'create table pond(duck_type string, total int)'
echo "we will try to query that"

from sqlalchemy import create_engine, text
from sqlalchemy.dialects import registry

registry.register(
    "radio_duck.district5", "radio_duck.sqlalchemy", "RadioDuckDialect"
)


#run docker instance of radio-duck
#docker run -p 8000:8000 -t jaihind213/radio-duck:latest
engine = create_engine(
    "radio_duck+district5://user:pass@localhost:8000/?api=/v1/sql/&scheme=http"
)
# Establish a database connection
conn = engine.connect()

# Define a SQL query using qmark style or positional style
try:
    query_1 = text("""SELECT duck_type, total FROM pond where total > :total""")
    params = {"total": 0}
    result = conn.execute(query_1, params)
    # Fetch and print the results
    for row in result:
        print(row)

    print("--------------")
    query_2 = "SELECT duck_type, total FROM pond where total > ?"
    result = conn.execute(query_2, (0,))

    for row in result:
        print(row)

except Exception as e:
    print(f"An error occurred: {e}")

finally:
    # Close the database connection
    conn.close()
    engine.dispose()

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

district5-0.1.18.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

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

district5-0.1.18-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file district5-0.1.18.tar.gz.

File metadata

  • Download URL: district5-0.1.18.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.9.18 Linux/6.2.0-1018-azure

File hashes

Hashes for district5-0.1.18.tar.gz
Algorithm Hash digest
SHA256 d6fe49ac87f54655d481c1d6eb579e989a0c3d7689ac098dce1abb206a3a77a2
MD5 2d350f5e79cfaeb97f8d663e540bea93
BLAKE2b-256 616cd9ccd16ac3cb2b3558fa2c5002ac7e49289308897029a636d93400d02f78

See more details on using hashes here.

File details

Details for the file district5-0.1.18-py3-none-any.whl.

File metadata

  • Download URL: district5-0.1.18-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.9.18 Linux/6.2.0-1018-azure

File hashes

Hashes for district5-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 e2a72813d14c395824680e44ea6ef487ecbabf9f017fc0dc7abde24de760be1a
MD5 4a3a89a2b296eb512d19a99398ef4e5e
BLAKE2b-256 6d13179324e150c82c036af70e3415c3afa8510e8ddb625da98f32954351abe1

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