Skip to main content

whywhytools

whywhytools is a lightweight Python package for reading and writing JSON, JSON Lines (.jsonl), and Pickle files. It provides simple and intuitive APIs for handling these common data formats.

Installation

The package can be installed via pip:

pip install whywhytools

For extended functionalities, optional dependencies are available.

To install dependencies for specific features:

pip install "whywhytools[torch]"
pip install "whywhytools[safetensors]"

To install all optional dependencies simultaneously:

pip install "whywhytools[all]"

Quickstart

JSON Lines (.jsonl)

Handle .jsonl files, supporting read, write, and append operations.

Write JSONL File
from whywhytools import write_jsonl

data = [
    {'id': 'data-1', 'text': 'hello world'},
    {'id': 'data-2', 'text': 'whywhytools is awesome'}
]

# Write to file
write_jsonl(data, 'output.jsonl') # [INFO] save to output.jsonl

# If file exists
write_jsonl(data, 'output.jsonl') # [INFO] output.jsonl already exists.

# Force overwrite existing file
write_jsonl(data, 'output.jsonl', force=True) # [INFO] save to output.jsonl

# Silent mode (not print any message)
write_jsonl(data, 'output.jsonl', force=True, silent=True)
Append to JSONL File
from whywhytools import append_jsonl

new_data = [{'id': 'data-3', 'text': 'new line'}]
append_jsonl(new_data, 'output.jsonl')
Read JSONL File
from whywhytools import read_jsonl

data = read_jsonl('output.jsonl')
print(data)
# [{'id': 'data-1', 'text': 'hello world'}, {'id': 'data-2', 'text': 'whywhytools is awesome'}, {'id': 'data-3', 'text': 'new line'}]

JSON (.json)

Handle standard .json files.

Write JSON File
from whywhytools import write_json

data = {'project': 'whywhytools', 'version': '0.1.0'}

# Write to file
write_json(data, 'config.json')
Read JSON File
from whywhytools import read_json

config = read_json('config.json')
print(config)

Pickle (.pkl)

Handle Python's pickle serialization format.

Save Pickle File
from whywhytools import save_pickle

model_data = {'weights': [0.1, 0.5, 0.9], 'bias': 0.01}
save_pickle(model_data, 'model.pkl')
Load Pickle File
from whywhytools import load_pickle

data = load_pickle('model.pkl')
print(data)

Plain Text (.txt or general text files)

Handle plain text files, supporting direct string reading or line-by-line list loading, as well as write and append operations.

Write Text File
from whywhytools import write_file

lines = [
    "First line of the text file.",
    "Second line is here."
]

# Write a list of strings to a file
write_file(lines, "document.txt")

# Write a single string
write_file("Just one line here.", "single_doc.txt")
Append to Text File
from whywhytools import append_file

# Append single or multiple lines
append_file("This is a newly appended line.", "document.txt")
Read Text File
from whywhytools import read_file

# Read entire file as a single string
content = read_file("document.txt")
print(content)

# Read file line by line into a list
lines = read_file("document.txt", lines=True)
print(lines)

PyTorch (.pt or .pth)

Handle PyTorch files. Compared to the original torch.save and torch.load, whywhytools provides built-in path type checking, automatic parent directory creation, and safety guards like force argument to prevent accidental overwrites.

Save PyTorch File
import torch
from whywhytools import save_pt

model_data = {'weights': torch.tensor([0.1, 0.5, 0.9])}
save_pt(model_data, 'model.pt')
Load PyTorch File
from whywhytools import load_pt

data = load_pt('model.pt')
print(data)

# Load safely with weights_only=True
safe_data = load_pt('model.pt', weights_only=True)

License

MIT

Metadata

Release files for whywhytools 1.13.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 whywhytools 1.13.0
File Size Uploaded Provenance Actions
whywhytools-1.13.0.tar.gz 75.1 kB With provenance Details for whywhytools-1.13.0.tar.gz

Built distribution (wheel)

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

Total release size: 91.0 kB

Release files / whywhytools-1.13.0.tar.gz

Download URL whywhytools-1.13.0.tar.gz
Size 75.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ca1e19f037cb02714f8a643f0a3fbf2f6ed4fe382040deff38b4eccd5bcf3d86
BLAKE2b-256 checksum
How to use checksums
e90368f8064a67e9dd6ad3c490d1bf583c837fa5817c8f312ae685737a847761
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 2, 2026.

Transparency log

Release files / whywhytools-1.13.0-py3-none-any.whl

Download URL whywhytools-1.13.0-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5bb8d5d128f1928351690dbc34fcb13d0a73f25d758a5349d6ab36d9553b1bcc
BLAKE2b-256 checksum
How to use checksums
3dea663963ea64ddac96dbf008afdb76bcc6f28347e46608266ad3e642805dce
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 2, 2026.

Transparency log

Security for whywhytools 1.13.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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for whywhytools-1.13.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 2, 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