Skip to main content

Self-contained postgres server for your python applications

Project description

Python Version Postgres Version

Linux Support macOS Apple Silicon Support >=11 macOS Intel Support => 10.0 Windows Support >= 2022

License PyPI Package PyPI - Downloads

pgembed: pip-installable, embedded postgres server + pgvector extension for your python app

pgembed is a fork of pgserver, a project that 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 pgembed, 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 pgembed and pgembed.get_server(...), as shown in this notebook: Open In Colab

To achieve this, you need two things which pgembed provides

  • python binary wheels for multiple-plaforms with postgres binaries
  • convenience python methods that handle db initialization and server process management, that deals with things that would normally prevent you from running your python app seamlessly on environments like docker containers, a machine you have no root access in, machines with other running postgres servers, google colab, etc. One main goal of the project is robustness around this.

Additionally, this package includes the pgvector postgres extension, useful for storing associated vector data and for vector similarity queries.

Basic summary:

  • Pip installable binaries: built and tested on Manylinux, MacOS and Windows.
  • No sudo or admin rights needed: Does not require root privileges or sudo.
  • but... can handle root: in some environments your python app runs as root, eg docker, google colab, pgembed handles this case.
  • Simpler initialization: pgembed.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.
  • Convenient cleanup: server process cleanup is done for you: when the process using pgembed ends, the server is shutdown, including when multiple independent processes call pgembed.get_server(MY_DATA_DIR) on the same dir (wait for last one). You can blow away your PGDATA dir and start again.
  • 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 pgembed

db = pgembed.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 = pgembed.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 pgembed.POSTGRES_BIN_PATH to be used directly.

This project was originally based on , which provides a linux wheel. But adds the following differences:

  1. binary wheels for multiple platforms (ubuntu x86, MacOS apple silicon, MacOS x86, Windows)
  2. postgres python management: cross-platfurm startup and cleanup including many edge cases, runs on colab etc.
  3. includes pgvector extension but currently excludes postGIS

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

If you're not sure about the file name format, learn more about wheel file names.

pgembed-0.1.5-cp313-cp313-manylinux_2_28_x86_64.whl (12.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

pgembed-0.1.5-cp312-cp312-manylinux_2_28_x86_64.whl (12.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

File details

Details for the file pgembed-0.1.5-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pgembed-0.1.5-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 196541d1757ec9dc6964f7a9c092f75604dca014ee231f97f829289146cd3967
MD5 a9cb35a16e1292445ddec0bca5c452e3
BLAKE2b-256 2c963db42ac555f9081fd1fca8c36f0bfed16b12887d6a8fe45a8ab2994d2767

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgembed-0.1.5-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: build-and-test.yml on Ladybug-Memory/pgembed

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pgembed-0.1.5-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pgembed-0.1.5-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 11d07f96d4d49d83395334a25051f6daa8503e44f31716e31c070d859a6d7f5a
MD5 dbe423b63ceb6ba26ba248b566dba2df
BLAKE2b-256 3f9f6b2ded3c96effb41e95525549a90f4016e4e3f721571d277bed8330c9052

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgembed-0.1.5-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: build-and-test.yml on Ladybug-Memory/pgembed

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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