# Python Nntplib Module

The `nntplib` module defines a class `NNTP` which implements the client side of the Network News Transfer Protocol (NNTP). It is used to read and post articles to Usenet newsgroups.

**Note: The `nntplib` module is deprecated as of Python 3.11 and was removed in Python 3.13.**

## Importing the Module

```python
import nntplib
```

## Connecting to a Server

### Standard Connection

```python
import nntplib

# Connect to the server
# server = nntplib.NNTP('news.example.com')
```

### SSL Connection

For secure connections, use `NNTP_SSL`.

```python
# server = nntplib.NNTP_SSL('news.example.com')
```

## Selecting a Group

Before reading articles, you usually select a specific group using `group()`.

```python
# resp, count, first, last, name = server.group('comp.lang.python')
# print(f"Group: {name}, Article count: {count}")
```

## Retrieving Articles

You can retrieve the full article, just the header, or just the body.

```python
# Fetch the last article
# resp, number, message_id, lines = server.article(last)

# for line in lines:
#     print(line.decode('latin-1'))
```

## Posting

To post an article, use `post()`.

```python
# with open('article.txt', 'rb') as f:
#     server.post(f)
```

## Quitting

```python
# server.quit()
```

[[programming/python/python]]