semvec/pypi-packages huggingface dataset:
pytermtalk-ref 1.1.1
My reference implementation of a terminal-based chat program using sockets; supports both client and server modes.
Requires Python: >=3.10
Keywords: chat, terminal, cli, client & server, reference

# PyTermTalk-Ref 🖥️💬

![Python](https://img.shields.io/badge/Python-3.10-blue?logo=python\&logoColor=white) ![License](https://img.shields.io/badge/License-MIT-green)

A Python **reference implementation** of a terminal-based chat program using sockets. Supports **both server and client modes**.
This project serves as a **starting point** for building a production-ready terminal chat application.

> ⚠️ **Warning:** This script does **not** provide authentication. Do **not** use it for production or sensitive purposes.

The original script by Andrea Ciarrocchi was published in *Linux Magazine*, October 2025.

---

## Features

* Terminal-based chat via sockets
* Non-blocking communication using **threads**
* Supports multiple clients simultaneously
* Easy to extend and modify for educational purposes

---

## Installation & running from PyPi 

```bash
mkdir testing && cd testing
python -m venv .venv
source .venv/bin/activate
pip install pytermtalk-ref

# and now run the script ...

python pytermtall-ref

# when finished, deactivate the venv:

deactivate
```

## Installation & running from PyPi with uv

When using the uv tool:

```bash
mkdir testing && cd testing
uv init
uv add pytermtalk-ref

# and now run the script ...

uv run pytermtalk-ref
```

## Installation & running from github

When using the uv tool:

```bash
git clone https://github.com/rikroos/pytermtalk-ref.git
cd pytermtalk-ref
uv run pytermtalk-ref
```

Otherwise, if not using the uv tool:

```bash
git clone https://github.com/rikroos/pytermtalk-ref.git
cd pytermtalk-ref
python src/pytermtalk_ref/chat.py
```

---

## Usage

On startup, choose between **server** or **client** mode.

### Server Mode

* Initializes a socket (`127.0.0.1:5555`)
* Starts listening for client connections
* Launches a thread for non-blocking broadcasting to all connected clients
* For each new client, a separate thread is created to handle communication

### Client Mode

* Initializes a socket (`127.0.0.1:5555`)
* Launches a thread to receive messages from the server non-blocking
* Messages may come from other clients or the server operator
* Client can send messages to other clients via the server

---

## Future Work

* None, the project serves as a reference implementation for other projects

---

## Example

```bash
# Start server
$ uv run pytermtalk-ref

Warning: do not use in production environments or for exchanging sensitive information!

Start server or client? (s/c): s
[LISTENING] Server is listening on 127.0.0.1:5555
[NEW CONNECTION] ('127.0.0.1', 33076) connected.
('127.0.0.1', 33076): Hi there. Anybody home?

# Start client
$ uv run pytermtalk-ref

Warning: do not use in production environments or for exchanging sensitive information!

Start server or client? (s/c): c
Hi there. Anybody home?

```

---

## License

MIT License
chunkcheck 0.1.1
Chunk and checkpoint memory optimisation
Requires Python: >=3.9

# Chunk and Checkpoint Memory Optimisation

[![CI](https://github.com/alan-turing-institute/chunk-and-checkpoint/actions/workflows/ci.yml/badge.svg)](https://github.com/alan-turing-institute/chunk-and-checkpoint/actions/workflows/ci.yml)

Reduce peak memory when training models in PyTorch which require batched operations internally, such as Swin Transformers.

TLDR:

```python
from chunkcheck import chunk_and_checkpoint

...

# There is a really large batch size along dimension 0. `chunk_and_checkpoint`
# substantially reduces peak memory usage. Adjust `chunk_size` to achieve your
# preferred time vs memory tradeoff.
y = chunk_and_checkpoint(f, x1, x2, ..., chunk_size=4, batch_dim=0)

...
```
## Installation

```bash
pip install chunkcheck
```

## Usage

`chunkcheck` exports one function: `chunk_and_checkpoint`.
It can be fruitfully used to reduce the peak memory requirement of a programme written using PyTorch when the following hold:
- You have one or more input `torch.Tensor`s (`x1`, `x2`, ...) whose first dimension is a "batch" dimension of equal size.
- You wish to compute `f(x1, x2, ...)`, where `f` applies the same operation to each "batch" in (`x1`, `x2`, ...).
- The memory required during intermediate computations in `f` is large compared to the memory required to store (`x1`, `x2`, ...) and the output of `f(x1, x2, ...)`. A canonical example of this kind of function is an MLP with large hidden dimension(s).

Instead of calling `f(x1, x2, ...)`, call `chunk_and_checkpoint(f, x1, x2, ..., chunk_size=chunk_size)`, for some `int` `chunk_size`.
Doing this should substantially reduce peak memory, and increase the computation time by only a small amount for a well-chosen `chunk_size`.
`chunk_and_checkpoint` will reduce peak memory further than [`torch.utils.checkpoint.checkpoint`](https://docs.pytorch.org/docs/stable/checkpoint.html) ("activation checkpointing"), the exact amount depends on `chunk_size`.

See the docstring for `chunk_and_checkpoint` for more information.
For a more detailed explanation of why this works, and some usage case studies, see our note on arXiv (TODO: write this and link to it).


## Development

Clone the repo and `cd` into the repository.
Then create a virtual environment, enter it, and install all dependencies:

```bash
uv venv
source .venv/bin/activate
uv sync
```

Running the tests:

```bash
pytest -v
```