Add your description here
Project description
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.
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
Built Distribution
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 postgres_wire-1.0.2.tar.gz.
File metadata
- Download URL: postgres_wire-1.0.2.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf1e0b050e711977683c045e9bd5949a2b75d11ea535a3ec5198db36979258fd
|
|
| MD5 |
13f4cf5455efd0cee3ce5bd281da9952
|
|
| BLAKE2b-256 |
13095a14383b4bdf2f47aa1286f79ec9179bf192dff778ebcab3aae9f81032f5
|
File details
Details for the file postgres_wire-1.0.2-py3-none-any.whl.
File metadata
- Download URL: postgres_wire-1.0.2-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
993b6525a9b253e65c7699f649356ddf5e3b3eefc3d3591717321755e0608b47
|
|
| MD5 |
1d6e9d8fa227989f13efc33e4637ea84
|
|
| BLAKE2b-256 |
6a890986688b2779bbda6b89247c8c5e5daf020b6f2183a3c87863b160a12bc8
|