Skip to main content

PostgreSQL 服务器编译成 Python Wheel。

项目描述

postgresql 轮

一个用于 Linux 的 Python 轮,包含一个完整的、独立的、可本地安装的 PostgreSQL 数据库服务器。

所有服务器在本地路径中以 Python 进程用户身份运行,因此此轮不需要 root 或 sudo 权限。数据库可以在任何目录中初始化。

可以在测试夹具中设置和拆除服务器,而无需额外的外部依赖。

目前这个轮子只适用于大多数版本的 Linux。

Postgres 使用Github Actions在cibuildwheel 工具提供的相同“manylinux”环境中编译, 并直接归档到轮子的“package_data”中。

轮子可以用pip安装:

$ pip install postgresql-wheel

postgresql.pg_bin包中的 Postgres 二进制文件可以在全局变量指向的目录中找到。为方便起见,提供了所有 postgres 二进制程序的函数包装器,如initdbpg_ctl 函数:

>>> from postgresql import initdb, pg_ctl
>>> initdb('-D testdatabase')
>>> pg_ctl('-D testdatabase -o "-p 5678" -l testdatabase.log start')

>>> import psycopg2
>>> c = psycopg2.connect("postgres://localhost:5678/postgres") # connect with local client
>>> with c.cursor() as q:
>>>     q.execute("select version()")
>>>     print(q.fetchall())
...
[('PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3), 64-bit',)]
>>> pg_ctl('-D testdatabase stop')

为了测试的目的,提供了方便的函数来建立和拆除数据库:

>>> pgdata, con_str = postgresql.setup()
>>> postgresql.psql(f'-h {con_str} -c "select version()"')
>>> postgresql.teardown(pgdata)

还有一个称为 pytest 固定装置tmp_postgres,它将一个新的连接字符串返回到一个临时数据库本地域套接字,并且可以在 pytest 中使用:

>>> from postgresql import tmp_postgres
>>> def test_foo(tmp_postgres):
...    postgresql.psql(f'-h {tmp_postgres} -c "select version()"')

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

内置发行版

postgresql_wheel-14.1.2-cp39-cp39-musllinux_1_1_x86_64.whl (16.7 kB 查看哈希

已上传 cp39

postgresql_wheel-14.1.2-cp39-cp39-musllinux_1_1_i686.whl (16.8 kB 查看哈希

已上传 cp39

postgresql_wheel-14.1.2-cp38-cp38-musllinux_1_1_x86_64.whl (17.1 kB 查看哈希

已上传 cp38

postgresql_wheel-14.1.2-cp38-cp38-musllinux_1_1_i686.whl (17.2 kB 查看哈希

已上传 cp38

postgresql_wheel-14.1.2-cp37-cp37m-musllinux_1_1_x86_64.whl (16.7 kB 查看哈希

已上传 cp37

postgresql_wheel-14.1.2-cp37-cp37m-musllinux_1_1_i686.whl (16.8 kB 查看哈希

已上传 cp37