SQLAlchemy Vertica Dialect (sqlalchemy-vertica-python)

0.6.3 · active · verified Thu Apr 16

sqlalchemy-vertica-python is a Vertica dialect for SQLAlchemy that utilizes the pure-Python DB-API driver `vertica-python` for database connectivity. It is currently at version 0.6.3, actively maintained by BlueLabs, and typically releases updates to align with SQLAlchemy versions or address bugs.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a connection to a Vertica database using `sqlalchemy-vertica-python` and execute a simple query to retrieve the database version. Ensure your Vertica instance is accessible and replace placeholder credentials with actual environment variables or direct values.

import os
from sqlalchemy import create_engine, text

# Environment variables for connection details (replace with your Vertica credentials)
VERTICA_USER = os.environ.get('VERTICA_USER', 'dbadmin')
VERTICA_PASSWORD = os.environ.get('VERTICA_PASSWORD', 'password')
VERTICA_HOST = os.environ.get('VERTICA_HOST', 'localhost')
VERTICA_PORT = os.environ.get('VERTICA_PORT', '5433')
VERTICA_DB = os.environ.get('VERTICA_DB', 'VMart')

# Construct the connection string
connection_string = (
    f"vertica+vertica_python://{VERTICA_USER}:{VERTICA_PASSWORD}"
    f"@{VERTICA_HOST}:{VERTICA_PORT}/{VERTICA_DB}"
)

try:
    # Create an engine instance
    engine = create_engine(connection_string)

    # Establish a connection
    with engine.connect() as connection:
        # Execute a simple query
        result = connection.execute(text("SELECT version();"))
        
        # Fetch and print the result
        for row in result:
            print(f"Connected to Vertica. Version: {row[0]}")

except Exception as e:
    print(f"Error connecting to Vertica or executing query: {e}")

view raw JSON →