Skip to main content

Python API for pg0 - embedded PostgreSQL

Project description

pg0 - Embedded PostgreSQL for Python

Zero-config PostgreSQL with pgvector support. Just pip install and go.

Installation

pip install pg0-embedded

Quick Start

from pg0 import Pg0

# Start PostgreSQL (auto-installs on first run)
pg = Pg0()
pg.start()

print(pg.uri)  # postgresql://postgres:postgres@localhost:5432/postgres

pg.stop()

Context Manager

from pg0 import Pg0

with Pg0() as pg:
    print(pg.uri)
    pg.execute("CREATE EXTENSION IF NOT EXISTS vector")
    pg.execute("SELECT version()")
# Automatically stopped

Custom Configuration

from pg0 import Pg0

pg = Pg0(
    port=5433,
    username="myuser",
    password="mypass",
    database="mydb",
    config={
        "shared_buffers": "512MB",
        "maintenance_work_mem": "1GB",
    }
)

with pg:
    print(pg.uri)

Multiple Instances

from pg0 import Pg0, list_instances

# Run multiple PostgreSQL instances
app = Pg0(name="app", port=5432)
test = Pg0(name="test", port=5433)

app.start()
test.start()

for instance in list_instances():
    print(f"{instance.name}: {instance.uri}")

app.stop()
test.stop()

API Reference

Pg0 Class

pg = Pg0(
    name="default",      # Instance name
    port=5432,           # Port
    username="postgres", # Username
    password="postgres", # Password
    database="postgres", # Database
    data_dir=None,       # Custom data directory
    config={},           # PostgreSQL config options
)

pg.start()        # Start PostgreSQL -> InstanceInfo
pg.stop()         # Stop PostgreSQL
pg.info()         # Get instance info -> InstanceInfo
pg.uri            # Connection URI (property)
pg.running        # Is running (property)
pg.execute(sql)   # Execute SQL -> str
pg.psql(*args)    # Run psql command

Module Functions

import pg0

pg0.start(port=5432, ...)   # Start instance -> InstanceInfo
pg0.stop(name="default")    # Stop instance
pg0.info(name="default")    # Get info -> InstanceInfo
pg0.list_instances()        # List all -> [InstanceInfo]
pg0.install(version=None)   # Install pg0 binary

InstanceInfo

info.name       # Instance name
info.running    # Is running
info.pid        # Process ID
info.port       # Port
info.uri        # Connection URI
info.username   # Username
info.database   # Database
info.data_dir   # Data directory

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pg0_embedded-0.1.1.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

pg0_embedded-0.1.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file pg0_embedded-0.1.1.tar.gz.

File metadata

  • Download URL: pg0_embedded-0.1.1.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pg0_embedded-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fb39f5a7e45257e95379cc5fcff226d7c7f17a081806d9eead00fe903ccca789
MD5 9ec76ff3a0923ea30d54d9224e059fab
BLAKE2b-256 b14ccae8662ba15f6607e030c57d1195347159721e503991e3c55d7f1a8beab6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pg0_embedded-0.1.1.tar.gz:

Publisher: release-python.yml on vectorize-io/pg0

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

File details

Details for the file pg0_embedded-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pg0_embedded-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pg0_embedded-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 643500836abf4d09a4f20db31d3c80ad16dc273ade439dafc86f1735a384d9ba
MD5 27bb714baee1c008bd6f314012e3294b
BLAKE2b-256 6d286e8de2e0d55b09d17bc4547e3d57d5d5856c35785001dbe81cd372f062e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pg0_embedded-0.1.1-py3-none-any.whl:

Publisher: release-python.yml on vectorize-io/pg0

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