Pip-installable, embedded-like postgres server for your python app
Python
103
236 commits
updated Jun 10, 2024
pgserver lets you build Postgres-backed python apps with the same convenience afforded by an embedded database (ie, alternatives such as sqlite).
If you build your app with pgserver, your app remains wholly pip-installable, saving your users from needing to understand how to setup a postgres server (they simply pip install your app, and postgres is brought in through dependencies), and letting you get started developing quickly: just pip install pgserver and pgserver.get_server(...), as shown in this notebook:
To achieve this, you need two things which pgserver provides
Additionally, this package includes the pgvector postgres extension, useful for storing associated vector data and for vector similarity queries.
root privileges or sudo.pgserver handles this case.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.pgserver.get_server(MY_DATA_DIR) on the same dir (wait for last one). You can blow away your PGDATA dir and start again.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
db = pgserver.get_server(MYPGDATA)
# server ready for connection.
print(db.psql('create extension vector'))
db_uri = db.get_uri()
# use uri with sqlalchemy / psycopg, etc, see colab.
# 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()
pg = pgserver.get_server(tmp_pg_data, cleanup_mode='stop')
yield pg
pg.cleanup()
Postgres binaries in the package can be found in the directory pointed
to by the pgserver.POSTGRES_BIN_PATH to be used directly.
This project was originally based on , which provides a linux wheel. But adds the following differences:
pgvector extension but currently excludes postGISPython
87.9%
Makefile
5.8%
Jupyter Notebook
5.7%
Pip-installable, embedded-like postgres server for your python app
Python
103
236 commits
updated Jun 10, 2024
pgserver lets you build Postgres-backed python apps with the same convenience afforded by an embedded database (ie, alternatives such as sqlite).
If you build your app with pgserver, your app remains wholly pip-installable, saving your users from needing to understand how to setup a postgres server (they simply pip install your app, and postgres is brought in through dependencies), and letting you get started developing quickly: just pip install pgserver and pgserver.get_server(...), as shown in this notebook:
To achieve this, you need two things which pgserver provides
Additionally, this package includes the pgvector postgres extension, useful for storing associated vector data and for vector similarity queries.
root privileges or sudo.pgserver handles this case.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.pgserver.get_server(MY_DATA_DIR) on the same dir (wait for last one). You can blow away your PGDATA dir and start again.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
db = pgserver.get_server(MYPGDATA)
# server ready for connection.
print(db.psql('create extension vector'))
db_uri = db.get_uri()
# use uri with sqlalchemy / psycopg, etc, see colab.
# 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()
pg = pgserver.get_server(tmp_pg_data, cleanup_mode='stop')
yield pg
pg.cleanup()
Postgres binaries in the package can be found in the directory pointed
to by the pgserver.POSTGRES_BIN_PATH to be used directly.
This project was originally based on , which provides a linux wheel. But adds the following differences:
pgvector extension but currently excludes postGISPython
87.9%
Makefile
5.8%
Jupyter Notebook
5.7%