Zero-config embedded PostgreSQL with pgvector for Python
Project description
pgbox
Zero-config embedded PostgreSQL with pgvector for Python.
from pgbox import get_server
server = get_server("~/.myapp/data")
uri = server.get_uri() # postgresql:///postgres?host=...&port=5501
server.enable_extension("vector")
server.execute("CREATE TABLE items (id serial, embedding vector(384))")
No Docker. No install steps. No configuration. Just pip install pgbox and you have a running PostgreSQL 17.4 with pgvector 0.8.0.
Install
pip install pgbox
Pre-compiled PostgreSQL binaries are included in the wheel — nothing to download at runtime.
Platforms: macOS (Apple Silicon + Intel), Linux (x86_64)
Python: 3.11+
Usage
Basic
from pgbox import get_server
# Start PostgreSQL (or connect to existing instance at this path)
server = get_server("/path/to/pgdata")
# Get connection URI for any PostgreSQL client
uri = server.get_uri()
# Use with asyncpg
import asyncpg
conn = await asyncpg.connect(uri)
# Use with psycopg2
import psycopg2
conn = psycopg2.connect(uri)
# Use with SQLAlchemy
from sqlalchemy import create_engine
engine = create_engine(uri)
Enable extensions
server.enable_extension("vector") # pgvector for embeddings
server.enable_extension("pg_trgm") # trigram similarity
Execute SQL
server.execute("CREATE TABLE users (id serial PRIMARY KEY, name text)")
server.execute("INSERT INTO users (name) VALUES ('Alice')")
result = server.execute("SELECT * FROM users")
Create databases
server.create_database("myapp")
uri = server.get_uri(database="myapp")
Context manager (auto-cleanup)
# Server stops when the block exits
with get_server("/tmp/test_data") as server:
uri = server.get_uri()
# ... use it ...
# Server stops + data directory deleted
with get_server("/tmp/test_data", cleanup_mode="delete") as server:
uri = server.get_uri()
# ... use it, everything cleaned up on exit ...
Health check
server.is_healthy() # True if accepting connections
server.pid # Postmaster process ID
server.port # TCP port
Cleanup modes
| Mode | Behavior |
|---|---|
"stop" (default) |
Stop PostgreSQL on exit |
"delete" |
Stop + delete the data directory |
"nothing" |
Leave running (for daemon/service use) |
How it works
pgbox bundles pre-compiled PostgreSQL 17.4 and pgvector 0.8.0 binaries directly in the Python wheel. When you call get_server():
- Initialize — runs
initdbif the data directory doesn't exist - Start — runs
pg_ctl starton an available port - Wait — polls
pg_isreadyuntil the server accepts connections - Return — gives you a
PostgresServerwith connection URI
The server is a singleton per data directory — calling get_server() twice with the same path returns the same instance. Cross-process safety is handled via file locks.
Versions
| Component | Version |
|---|---|
| PostgreSQL | 17.4 |
| pgvector | 0.8.0 |
License
Apache-2.0
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pgbox-0.1.3-cp312-cp312-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pgbox-0.1.3-cp312-cp312-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 12.2 MB
- Tags: CPython 3.12, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04c98df4b96c146bdfea9d9bfcef8ae5b4f0fcf627b45a5419421005ca69bfee
|
|
| MD5 |
20b1f17481201cb5bec17476a665b625
|
|
| BLAKE2b-256 |
1ebed228534c9e800ddc2a3d74d666d3b3cf826b89631ffed10577a73a16ea20
|
Provenance
The following attestation bundles were made for pgbox-0.1.3-cp312-cp312-manylinux_2_28_x86_64.whl:
Publisher:
build.yml on unforget-ai/pgbox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pgbox-0.1.3-cp312-cp312-manylinux_2_28_x86_64.whl -
Subject digest:
04c98df4b96c146bdfea9d9bfcef8ae5b4f0fcf627b45a5419421005ca69bfee - Sigstore transparency entry: 1194668322
- Sigstore integration time:
-
Permalink:
unforget-ai/pgbox@7ea50a528faeda0963863268fd0d1541f55cb64f -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/unforget-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@7ea50a528faeda0963863268fd0d1541f55cb64f -
Trigger Event:
push
-
Statement type:
File details
Details for the file pgbox-0.1.3-cp312-cp312-macosx_15_0_universal2.whl.
File metadata
- Download URL: pgbox-0.1.3-cp312-cp312-macosx_15_0_universal2.whl
- Upload date:
- Size: 10.3 MB
- Tags: CPython 3.12, macOS 15.0+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb9c0b61be8ee11452c42270ed8e94659b901f87b628bd2bb9c5406b507f795c
|
|
| MD5 |
92fe529ca745327499db16eec26a307f
|
|
| BLAKE2b-256 |
2e1037c840763cbfb54a67c333316e331c535f80297ac20bee3469247605e228
|
Provenance
The following attestation bundles were made for pgbox-0.1.3-cp312-cp312-macosx_15_0_universal2.whl:
Publisher:
build.yml on unforget-ai/pgbox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pgbox-0.1.3-cp312-cp312-macosx_15_0_universal2.whl -
Subject digest:
cb9c0b61be8ee11452c42270ed8e94659b901f87b628bd2bb9c5406b507f795c - Sigstore transparency entry: 1194668330
- Sigstore integration time:
-
Permalink:
unforget-ai/pgbox@7ea50a528faeda0963863268fd0d1541f55cb64f -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/unforget-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@7ea50a528faeda0963863268fd0d1541f55cb64f -
Trigger Event:
push
-
Statement type:
File details
Details for the file pgbox-0.1.3-cp312-cp312-macosx_14_0_universal2.whl.
File metadata
- Download URL: pgbox-0.1.3-cp312-cp312-macosx_14_0_universal2.whl
- Upload date:
- Size: 10.3 MB
- Tags: CPython 3.12, macOS 14.0+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3830c85fc8b53bc5e82cf456ad62d4520a17efc6901e6239bd27baa2a7846c1f
|
|
| MD5 |
50879e79e9a12337fa7de2b6d9f989f7
|
|
| BLAKE2b-256 |
d93001ff48bf6b2716bf07da017bb4fa6c6dd4594526c8e92c9a0a05e85a47f2
|
Provenance
The following attestation bundles were made for pgbox-0.1.3-cp312-cp312-macosx_14_0_universal2.whl:
Publisher:
build.yml on unforget-ai/pgbox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pgbox-0.1.3-cp312-cp312-macosx_14_0_universal2.whl -
Subject digest:
3830c85fc8b53bc5e82cf456ad62d4520a17efc6901e6239bd27baa2a7846c1f - Sigstore transparency entry: 1194668345
- Sigstore integration time:
-
Permalink:
unforget-ai/pgbox@7ea50a528faeda0963863268fd0d1541f55cb64f -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/unforget-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@7ea50a528faeda0963863268fd0d1541f55cb64f -
Trigger Event:
push
-
Statement type: