pynntp
A Python NNTP client library, built for working with large Usenet servers.
- Streaming responses. Commands that can return a lot of data (XOVER, HDR, LIST, ...) return iterators, so gigabytes of overview data can be processed as it arrives, with little memory.
- Compressed headers. Supports
XFEATURE COMPRESS GZIPand the yEnc/zlib compressed XZVER and XZHDR commands, decompressed transparently. - yEnc. Article bodies are yEnc-decoded and checked against their size and CRC.
- TLS and authentication. Implicit TLS or STARTTLS, and AUTHINFO login sent when the server asks for it.
- No dependencies outside the standard library.
Documentation, including the API reference: https://greenbender.github.io/pynntp/
Installation
pip install pynntp
or uv add pynntp. Requires Python 3.11 or newer. The package is imported
as nntp.
Quickstart
Connecting
import nntp
with nntp.NNTPClient(
"news.example.com", username="user", password="secret", use_ssl=True
) as client:
print(client.date())
The username and password are only sent if the server asks for them (call
client.login() to log in straight away), and in clear text unless TLS is
used. With use_ssl=True the port defaults to 563;
for STARTTLS on port 119 instead, also pass ssl_mode=nntp.SSLMode.STARTTLS.
TLS certificates are verified;
pass ssl_context= (an ssl.SSLContext) to trust a private CA or change other
TLS settings. Leaving the with block sends QUIT.
Or connect from a URL, such as one held in an environment variable. The schemes
are nntp://, nntps:// (or snews://) and nntp+starttls://:
client = nntp.NNTPClient.from_url("nntps://user@news.example.com", password=secret)
The username and password come from the URL's user info, and the query can set
timeout (seconds, or none) and reader (true/false), for example
?timeout=10&reader=false. Keyword arguments override the URL. Passing the
password as an argument keeps it out of the URL, which tends to end up in logs.
Browsing a group
total, first, last, name = client.group("alt.binaries.test")
for number, overview in client.xover((last - 999, last)):
print(number, overview["subject"], overview["bytes"])
Header and overview names are case-insensitive: overview["Subject"] and
overview["subject"] are the same.
To compress the whole connection on servers that support RFC 8054, call
client.compress() after connecting and logging in: servers that only ask for
a login later can't get one once compression is on, so call client.login()
first. Some servers instead
offer compressed overview data: call client.xfeature_compress_gzip() once,
or use client.xzver() instead of xover().
Downloading an article
headers = client.head("<part1of10.abc@example.com>")
data = client.body("<part1of10.abc@example.com>") # yEnc is decoded
A body whose yEnc data fails its size or CRC check raises NNTPYEncError.
The decoded data is still available, for example for par2 repair:
try:
data = client.body(message_id)
except nntp.NNTPYEncError as e:
data = e.data
Posting
message_id = client.post(
{"From": "me@example.com", "Newsgroups": "alt.test", "Subject": "Hello"},
"Hello, world!\n",
)
post() returns the new article's message-id if the server reports it,
otherwise True.
Errors and reconnecting
All errors derive from nntp.NNTPError:
NNTPReplyError: an unexpected reply, withcodeandmessage.NNTPTemporaryError(4xx) andNNTPPermanentError(5xx) are subclasses.NNTPDataError: a response that can't be parsed, such as a bad overview line, or a line longer thanclient.max_line_length(64 KiB, including CRLF).NNTPYEncErroris a subclass.NNTPSyncError: the connection can't be used, see below.
A streamed response must be read to the end before the next command. If one
is abandoned part way (a break, or next() to take only the first match)
or fails part way, the connection is left out of sync and the next command
raises NNTPSyncError. Use list() to read a response before searching it.
Call reconnect() to recover; it does not restore the selected group.
for number, overview in client.xover((first, last)):
if number > 1000:
break # The rest of the response is never read
client.reconnect()
client.group("alt.binaries.test")
Supported commands
CAPABILITIES, MODE READER, QUIT, DATE, HELP, NEWGROUPS, NEWNEWS, LIST (ACTIVE, ACTIVE.TIMES, NEWSGROUPS, OVERVIEW.FMT, HEADERS, EXTENSIONS), GROUP, LISTGROUP, NEXT, LAST, STAT, ARTICLE, HEAD, BODY, POST, IHAVE, HDR, XHDR, XZHDR, OVER, XOVER, XZVER, XPAT, COMPRESS DEFLATE and XFEATURE COMPRESS GZIP.
Other commands can be sent with client.command(); read a multi-line
response with client.info().
License
GPL-3.0-or-later.
Metadata
Release files for pynntp 3.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pynntp-3.3.0.tar.gz | 43.0 kB | With provenance | Details for pynntp-3.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pynntp-3.3.0-py3-none-any.whl | Python 3 | none | any | Details for pynntp-3.3.0-py3-none-any.whl |
Total release size: 86.3 kB
Release files / pynntp-3.3.0.tar.gz
| Download URL | pynntp-3.3.0.tar.gz |
|---|---|
| Size | 43.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6bfba48da8aa04ee1edf15fdd76b0f259e03a10ea53f46a3e23ea9568904bc3f
|
|
BLAKE2b-256 checksum How to use checksums |
4356a6fd213e266aa761d437c9f4161c8df435cc08bb5408c0f35c3687ebe327
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logRelease files / pynntp-3.3.0-py3-none-any.whl
| Download URL | pynntp-3.3.0-py3-none-any.whl |
|---|---|
| Size | 43.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c8aba2cac14c81040c664b69083433aa9c01ca4b56a0b65cff5d59cc7f3a736c
|
|
BLAKE2b-256 checksum How to use checksums |
4348040d97df6d16e9d3edec1779bba073eaf16ae9c03ed58422bbc2a6c7befa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logSecurity for pynntp 3.3.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pynntp-3.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logA 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.