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
orsudo
. - Simpler initialization:
pgserver.get_server(MY_DATA_DIR)
method to initialize data and server if needed, so you don't need to understandinitdb
,pg_ctl
, port conflicts, and skip debugging why you still cannot connect to the server, just doserver.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:
- Wheels for multiple platforms (ubuntu x86, +MacOS x86, +MacOS apple silicon), pull requests taken for ubuntu arm.
- pgvector extension included
- postgres Server management: cleanup via shared count when multiple processes use the same server.
- no postGIS (need to build cross platform, pull requests taken)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file pgserver-0.0.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pgserver-0.0.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 15.0 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20de83673a5ff1cb6309f86a1f1c4b21d19ef8179b64eea713c56a1d0001aea1 |
|
MD5 | da34fd7f51f01bac218b845c6bf97f16 |
|
BLAKE2b-256 | bac0fe5a6133b3699fc029db777d6eaaecdecf53574df6644c158f81abcb4098 |
File details
Details for the file pgserver-0.0.6-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: pgserver-0.0.6-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 13.1 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b930f9e01ada7fdf22f1dc1f17ced34819af328ff99644800afe5e43e230640c |
|
MD5 | 9b07649400770bc9d0edadf3fec9a384 |
|
BLAKE2b-256 | 0609ee847b398679561da4b1d387e4c981e674557899eb2fe51bebf54707c174 |
File details
Details for the file pgserver-0.0.6-cp311-cp311-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pgserver-0.0.6-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 14.0 MB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbfe013d6cc6c9b0ff4008f923d396cda7b61a1406a89229edfc6fb94f7ed2a9 |
|
MD5 | 2906391a7608312820afc62e1d71311d |
|
BLAKE2b-256 | 0d8e2f880bae6dd3f0b8eb77f8e271d5514b00a309ffad2d12290e8639f30ba8 |
File details
Details for the file pgserver-0.0.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pgserver-0.0.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 15.0 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf6bd3f2fb07e877a83a298f25ab55efb759482c0997c4bf7a34c53d373cb849 |
|
MD5 | 9c41581fedd7e69a841eeb13c6f38a3e |
|
BLAKE2b-256 | 4045ce7ce9f97a1fb561d2caf2ff85466973a4800df49cd0015eb0bda375fb7f |
File details
Details for the file pgserver-0.0.6-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: pgserver-0.0.6-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 13.1 MB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93d9cf5c9218684063d4348566943f9108dbd4430b1006d27cd5349c8f59db87 |
|
MD5 | 1aca99deffab95b3ce82822aba62c966 |
|
BLAKE2b-256 | af8e25727bb7fa09accec156bde4ed651841b05eb26cc7a4c7b47b815d863f1e |
File details
Details for the file pgserver-0.0.6-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pgserver-0.0.6-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 14.0 MB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 430270719fccf3873d476a88795e517ce0c9069b92946c97c60abc567796d20a |
|
MD5 | 472d5732b15728f5ad24f2770caaae2a |
|
BLAKE2b-256 | 6bc45561cf27c31b4ea01a3c1c4b754fd5dbee846c2e4a8b8eee38eee3f39243 |
File details
Details for the file pgserver-0.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pgserver-0.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 15.0 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad27a1abe360f41518fcd4b94453fce2dd4a97c587594045d9fb6228bc5694c7 |
|
MD5 | 4d8b33e700c68fbea9ba29f1c857f286 |
|
BLAKE2b-256 | 7e56b40d5df06cd4a65a3d87f505ffdaa0d5ecf6d0160222754483a44b326f8f |
File details
Details for the file pgserver-0.0.6-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: pgserver-0.0.6-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 13.1 MB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0214411395809a70fcbb6894cc19570c2011de67030122563908b20890e432a4 |
|
MD5 | e814858f15704c78fa94b96f99e8c0a2 |
|
BLAKE2b-256 | ca4bf6dbfa26b8af12d3c9b55ecbff97da1b1a43cfea8d262dd4e4b796b22fa7 |
File details
Details for the file pgserver-0.0.6-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pgserver-0.0.6-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 14.0 MB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b60cc7345fcf89ecf8cf63a2b5bd2fc36654a127fca065ee651ecd8d9905a09 |
|
MD5 | 5d47f6516f6ab181cf18884c9ff2bd9c |
|
BLAKE2b-256 | ba1ce26baea00c2f8014d97e3e6211051c56427f2a22dc9062123eba428997e9 |