postgresql PyGreSQL 与 psycopg2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/413228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 23:37:38  来源:igfitidea点击:

PyGreSQL vs psycopg2

pythonpostgresql

提问by maxp

What is the difference between these two apis? Which one faster, reliable using Python DB API?

这两个api有什么区别?哪个使用 Python DB API 更快、更可靠?

Upd:I see two psql drivers for Django. The first one is psycopg2. What is the second one? pygresql?

更新:我看到两个用于 Django 的 psql 驱动程序。第一个是psycopg2。第二个是什么?pygresql?

采纳答案by maxp

For what it's worth, django uses psycopg2.

对于它的价值,django 使用 psycopg2。

回答by maxp

"PyGreSQL is written in Python only, easy to deployed but slower."

“PyGreSQL 仅用 Python 编写,易于部署但速度较慢。”

PyGreSQL contains a C-coded module, too. I haven't done speed tests, but they're not likely to be much different, as the real work will happen inside the database server.

PyGreSQL 也包含一个 C 编码模块。我没有做过速度测试,但它们不太可能有太大不同,因为真正的工作将在数据库服务器内部进行。

回答by thethinman

Psycopg2 doesn't have much documentation but the code in the examples directory is very helpful.
Also it's thread safety level 2, meaning multiple threads can share the module and connections but not the cursors.
python dbi pep

Psycopg2 没有太多文档,但示例目录中的代码非常有用。
它也是线程安全级别 2,这意味着多个线程可以共享模块和连接,但不能共享游标。
蟒蛇 dbi pep

回答by Ali Afshar

Licensing may be an issue for you. PyGreSQL is MIT license. Psycopg2 is GPL license.

许可对您来说可能是一个问题。PyGreSQL 是 MIT 许可证。Psycopg2 是 GPL 许可证。

(as long as you are accessing psycopg2 in normal ways from Python, with no internal API, and no direct C calls, this shouldn't cause you any headaches, and you can release your code under whatever license you like - but I am not a lawyer).

(只要您从 Python 以正常方式访问 psycopg2,没有内部 API,也没有直接的 C 调用,这应该不会让您感到头疼,您可以根据您喜欢的任何许可证发布您的代码 - 但我不是律师)。

回答by Seb

psycopg2 is partly written in C so you can expect a performance gain, but on the other hand, a bit harder to install. PyGreSQL is written in Python only, easy to deployed but slower.

psycopg2 部分是用 C 编写的,因此您可以期待性能提升,但另一方面,安装起来有点困难。PyGreSQL 仅用 Python 编写,易于部署但速度较慢。