pypyodbc
raw JSON → 1.3.6 verified Fri May 01 auth: no python
A pure Python ctypes-based ODBC module supporting multiple databases (SQL Server, Oracle, MySQL, PostgreSQL, SQLite, etc.). Current version 1.3.6 (2022-08-29). Release cadence is sporadic; last release fixed metadata issues from 1.3.5.
pip install pypyodbc Common errors
error Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified') ↓
cause ODBC driver not installed or DSN not configured.
fix
Install ODBC driver (e.g., msodbcsql17) and configure DSN or use full connection string.
error pypyodbc.DatabaseError: ('HY024', '[HY024] [Microsoft][ODBC Driver 17 for SQL Server]Invalid connection string attribute (0) (SQLDriverConnect)') ↓
cause Connection string syntax error, often missing semicolon or incorrect attribute.
fix
Check connection string format: 'DRIVER={...};SERVER=...;DATABASE=...;UID=...;PWD=...'.
error ModuleNotFoundError: No module named 'pypyodbc' ↓
cause pypyodbc not installed.
fix
Run 'pip install pypyodbc'.
Warnings
gotcha pypyodbc does not use pyodbc's function names like 'connect' directly on module level; you must use pypyodbc.connect(). ↓
fix Always call pypyodbc.connect() not pyodbc.connect().
gotcha Connection strings must be formatted for ODBC, not for native database drivers. For example, SQL Server requires 'DRIVER={ODBC Driver 17 for SQL Server};SERVER=...'. ↓
fix Use proper ODBC connection strings; see documentation.
gotcha On macOS/Linux, you need to install unixODBC and appropriate ODBC drivers. pypyodbc itself is pure Python but ODBC driver layer is not. ↓
fix Install unixODBC and driver (e.g., freetds, msodbcsql17).
Imports
- pypyodbc
import pypyodbc - DatabaseError
from pypyodbc import DatabaseError
Quickstart
import pypyodbc
# Replace with your actual DSN or connection string
connection = pypyodbc.connect('DSN=my_dsn;UID=user;PWD=password')
cursor = connection.cursor()
cursor.execute("SELECT 'Hello, World!' AS greeting")
for row in cursor.fetchall():
print(row['greeting'])
cursor.close()
connection.close()