Skip to content

python: Use direct TLS connections for psycopg2#167

Merged
danielfrankcom merged 1 commit intomainfrom
feat/native-direct-tls-psycopg2
May 30, 2025
Merged

python: Use direct TLS connections for psycopg2#167
danielfrankcom merged 1 commit intomainfrom
feat/native-direct-tls-psycopg2

Conversation

@danielfrankcom
Copy link
Copy Markdown
Contributor

This PR modifies the psycopg2 sample to set sslnegotiation=direct as per #150.

It does this conditionally based on the underlying libpq version, since the same psycopg2 version can be used with multiple versions of libpq. I verified in the release notes here that sslnegotiation has been available since the 17.0 release and was not added as a minor version bump.

At the time of writing, the psycopg2-binary package includes libpq 16.0, which doesn't support the sslnegotiation parameter. I manually checked a version of psycopg2 compiled against libpq 17.4 and the direct TLS connection worked properly. I have kept the sample dependency on the pre-built binary, as it's more approachable in terms of the system requirement for running the sample. If/when psycopg2-binary is updated to include libpq 17.0+, it will start using sslnegotiation without any changes here.

I added a section to the README.md file which describes more about the TLS configuration, and calls out that direct TLS connections are a new feature and may not be supported by all driver versions. This section was already reviewed in #160, and will be added to all samples which support direct TLS connections.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT-0 license.

Copy link
Copy Markdown
Contributor

@leszek-bq leszek-bq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@danielfrankcom danielfrankcom merged commit 4ce19b0 into main May 30, 2025
3 checks passed
@danielfrankcom danielfrankcom deleted the feat/native-direct-tls-psycopg2 branch May 30, 2025 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants