Is psycopg3 a fork of psycopg2, or a replacement upgrade?
Asked Answered
A

1

15

I see references to both psycopg2 and psycopg3, but no clear guidance wrt a roadmap for transitioning between the two. I see that over time there is a large body of SO questions regarding psycopg2.

Is psycopg3 intended to be a replacement for psycopg2? Has there been a significant uptake of this version?

Will there be a long-lived version of psycopg2? Are there any compelling reasons to choose one version over the other?

Anselmi answered 2/10, 2023 at 17:53 Comment(7)
"Is psycopg3 intended to be a replacement for psycopg2?" AFAICT, yes. "Has there been a significant uptake of this version?" AFAICT not yet. "Will there be a long-lived version of psycopg2?" they haven't said, but the last release was 3-4 days ago so I plan to keep using it until I have a compelling reason to switch for my own $0.02, FWIW.Brahma
@Woodford, good point... updated to clarify if "3" represents a fork or a version.Anselmi
I mean, is it really a fork if the same people are working on it? Seems like two different major versions: one in maintenance mode and one in active development - just like Python 2 and 3 for a long time.Necessity
@ColonelThirtyTwo, that's a good question. Do you know how long psycopg3 has been in development? and when people think that the world might be a psycopg3-majority place? I last used postgres in 2008, so you can imagine I'm not familiar at all with the state of the art!Anselmi
Some homework would have answered these questions. 1) First page of psycopg3 2) psycopg(3) differencesHeteronomous
@AdrianKlaver, actually the question came about from doing the homework of looking at psycopg.org. Both 2 and 3 seem to have roughly equivalent info boxes, hence my question. Along with, of course, the fact that 'pip install' seems to only work for psycopg2 and not psycopg3. Thanks for the links though, they're quite informative.Anselmi
1) Per the docs psycopg3 install pip install psycopg, pip install psycopg[binary] or pip install psycopg[c] should work depending on what form of psycopg you want to end up with and whether you have the necessary prerequisites installed. 2) psycopg(3) differences will show there are some significant differences.Heteronomous
N
11

From the documentation of psycopg3:

Psycopg 3 is a newly designed PostgreSQL database adapter for the Python programming language.

Psycopg 3 presents a familiar interface for everyone who has used Psycopg 2 or any other DB-API 2.0 database adapter, but allows to use more modern PostgreSQL and Python features, such as:

  • Asynchronous support
  • COPY support from Python objects
  • A redesigned connection pool
  • Support for static typing
  • Server-side parameters binding
  • Prepared statements
  • Statements pipeline
  • Binary communication
  • Direct access to the libpq functionalities

From a glance, psycopg3 appears to support more modern python and postgresql features like typing and async. Doing so likely required a lot of backwards-incompatible changes from psycopg2, hence the new version and forked development.

Necessity answered 2/10, 2023 at 18:0 Comment(2)
This is really annoying. The DB API specifies executemany(), and psycopg2 has long-acknowledged their deficiencies in implementation here. There is no mention of executemany in the docs you link. Unless they forgot this major issue, this was the time to revamp the default behaviour and they... didn't?Glasses
@Glasses I'm not sure why you're complaining about a random psycopg detail in my answer, but psycopg3 does have executemany and it does not have the warning that psycopg2 has.Necessity

© 2022 - 2024 — McMap. All rights reserved.