postgres-wire
This module provides a postgres wire compatible server for Python that leverages Pydantic models for brevity.
$ # The example below is being run in a separate terminal
$ psql postgresql://user:password@localhost:5432/db
psql (14.19 (Homebrew), server 0.0.0)
Type "help" for help.
db=> SELECT t;
foo | bar
--------+-----
'wow' | 12
'woah' | 21
(2 rows)
db=>
Installing
You should be able to use your preferred package manager to fetch the latest version from PyPi.
$ uv add postgres-wire
$ # or pip install postgres-wire
Usage
from postgres_wire import create_server, Handler
from pydantic import BaseModel
class YourObject(BaseModel):
foo: str
bar: int
class YourHandler(Handler):
# If you'd like to listen on a different port
# port = 55432
def query(self, sql):
print(f"Handling the query <{sql}>")
return [YourObject(foo="wow", bar=12), YourObject(foo="woah", bar=21)]
serve = create_server(YourHandler)
serve() # You can now connect with `psql postgresql://user:pass@localhost:5432`
Usage with auth
If you're interested in adding auth (ie API keys), then implement a check_auth method for the handler object which accepts a username and password as arguments.
from postgres_wire import create_server, Handler
from pydantic import BaseModel
class YourObject(BaseModel):
foo: str
bar: int
class YourHandler(Handler):
# If you'd like to listen on a different port
# port = 55432
def query(self, sql):
print(f"Handling the query <{sql}>")
return [YourObject(foo="wow", bar=12), YourObject(foo="woah", bar=21)]
def check_auth(self, user, password):
if password == "pass":
# Raising an exception will cause the authentication to fail
raise ValueError
serve = create_server(YourHandler)
serve() # You can now connect with `psql postgresql://user:password@localhost:5432`
Background
The initial code is taken from this gist which was an improvement atop this gist.
Metadata
Release files for postgres-wire 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| postgres_wire-1.0.2.tar.gz | 4.4 kB | Without provenance | Details for postgres_wire-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| postgres_wire-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for postgres_wire-1.0.2-py3-none-any.whl |
Total release size: 10.0 kB
Release files / postgres_wire-1.0.2.tar.gz
| Download URL | postgres_wire-1.0.2.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cf1e0b050e711977683c045e9bd5949a2b75d11ea535a3ec5198db36979258fd
|
|
BLAKE2b-256 checksum How to use checksums |
13095a14383b4bdf2f47aa1286f79ec9179bf192dff778ebcab3aae9f81032f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / postgres_wire-1.0.2-py3-none-any.whl
| Download URL | postgres_wire-1.0.2-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
993b6525a9b253e65c7699f649356ddf5e3b3eefc3d3591717321755e0608b47
|
|
BLAKE2b-256 checksum How to use checksums |
6a890986688b2779bbda6b89247c8c5e5daf020b6f2183a3c87863b160a12bc8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for postgres-wire 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.