Skip to main content

🐘 pygwire 🐍

A low-level PostgreSQL wire protocol codec for Python

CI Python 3.11+ License: MIT PyPI

[!NOTE] Beta. Pygwire is under active development. The API may change between minor releases until 1.0. See the changelog for migration notes.


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 with connection phase tracking.
  • 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 BackendMessageDecoder
from pygwire.messages import Query, ParameterStatus

# Encode a client message to wire bytes
query = Query(query_string="SELECT * FROM users")
wire_bytes = query.to_wire()  # b'Q\x00\x00\x00\x18SELECT * FROM users\x00'

# Decode server messages from raw bytes
decoder = BackendMessageDecoder()
decoder.feed(ParameterStatus(name="server_version", value="16.1").to_wire())

for msg in decoder:
    print(msg)  # ParameterStatus(name='server_version', value='16.1')

🏗️ 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 Connection phase tracking for framing, disambiguation, and lifecycle
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.

Metadata

Release files for pygwire 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pygwire 0.2.0
File Size Uploaded Provenance Actions
pygwire-0.2.0.tar.gz 29.2 kB Without provenance Details for pygwire-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pygwire 0.2.0
File Interpreter ABI Platform Actions
pygwire-0.2.0-py3-none-any.whl Python 3 none any Details for pygwire-0.2.0-py3-none-any.whl

Total release size: 65.4 kB

Release files / pygwire-0.2.0.tar.gz

Download URL pygwire-0.2.0.tar.gz
Size 29.2 kB
Tags Source
SHA-256 checksum
How to use checksums
cf7acf697d7d161b4732805d6b48e3242097ca17708a607de25d889ba2feb245
BLAKE2b-256 checksum
How to use checksums
15b1858d26b05f3b789b0fd604e6ad8b321b26455768a389405ba48f3ba2c0de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","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}

Release files / pygwire-0.2.0-py3-none-any.whl

Download URL pygwire-0.2.0-py3-none-any.whl
Size 36.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d6a662930e9fa10ea9af47f4ec30a675fed6f16bd6b7e947f498aadd575bf5a0
BLAKE2b-256 checksum
How to use checksums
32fade8f41b0744660d92ede8e413a8c855472137c5e9c3e1a5e783ca7d19aef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","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}

Security for pygwire 0.2.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page