又一个PostgreSQL数据库驱动程序
minipg的Python项目详细描述
另一个python postgresql数据库驱动程序。
纯Python或cythonhttp://cython.org/加速。
要求
- PostgreSQL 9.6+
- Python3.5+
安装
$ pip install minipg
示例
查询:
import minipg conn = minipg.connect(host='localhost', user='postgres', password='secret', database='database_name') cur = conn.cursor() cur.execute('select foo, bar from baz') for r in cur.fetchall(): print(r[0], r[1]) conn.close()
复制到:
import minipg conn = minipg.connect(host='localhost', user='postgres', password='secret', database='database_name') f = open('foo.txt', 'bw') conn.execute('COPY foo_table TO stdout', f) f.close() conn.close()
复制自:
import minipg conn = minipg.connect(host='localhost', user='postgres', password='secret', database='database_name') f = open('foo.txt', 'br') conn.execute('COPY foo_table FROM stdin', f) f.close() conn.close()
作为sqlalchemy方言:
from sqlalchemy.dialects import registry registry.register("postgresql.minipg", "minipg.dialect", "PGDialect_minipg") from sqlalchemy import create_engine engine = create_engine('postgresql+minipg://postgres:secret@host/database_name')
限制和不支持的功能
- 支持的身份验证方法只有“trust”、“md5”和“scram-sha-256”。
- 不完全支持数组数据类型。
- 不支持已准备好的声明。
对于micropython
见https://github.com/nakagami/micropg。 它是一个minipg子集驱动程序。