
VerticaPy
Python API for Vertica Data Science at Scale
Create a connection using the new_connection function (Recommended)¶
The new_connection function provides an easy, accuracte way to create a connection in VerticaPy.
In [ ]:
import verticapy as vp
vp.new_connection({"host": "10.211.55.14",
"port": "5433",
"database": "testdb",
"password": "XxX",
"user": "dbadmin"},
name = "Vertica_New_Connection")
If you want to reconnect to an existing connection, use the connect function.
In [ ]:
vp.connect("Vertica_New_Connection")
Manually create a connection (Not recommended)¶
You can create a manual connection using any of the following methods:
Native with vertica_python (Best connector for Vertica)¶
In [ ]:
import vertica_python
conn_info = {'host': "10.211.55.14",
'port': 5433,
'user': "dbadmin",
'password': "XxX",
'database': "testdb"}
conn = vertica_python.connect(** conn_info)
# Setting the connection in the VerticaPy API
vp.set_connection(conn)
ODBC with pyodbc¶
In [ ]:
import pyodbc
# Option 1 - credentials
# Connecting with DSN credentials
driver = "/Library/Vertica/ODBC/lib/libverticaodbc.dylib"
server = "10.211.55.14"
database = "testdb"
port = "5433"
uid = "dbadmin"
pwd = "XxX"
dsn = ("DRIVER={}; SERVER={}; DATABASE={}; PORT={}; UID={}; PWD={};").format(driver,
server,
database,
port,
uid,
pwd)
conn = pyodbc.connect(dsn)
# Option 2 - DSN
# Connecting with the DSN
dsn = ("DSN=VerticaDSN")
conn = pyodbc.connect(dsn, autocommit = True)
# Setting the connection in the VerticaPy API
vp.set_connection(conn)
JDBC with jaydebeapi¶
In [ ]:
import jaydebeapi
# Vertica Server Details
database = "testdb"
hostname = "10.211.55.14"
port = "5433"
uid = "dbadmin"
pwd = "XxX"
# Vertica JDBC class name
jdbc_driver_name = "com.vertica.jdbc.Driver"
# Vertica JDBC driver path
jdbc_driver_loc = "/Library/Vertica/JDBC/vertica-jdbc-9.3.1-0.jar"
# JDBC connection string
connection_string = 'jdbc:vertica://' + hostname + ':' + port + '/' + database
url = '{}:user={};password={}'.format(connection_string, uid, pwd)
conn = jaydebeapi.connect(jdbc_driver_name,
connection_string,
{'user': uid, 'password': pwd},
jars = jdbc_driver_loc)
# Setting the connection in the VerticaPy API
vp.set_connection(conn)
Close a connection¶
You can use the close_connection function to close the connection.
In [ ]:
vp.close_connection()