Skip to main content

PostgreSQL Server compiled into a Python Wheel.

Project description

postgresql-wheel

A Python wheel for Linux containing a complete, self-contained, locally installable PostgreSQL database server.

All servers run as the Python process user in a local path, so this wheel does not require root or sudo privledges. Databases can be initialized in any directory.

Servers can be setup and torn down in test fixtures with no additional outside dependencies.

Currently this wheel only works for most flavors of Linux.

Postgres is compiled in the same "manylinux" environments provided by the cibuildwheel tool using Github Actions and directly archived into the wheel's "package_data".

The wheel can be installed with pip:

$ pip install postgresql-wheel

Postgres binaries in the package can be found in the directory pointed to by the postgresql.pg_bin global variable. Function wrappers around all of the postgres binary programs, like initdb and pg_ctl functions are provided for convenience:

>>> 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')

For the purposes of testing, convenience functions are provided for setting up and tearing down databases:

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

There is also a pytest fixture called tmp_postgres that returns a new connection string to a temporary database local domain socket, and can be used in a pytest:

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

postgresql_wheel-14.1.2-pp38-pypy38_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

postgresql_wheel-14.1.2-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (16.8 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

postgresql_wheel-14.1.2-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.7 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

postgresql_wheel-14.1.2-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (16.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

postgresql_wheel-14.1.2-cp39-cp39-musllinux_1_1_x86_64.whl (16.7 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

postgresql_wheel-14.1.2-cp39-cp39-musllinux_1_1_i686.whl (16.8 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

postgresql_wheel-14.1.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

postgresql_wheel-14.1.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (14.5 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

postgresql_wheel-14.1.2-cp38-cp38-musllinux_1_1_x86_64.whl (17.1 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

postgresql_wheel-14.1.2-cp38-cp38-musllinux_1_1_i686.whl (17.2 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

postgresql_wheel-14.1.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.7 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

postgresql_wheel-14.1.2-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (14.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

postgresql_wheel-14.1.2-cp37-cp37m-musllinux_1_1_x86_64.whl (16.7 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

postgresql_wheel-14.1.2-cp37-cp37m-musllinux_1_1_i686.whl (16.8 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ i686

postgresql_wheel-14.1.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.5 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

postgresql_wheel-14.1.2-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (14.4 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page