ibm-db-sa is a SQLAlchemy dialect that enables Python applications to connect to IBM Db2 for LUW, Db2 on Cloud, and Informix data servers. It provides an interface for SQLAlchemy's ORM and core features, leveraging the `ibm_db` DBAPI driver for database communication. The current version is 0.4.4, with releases typically following updates in its core dependencies, `ibm_db` and `SQLAlchemy`.
pip install ibm_db_saVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to establish a connection to an IBM Db2 or Informix database using `ibm-db-sa` with SQLAlchemy. It retrieves connection parameters from environment variables for security and flexibility. The example executes a simple query to fetch the current timestamp, printing the result or any connection error.
Ensure all literal SQL strings are wrapped with `sqlalchemy.text()` (e.g., `connection.execute(text('SELECT 1'))`) for SQLAlchemy 1.4+ / 2.0 compatibility.Before installing `ibm_db` or `ibm_db_sa`, ensure you have the appropriate IBM Data Server Client or Driver Package installed and configured for your operating system. Refer to the `ibm_db` documentation for specific installation instructions.
When connecting to Informix, append `?INFORMIXSERVER=<servername>` to your connection string. Example: `ibm_db_sa://user:pass@host:port/database?INFORMIXSERVER=myserver`.
For SSL connections, add `SECURITY=SSL;SSLCLIENTKEYSTOREDB=/path/to/keystore.kdb;SSLCLIENTKEYSTASH=/path/to/keystore.sth` or similar parameters to your connection string's query part (e.g., `?security=SSL;...`). Consult IBM Db2 documentation for full SSL setup.
Verify the `DB2_DATABASE` (or equivalent) parameter in your connection string matches the actual database name on your Db2 server.
Check the `DB2_HOST` and `DB2_PORT` values in your connection string. Ensure the Db2 server is running and network access is permitted from your client machine (e.g., firewall rules).
Install the appropriate IBM Data Server Driver Package for your operating system. Ensure its `bin` (or equivalent) directory is added to your system's PATH environment variable (Windows) or `LD_LIBRARY_PATH` (Linux/macOS).
Carefully re-check your username and password in the connection string. Ensure they are correct for the specified database and user. Also, verify that the user has necessary permissions to connect to the database.