vertica-python is the official native Python client for the Vertica Analytics Database. It provides a DB-API 2.0 compliant interface for connecting to and interacting with Vertica, supporting features like query execution, data retrieval, and bulk loading. Currently at version 1.4.0, the library maintains an active development pace with frequent minor releases addressing bug fixes, performance improvements, and new features.
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
from vertica_python import connect
from vertica_python import Error, DatabaseError, ProgrammingError
This quickstart demonstrates how to establish a connection to a Vertica database, create a table, insert data, and query it using the `vertica-python` client. It leverages environment variables for sensitive connection details and uses a `with` statement for proper connection and cursor management. Error handling is included to catch common database exceptions.
import vertica_python
import os
# Configure connection details using environment variables for security
conn_info = {
'host': os.environ.get('VERTICA_HOST', '127.0.0.1'),
'port': int(os.environ.get('VERTICA_PORT', 5433)),
'user': os.environ.get('VERTICA_USER', 'dbadmin'),
'password': os.environ.get('VERTICA_PASSWORD', 'password'),
'database': os.environ.get('VERTICA_DATABASE', 'verticadb'),
'read_timeout': 600, # 10 minutes timeout on queries
'unicode_error': 'strict', # default throw error on invalid UTF-8 results
'ssl': False # SSL is disabled by default, consider 'tlsmode' for production
}
try:
# Using 'with' statement for automatic connection closing
with vertica_python.connect(**conn_info) as connection:
print("Successfully connected to Vertica.")
with connection.cursor() as cursor:
# Execute a DDL statement
cursor.execute("DROP TABLE IF EXISTS my_test_table;")
cursor.execute("CREATE TABLE my_test_table (id INT, name VARCHAR(100));")
print("Table created.")
# Insert data
cursor.execute("INSERT INTO my_test_table (id, name) VALUES (1, 'Alice');")
cursor.execute("INSERT INTO my_test_table (id, name) VALUES (2, 'Bob');")
print("Data inserted.")
# Query data
cursor.execute("SELECT id, name FROM my_test_table;")
rows = cursor.fetchall()
print("Retrieved data:")
for row in rows:
print(f" ID: {row[0]}, Name: {row[1]}")
except vertica_python.Error as e:
print(f"An error occurred: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.
Agent activity
0 hits · last 30 days
No traffic data recorded yet.