Skip to main content

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

postgres_wire-1.0.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

postgres_wire-1.0.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file postgres_wire-1.0.1.tar.gz.

File metadata

  • Download URL: postgres_wire-1.0.1.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

Hashes for postgres_wire-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b3ee43e40b3731258703872f4297dd88bd5f815e660177824fe411a61e1f592f
MD5 2de52cf6835e96f082837d8f2ca8e1c9
BLAKE2b-256 f6d702eedf15ce74db157a1c2f9788238097ebf6f98f54385ce29636e1691b36

See more details on using hashes here.

File details

Details for the file postgres_wire-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: postgres_wire-1.0.1-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

Hashes for postgres_wire-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1178f75c4a4033241db1786554ff4aface67cfd8e86e35bb14e0f7febae5422e
MD5 d1c18bf67a397122e04d77da67115496
BLAKE2b-256 eec0393f57ca149b5dc20658ea4c6699f8da52ad60ad1d9a88cf514d4fbf311d

See more details on using hashes here.

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