Skip to main content

pre-commit.ci status

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 GZIP and 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, with code and message. NNTPTemporaryError (4xx) and NNTPPermanentError (5xx) are subclasses.
  • NNTPDataError: a response that can't be parsed, such as a bad overview line. NNTPYEncError is 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.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 pynntp 3.2.0
File Size Uploaded Provenance Actions
pynntp-3.2.0.tar.gz 40.9 kB With provenance Details for pynntp-3.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 82.0 kB

Release files / pynntp-3.2.0.tar.gz

Download URL pynntp-3.2.0.tar.gz
Size 40.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0158deeb042d7a7fc4fddbdde79ee0e4ce0fc4c4d3dedd35dd8734be8401e4a9
BLAKE2b-256 checksum
How to use checksums
8f919e94adc96b76a5a644117b389a975222286624ef9ec6a353ba5867d6b88c
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 9, 2026.

Transparency log

Release files / pynntp-3.2.0-py3-none-any.whl

Download URL pynntp-3.2.0-py3-none-any.whl
Size 41.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
09fc6987feaefffa70658b7d05e8ee8cc2d90155f5ec128844221c9e44435010
BLAKE2b-256 checksum
How to use checksums
63d3571b6d28b89a2cbc850fc32485649cb8b8793ace8226dc7f27330f8d58bf
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 9, 2026.

Transparency log

Security for pynntp 3.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pynntp-3.2.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 9, 2026.

Transparency log

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