MagicStack / MagicStack/asyncpg

feat: allow connection with pre-configured socket

Open
#1,054 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
8.1k
Forks
468
PR merge metrics
No merged PRs in 30d

Description

I'd like to add support for creating a postgres connection over an existing socket like object. In this approach startTLS can or cannot be used depending on the caller. This lines up similarly with what we have in Java ([socketFactory connection param](https://jdbc.postgresql.org/documentation/use/#connection-parameters), [driver code](https://github.com/pgjdbc/pgjdbc/blob/aff581fe806f1c1cdc8bcd9e5a981e37691b44b5/pgjdbc/src/main/java/org/postgresql/core/SocketFactoryFactory.java#L25-L47)), Go ([pgx DialFunc](https://pkg.go.dev/github.com/jackc/pgconn#DialFunc)) (these two are slightly different as they allow specifying a creator/generator func that creates the socket, while here we could just pass in the socket directly but the extent of the feat is the same), and other Python libraries ([pymysql](https://github.com/PyMySQL/PyMySQL/blob/main/pymysql/connections.py#L626), and [pg8000](https://github.com/tlocke/pg8000/pull/136))

The equivalent pymysql PR that introduced this change explains the feature really well https://github.com/PyMySQL/PyMySQL/pull/355

The benefit of this feature is that it allows the user to specify their own secure tunnel to connect over (such as ssh).

Is this sort of feat possible for asyncpg?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing asyncpg's connection setup and compare the socketFactory, DialFunc, and PyMySQL references linked in the issue. Determine how an existing socket and optional startTLS would fit the API, then verify completion with coverage for both TLS choices and tunneled connections.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.