Low-level PostgreSQL wire protocol (3.0 & 3.2) codec for Python
Project description
[!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
memoryviewfor 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.typedmarker 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 |
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.
Project details
Release history Release notifications | RSS feed
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 pygwire-0.1.0.tar.gz.
File metadata
- Download URL: pygwire-0.1.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89ec22ac5f542fa4016b44a7b0bc81ae599bb86e1c30f03ea7fe5f23e0bae7a5
|
|
| MD5 |
992f7323d770cbfb4c38c5ea1fba5257
|
|
| BLAKE2b-256 |
d3610aa21c19c59be0bb6b6e2fde3bafecc3f49e615054d051d2da5e15fd1cd5
|
File details
Details for the file pygwire-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pygwire-0.1.0-py3-none-any.whl
- Upload date:
- Size: 36.0 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
265c4d6f8b84d8729a29a638a568d334885461486e223bda4b097e33847a5cd5
|
|
| MD5 |
1d6d32bff91a3c57d81353781b6def2c
|
|
| BLAKE2b-256 |
09499d7d2f87ab76e08f86cec59ec316fff682075411eb8571949d03d041166a
|