Skip to main content

Low-level PostgreSQL wire protocol (3.0 & 3.2) codec for Python

Project description

🐘 pygwire 🐍

A low-level PostgreSQL wire protocol codec for Python

CI Python 3.11+ License: MIT

[!WARNING] Early stage project. Pygwire is under active development. The API is not yet stable and breaking changes should be expected between releases.


Pygwire is a sans-I/O PostgreSQL wire protocol (v3.0 and v3.2) codec. All codec and state machine logic is I/O-independent, making it portable across asyncio, trio, synchronous sockets, or any other transport.

✨ Features

  • Sans-I/O design. No I/O dependencies. Bring your own transport.
  • Zero-copy parsing. Uses memoryview for buffer slicing.
  • Complete protocol coverage. All PostgreSQL v3.0 and v3.2 wire protocol messages.
  • Protocol state machines. Validate message sequences for both client and server roles.
  • Zero dependencies. No runtime dependencies.
  • Fully typed. Ships with py.typed marker for PEP 561 support.

📦 Installation

pip install pygwire

Or with uv:

uv add pygwire

🚀 Quick Start

📖 Read the full documentation →

from pygwire import FrontendConnection
from pygwire.messages import StartupMessage, Query

conn = FrontendConnection()
sock.send(conn.send(StartupMessage(params={"user": "postgres", "database": "mydb"})))

# Authentication, queries, and more - see the docs!

🏗️ Architecture

Pygwire is organized into four layers, from low-level to high-level:

Layer Module Purpose
Messages pygwire.messages Encode and decode all PostgreSQL protocol messages
Codec pygwire.codec Incremental stream decoder with zero-copy framing
State Machine pygwire.state_machine Protocol phase tracking and message validation
Connection pygwire.connection Coordinated decoder + state machine (sans-I/O)

Use the lower layers independently for maximum control, or use Connection for a higher-level API that coordinates them together.

[!NOTE] Pygwire follows PostgreSQL's naming convention: backend = server, frontend = client.

📋 Requirements

  • Python 3.11+
  • No runtime dependencies

📚 Documentation

📖 Full documentation, tutorials, and API reference →

Additional Resources

🤝 Contributing

See CONTRIBUTING.md for development setup and guidelines.

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

pygwire-0.0.2.tar.gz (28.9 kB view details)

Uploaded Source

Built Distribution

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

pygwire-0.0.2-py3-none-any.whl (35.9 kB view details)

Uploaded Python 3

File details

Details for the file pygwire-0.0.2.tar.gz.

File metadata

  • Download URL: pygwire-0.0.2.tar.gz
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pygwire-0.0.2.tar.gz
Algorithm Hash digest
SHA256 43df9afeb822f11e88e17926c89307dd62d4549ef2b2c899819439b16dcbb350
MD5 c795be10054494103fa105c4b22507b2
BLAKE2b-256 e123055cfb72bc759f30e83a04ed5cb4c94c2caae492d7fede4d38f5b5ee263d

See more details on using hashes here.

File details

Details for the file pygwire-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pygwire-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 35.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pygwire-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3776a881aa0b566f0c177d192debe0295d68a845af11515e26f8d3dd7c995f92
MD5 1426ca19d4d7bdd42075603dc926c059
BLAKE2b-256 cd3510b198a23abd33af6a2e3ecd3526837fdd894b88aee759a25d08612c53be

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