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.0.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.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: postgres_wire-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 8a5eacd00452cdec4aed8d4d8cefbe6cf74ffe75561d24e3f874e0ea975b70c1
MD5 56e8680035b48bf001f5209d68e64ab8
BLAKE2b-256 1e8a35f6c8d4d859a329e229b28a0cf0b14eccc5ff1eee7523037e69e74ca0ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: postgres_wire-1.0.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b14254064398fbe1fec5d99e46af64551e4267ff0895b3cd7a0345676959603
MD5 63df07ec5ae5958e4619934381f5ede2
BLAKE2b-256 2ada3dfb337e0938456ed09f4df90d1fcf151c87a7609dbe9e02da79b1787f1d

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