pg0-embedded 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pg0_embedded-0.2.0 → pg0_embedded-0.3.0}/PKG-INFO +20 -1
- {pg0_embedded-0.2.0 → pg0_embedded-0.3.0}/README.md +19 -0
- {pg0_embedded-0.2.0 → pg0_embedded-0.3.0}/pg0/__init__.py +34 -104
- {pg0_embedded-0.2.0 → pg0_embedded-0.3.0}/pyproject.toml +1 -1
- {pg0_embedded-0.2.0 → pg0_embedded-0.3.0}/uv.lock +1 -1
- {pg0_embedded-0.2.0 → pg0_embedded-0.3.0}/.gitignore +0 -0
- {pg0_embedded-0.2.0 → pg0_embedded-0.3.0}/pg0/py.typed +0 -0
- {pg0_embedded-0.2.0 → pg0_embedded-0.3.0}/tests/__init__.py +0 -0
- {pg0_embedded-0.2.0 → pg0_embedded-0.3.0}/tests/test_pg0.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pg0-embedded
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Python API for pg0 - embedded PostgreSQL
|
|
5
5
|
Project-URL: Homepage, https://github.com/vectorize-io/pg0
|
|
6
6
|
Project-URL: Repository, https://github.com/vectorize-io/pg0
|
|
@@ -82,6 +82,25 @@ pg0.info(name="default") # Get instance info
|
|
|
82
82
|
pg0.list_instances() # List all instances
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
+
### Getting Connection URI
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from pg0 import Pg0
|
|
89
|
+
|
|
90
|
+
pg = Pg0()
|
|
91
|
+
pg.start()
|
|
92
|
+
|
|
93
|
+
# Using the uri property
|
|
94
|
+
print(pg.uri) # postgresql://postgres:postgres@localhost:5432/postgres
|
|
95
|
+
|
|
96
|
+
# Or using info()
|
|
97
|
+
info = pg.info()
|
|
98
|
+
print(info.uri) # postgresql://postgres:postgres@localhost:5432/postgres
|
|
99
|
+
print(info.port) # 5432
|
|
100
|
+
print(info.username) # postgres
|
|
101
|
+
print(info.database) # postgres
|
|
102
|
+
```
|
|
103
|
+
|
|
85
104
|
## Links
|
|
86
105
|
|
|
87
106
|
- [GitHub](https://github.com/vectorize-io/pg0)
|
|
@@ -60,6 +60,25 @@ pg0.info(name="default") # Get instance info
|
|
|
60
60
|
pg0.list_instances() # List all instances
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
+
### Getting Connection URI
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from pg0 import Pg0
|
|
67
|
+
|
|
68
|
+
pg = Pg0()
|
|
69
|
+
pg.start()
|
|
70
|
+
|
|
71
|
+
# Using the uri property
|
|
72
|
+
print(pg.uri) # postgresql://postgres:postgres@localhost:5432/postgres
|
|
73
|
+
|
|
74
|
+
# Or using info()
|
|
75
|
+
info = pg.info()
|
|
76
|
+
print(info.uri) # postgresql://postgres:postgres@localhost:5432/postgres
|
|
77
|
+
print(info.port) # 5432
|
|
78
|
+
print(info.username) # postgres
|
|
79
|
+
print(info.database) # postgres
|
|
80
|
+
```
|
|
81
|
+
|
|
63
82
|
## Links
|
|
64
83
|
|
|
65
84
|
- [GitHub](https://github.com/vectorize-io/pg0)
|
|
@@ -19,13 +19,9 @@ from __future__ import annotations
|
|
|
19
19
|
|
|
20
20
|
import json
|
|
21
21
|
import os
|
|
22
|
-
import platform
|
|
23
22
|
import shutil
|
|
24
|
-
import stat
|
|
25
23
|
import subprocess
|
|
26
24
|
import sys
|
|
27
|
-
import tempfile
|
|
28
|
-
import urllib.request
|
|
29
25
|
from dataclasses import dataclass
|
|
30
26
|
from pathlib import Path
|
|
31
27
|
from typing import Optional
|
|
@@ -35,6 +31,7 @@ __version__ = "0.1.0"
|
|
|
35
31
|
|
|
36
32
|
# GitHub repo for pg0 releases
|
|
37
33
|
PG0_REPO = "vectorize-io/pg0"
|
|
34
|
+
INSTALL_SCRIPT_URL = f"https://raw.githubusercontent.com/{PG0_REPO}/main/install.sh"
|
|
38
35
|
|
|
39
36
|
|
|
40
37
|
class Pg0Error(Exception):
|
|
@@ -95,74 +92,11 @@ def _get_install_dir() -> Path:
|
|
|
95
92
|
return Path.home() / ".local" / "bin"
|
|
96
93
|
|
|
97
94
|
|
|
98
|
-
def
|
|
99
|
-
"""Get the platform string for downloading the correct binary."""
|
|
100
|
-
system = platform.system().lower()
|
|
101
|
-
machine = platform.machine().lower()
|
|
102
|
-
|
|
103
|
-
if system == "darwin":
|
|
104
|
-
# macOS - only Apple Silicon supported, Intel uses Rosetta
|
|
105
|
-
return "darwin-aarch64"
|
|
106
|
-
elif system == "linux":
|
|
107
|
-
# Detect architecture
|
|
108
|
-
if machine in ("x86_64", "amd64"):
|
|
109
|
-
arch_str = "x86_64"
|
|
110
|
-
elif machine in ("aarch64", "arm64"):
|
|
111
|
-
arch_str = "aarch64"
|
|
112
|
-
else:
|
|
113
|
-
raise Pg0NotFoundError(f"Unsupported Linux architecture: {machine}")
|
|
114
|
-
|
|
115
|
-
# Detect libc (musl vs glibc)
|
|
116
|
-
# Check for musl by looking for the musl loader
|
|
117
|
-
import subprocess
|
|
118
|
-
try:
|
|
119
|
-
result = subprocess.run(
|
|
120
|
-
["ldd", "--version"],
|
|
121
|
-
capture_output=True,
|
|
122
|
-
text=True,
|
|
123
|
-
timeout=5,
|
|
124
|
-
)
|
|
125
|
-
output = result.stdout + result.stderr
|
|
126
|
-
if "musl" in output.lower():
|
|
127
|
-
return f"linux-{arch_str}-musl"
|
|
128
|
-
except (FileNotFoundError, subprocess.TimeoutExpired):
|
|
129
|
-
pass
|
|
130
|
-
|
|
131
|
-
# Check for musl loader file
|
|
132
|
-
musl_loaders = [
|
|
133
|
-
f"/lib/ld-musl-{arch_str}.so.1",
|
|
134
|
-
"/lib/ld-musl-x86_64.so.1",
|
|
135
|
-
"/lib/ld-musl-aarch64.so.1",
|
|
136
|
-
]
|
|
137
|
-
for loader in musl_loaders:
|
|
138
|
-
if Path(loader).exists():
|
|
139
|
-
return f"linux-{arch_str}-musl"
|
|
140
|
-
|
|
141
|
-
# Default to glibc
|
|
142
|
-
return f"linux-{arch_str}-gnu"
|
|
143
|
-
elif system == "windows":
|
|
144
|
-
return "windows-x86_64"
|
|
145
|
-
else:
|
|
146
|
-
raise Pg0NotFoundError(f"Unsupported platform: {system}")
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
def _get_latest_version() -> str:
|
|
150
|
-
"""Get the latest pg0 version from GitHub."""
|
|
151
|
-
url = f"https://api.github.com/repos/{PG0_REPO}/releases/latest"
|
|
152
|
-
try:
|
|
153
|
-
with urllib.request.urlopen(url, timeout=30) as response:
|
|
154
|
-
data = json.loads(response.read().decode())
|
|
155
|
-
return data["tag_name"]
|
|
156
|
-
except Exception as e:
|
|
157
|
-
raise Pg0NotFoundError(f"Failed to fetch latest version: {e}")
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
def install(version: Optional[str] = None, force: bool = False) -> Path:
|
|
95
|
+
def install(force: bool = False) -> Path:
|
|
161
96
|
"""
|
|
162
|
-
Install the pg0 binary.
|
|
97
|
+
Install the pg0 binary using the official install script.
|
|
163
98
|
|
|
164
99
|
Args:
|
|
165
|
-
version: Version to install (default: latest)
|
|
166
100
|
force: Force reinstall even if already installed
|
|
167
101
|
|
|
168
102
|
Returns:
|
|
@@ -176,46 +110,42 @@ def install(version: Optional[str] = None, force: bool = False) -> Path:
|
|
|
176
110
|
if binary_path.exists() and not force:
|
|
177
111
|
return binary_path
|
|
178
112
|
|
|
179
|
-
#
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
url = f"https://github.com/{PG0_REPO}/releases/download/{version}/{filename}"
|
|
190
|
-
|
|
191
|
-
print(f"Installing pg0 {version}...")
|
|
192
|
-
|
|
193
|
-
# Create install directory
|
|
194
|
-
install_dir.mkdir(parents=True, exist_ok=True)
|
|
113
|
+
# Use the official install script which handles:
|
|
114
|
+
# - Platform detection (including old glibc fallback to musl)
|
|
115
|
+
# - Intel Mac Rosetta handling
|
|
116
|
+
# - Proper binary naming
|
|
117
|
+
if sys.platform == "win32":
|
|
118
|
+
# Windows: download directly since bash isn't available
|
|
119
|
+
raise Pg0NotFoundError(
|
|
120
|
+
"Auto-install not supported on Windows. "
|
|
121
|
+
"Please download pg0 manually from https://github.com/vectorize-io/pg0/releases"
|
|
122
|
+
)
|
|
195
123
|
|
|
196
|
-
|
|
124
|
+
print("Installing pg0 using official install script...")
|
|
197
125
|
try:
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
126
|
+
result = subprocess.run(
|
|
127
|
+
["bash", "-c", f"curl -fsSL {INSTALL_SCRIPT_URL} | bash"],
|
|
128
|
+
capture_output=True,
|
|
129
|
+
text=True,
|
|
130
|
+
timeout=120,
|
|
131
|
+
)
|
|
132
|
+
if result.returncode != 0:
|
|
133
|
+
raise Pg0NotFoundError(f"Install script failed: {result.stderr}")
|
|
206
134
|
|
|
207
|
-
#
|
|
208
|
-
if
|
|
209
|
-
binary_path
|
|
135
|
+
# Verify installation
|
|
136
|
+
if binary_path.exists():
|
|
137
|
+
return binary_path
|
|
210
138
|
|
|
211
|
-
|
|
212
|
-
|
|
139
|
+
# Check if installed to a different location
|
|
140
|
+
path = shutil.which("pg0")
|
|
141
|
+
if path:
|
|
142
|
+
return Path(path)
|
|
213
143
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
raise Pg0NotFoundError(
|
|
144
|
+
raise Pg0NotFoundError("Install script succeeded but pg0 binary not found")
|
|
145
|
+
except subprocess.TimeoutExpired:
|
|
146
|
+
raise Pg0NotFoundError("Install script timed out")
|
|
147
|
+
except FileNotFoundError:
|
|
148
|
+
raise Pg0NotFoundError("bash not found - please install pg0 manually")
|
|
219
149
|
|
|
220
150
|
|
|
221
151
|
def _find_pg0() -> str:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|