{"id":2352,"library":"vertica-python","title":"Vertica Python Client","description":"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.","status":"active","version":"1.4.0","language":"en","source_language":"en","source_url":"https://github.com/vertica/vertica-python","tags":["database","vertica","sql","client","analytics"],"install":[{"cmd":"pip install vertica-python","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for Kerberos authentication support on Unix-like systems.","package":"kerberos","optional":true}],"imports":[{"symbol":"vertica_python","correct":"import vertica_python"},{"symbol":"connect","correct":"from vertica_python import connect"},{"symbol":"Error","correct":"from vertica_python import Error, DatabaseError, ProgrammingError"}],"quickstart":{"code":"import vertica_python\nimport os\n\n# Configure connection details using environment variables for security\nconn_info = {\n    'host': os.environ.get('VERTICA_HOST', '127.0.0.1'),\n    'port': int(os.environ.get('VERTICA_PORT', 5433)),\n    'user': os.environ.get('VERTICA_USER', 'dbadmin'),\n    'password': os.environ.get('VERTICA_PASSWORD', 'password'),\n    'database': os.environ.get('VERTICA_DATABASE', 'verticadb'),\n    'read_timeout': 600, # 10 minutes timeout on queries\n    'unicode_error': 'strict', # default throw error on invalid UTF-8 results\n    'ssl': False # SSL is disabled by default, consider 'tlsmode' for production\n}\n\ntry:\n    # Using 'with' statement for automatic connection closing\n    with vertica_python.connect(**conn_info) as connection:\n        print(\"Successfully connected to Vertica.\")\n        with connection.cursor() as cursor:\n            # Execute a DDL statement\n            cursor.execute(\"DROP TABLE IF EXISTS my_test_table;\")\n            cursor.execute(\"CREATE TABLE my_test_table (id INT, name VARCHAR(100));\")\n            print(\"Table created.\")\n\n            # Insert data\n            cursor.execute(\"INSERT INTO my_test_table (id, name) VALUES (1, 'Alice');\")\n            cursor.execute(\"INSERT INTO my_test_table (id, name) VALUES (2, 'Bob');\")\n            print(\"Data inserted.\")\n\n            # Query data\n            cursor.execute(\"SELECT id, name FROM my_test_table;\")\n            rows = cursor.fetchall()\n            print(\"Retrieved data:\")\n            for row in rows:\n                print(f\"  ID: {row[0]}, Name: {row[1]}\")\n\nexcept vertica_python.Error as e:\n    print(f\"An error occurred: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to 3.7 or newer. If you must use Python 2, you will need to pin vertica-python to a version prior to 1.3.0, which is not recommended as it is no longer maintained.","message":"Starting with version 1.3.0, vertica-python dropped support for Python 2.x. The library now explicitly requires Python 3.7 or higher.","severity":"breaking","affected_versions":">=1.3.0"},{"fix":"Review your authentication configuration. If you were relying on the `crypt` package's functionality, consider migrating to newer, more secure authentication methods supported by Vertica and vertica-python (e.g., OAuth 2.0 or Kerberos if applicable).","message":"The `crypt` package, which was used for certain authentication mechanisms, has been deprecated in version 1.3.0. While still functional, users should be aware that its use is discouraged.","severity":"deprecated","affected_versions":">=1.3.0"},{"fix":"Replace `ssl: True/False` in your `conn_info` dictionary with `tlsmode: 'require'`, `tlsmode: 'verify-ca'`, or `tlsmode: 'verify-full'` as appropriate for your security requirements. Ensure any necessary `tls_cafile`, `tls_certfile`, and `tls_keyfile` paths are also provided for certificate verification modes.","message":"The `ssl` connection option for enabling TLS/SSL has been deprecated. Users should now use the `tlsmode` connection option for more granular control over TLS security levels (e.g., 'disable', 'require', 'verify-ca', 'verify-full).","severity":"deprecated","affected_versions":">=1.4.0"},{"fix":"After `cursor.execute()`, if you expect results from multiple statements, iterate through them using a loop with `while cursor.nextset():` and then `cursor.fetchall()` for each set.","message":"When executing multiple SQL statements in a single `cursor.execute()` call, only the results from the first statement are immediately accessible. To retrieve results from subsequent statements, you must explicitly call `cursor.nextset()`.","severity":"gotcha","affected_versions":"All"},{"fix":"It is recommended to always call a `fetch` method (e.g., `cursor.fetchall()`) after `cursor.execute()` to ensure all errors are captured, especially when dealing with multiple statements.","message":"Errors occurring in later statements of a multiple-statement query (or some other specific cases) might not raise an exception immediately during `cursor.execute()`. Instead, they might only be raised when `cursor.fetchone()`, `cursor.fetchmany()`, or `cursor.fetchall()` is called.","severity":"gotcha","affected_versions":"All"},{"fix":"Define VARCHAR column lengths with sufficient buffer for multi-byte characters, or consider using `LONG VARCHAR` for potentially large or unpredictable string data. Ensure your Python strings are correctly encoded (vertica-python uses UTF-8 by default for unicode_error='strict').","message":"Vertica's VARCHAR length is defined in bytes, not characters. When working with multi-byte UTF-8 characters (e.g., emojis or certain international characters), a VARCHAR(10) might only be able to store a few characters, leading to 'String data right truncation' errors if not accounted for.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}