Skip to main content

Self-contained postgres server for your python applications

Project description

pgserver: pip-installable postgres + pgvector for your python app

pip install pgserver

pgserver lets you initialize (if needed) and run a Postgres server associated with a data dir within your Python app, with server binaries included. Wheels are built for multiple platforms.

Example use cases:

  • The main motivation is to enable building Postgres-backed python apps that remain pip-installable, saving you and, more importantly, your users any need to install and setup postgres.
  • The second advantage is avoid remembering how to set-up a local postgres server, instead you immediately get a sqlalchemy or psql usable URI string and get to work.
  • Also possible: developing and testing apps that depend on some external Postgres (as a dev dependency)

Basic summary:

  • Pip installable binaries: tested on Ubuntu and MacOS (apple silicon + x86), including pgvector extension.
  • No sudo needed: Does not require root or sudo.
  • Simpler initialization: pgserver.get_server(MY_DATA_DIR) method to initialize data and server if needed, so you don't need to understand initdb, pg_ctl, port conflicts, and skip debugging why you still cannot connect to the server, just do server.get_uri() to connect. Uses unix domain sockets to avoid port conflicts.
  • Convenient cleanup: server process cleanup is done for you: when the process using pgserver ends, the server is shutdown, including when multiple independent processes call pgserver.get_server(MY_DATA_DIR) on the same dir (wait for last one)
    • includes context manager protocol to explicitly control cleanup timing in testing scenarios.
  • For lower-level control, wrappers to all binaries, such as initdb, pg_ctl, psql, pg_config. Includes header files in case you wish to build some other extension and use it against these binaries.
# Example 1: postgres backed application
import pgserver

pgdata = f'{MY_APP_DIR}/pgdata'
db = pgserver.get_server(pgdata)
# server ready for connection.

print(db.psql('create extension vector'))
db_uri = db.get_uri()
# use uri with sqlalchemy / psycopg, etc

# if no other process is using this server, it will be shutdown at exit,
# if other process use same pgadata, server process will be shutdown when all stop.
# Example 2: Testing
import tempfile
import pytest
@pytest.fixture
def tmp_postgres():
    tmp_pg_data = tempfile.mkdtemp()
    with pgserver.get_server(tmp_pg_data, cleanup_mode='delete') as pg:
        yield pg

Postgres binaries in the package can be found in the directory pointed to by the pgserver.pg_bin global variable.

Based on https://github.com/michelp/postgresql-wheel, but with the following differences:

  1. Wheels for multiple platforms (ubuntu x86, +MacOS x86, +MacOS apple silicon), pull requests taken for ubuntu arm.
  2. pgvector extension included
  3. postgres Server management: cleanup via shared count when multiple processes use the same server.
  4. no postGIS (need to build cross platform, pull requests taken)

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

pgserver-0.0.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.0 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pgserver-0.0.7-cp311-cp311-macosx_11_0_arm64.whl (13.1 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

pgserver-0.0.7-cp311-cp311-macosx_10_9_x86_64.whl (14.0 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pgserver-0.0.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.0 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pgserver-0.0.7-cp310-cp310-macosx_11_0_arm64.whl (13.1 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pgserver-0.0.7-cp310-cp310-macosx_10_9_x86_64.whl (14.0 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pgserver-0.0.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.0 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pgserver-0.0.7-cp39-cp39-macosx_11_0_arm64.whl (13.1 MB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pgserver-0.0.7-cp39-cp39-macosx_10_9_x86_64.whl (14.0 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

File details

Details for the file pgserver-0.0.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pgserver-0.0.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 23dbca7e7e1231c4a287f819c89458b1828751ca8426bf2e3b10e171e8aaf089
MD5 303e6cc8f7abd8f69898c86938d326d3
BLAKE2b-256 f726eb5edfc5d884592f6915e10dcb59c796c28e001d454c04fe5dbffdb9c68f

See more details on using hashes here.

File details

Details for the file pgserver-0.0.7-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pgserver-0.0.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7a7e0f76099780cc7fedc9811a7bd4ab5b5fe40790ffafd5e3b3de0323c1bb82
MD5 23955e74e813922964fe73d0a296e5a8
BLAKE2b-256 482f49605bcfda1359d66f2423880541d11f760eb2e6885a66062595186babd3

See more details on using hashes here.

File details

Details for the file pgserver-0.0.7-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pgserver-0.0.7-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5c7a504d0152e76939b3430bff91739e03a5b7f03e651e51715b1617aa09a400
MD5 ccea5e22c5c0e095bdd4aa73c2153ef4
BLAKE2b-256 8ed9522d59a38b0b625e4bacfeb848c7e990a2b8223d5de8515a2623d1686753

See more details on using hashes here.

File details

Details for the file pgserver-0.0.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pgserver-0.0.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 13ef11fb24ba35068b1dc997f31ac3b1223fb5f323bdc236f059cb7ae53f22f7
MD5 29ed916d6cebfe84ed8608562a8f0658
BLAKE2b-256 e18c4c86e457085c82c763ed0466e445313ce6c61b411ba791e664b009002190

See more details on using hashes here.

File details

Details for the file pgserver-0.0.7-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pgserver-0.0.7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d4325c33d514cdc0aef8735330e08071f8c953a11cc732e15a162452a122de1e
MD5 e29c5e67ef916dd8d1f60e3de0ca6c59
BLAKE2b-256 3d3b4afb0964af04fc06ea68c4b412019c7247034cc39f475a726b23d1632e72

See more details on using hashes here.

File details

Details for the file pgserver-0.0.7-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pgserver-0.0.7-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2122113afa8aab14ff10848c2c8dbe575359adef834ec74401dca4aa8cc24261
MD5 08a22c3da136ac5769c6a2e4a7c89f44
BLAKE2b-256 f0dfb0a5d68927c896025a13c6b03ca9f59fbe537601dff459e881b7344bdabb

See more details on using hashes here.

File details

Details for the file pgserver-0.0.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pgserver-0.0.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc3bcd5687f5cabe9e83ee1d7914c03a918cdb967f94aa91cc6ec12c44884750
MD5 9f36c8d04cdb3316ac44be0bed28f7c6
BLAKE2b-256 870400895bc3a8bc8df10b27d7c452c7e4e866900cca81a5a84f158572e0fde1

See more details on using hashes here.

File details

Details for the file pgserver-0.0.7-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pgserver-0.0.7-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b3f376f4dc8a749785d90cb46be92d31a1e46024fb2cf6ca2d2d62576a59b1c8
MD5 b1465c4d4cb91576f41cc57569f746a8
BLAKE2b-256 e1df74a6625630562cfeda404c3615c02767824141cfded1c65a612a9edf9ad4

See more details on using hashes here.

File details

Details for the file pgserver-0.0.7-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pgserver-0.0.7-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6d0e4500c5caaaf34af66cf5b3e9e19646fba53033a20c4fafd4e98e59315999
MD5 4e52cefef6d50ffa02e0a63a4d8ff93c
BLAKE2b-256 c528353525f0331c11326c6208eb2d7d02d420e303a7944189c28291fc71117e

See more details on using hashes here.

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