A lightweight Python package for easy reading and writing of JSON, JSONL, and Pickle files.
Project description
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
You can install this package using pip:
pip install whywhytools
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)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file whywhytools-0.7.0.tar.gz.
File metadata
- Download URL: whywhytools-0.7.0.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbd226dedeb1746aee056f10ef5adeba309c8749e6f0f6a5deabe92954924690
|
|
| MD5 |
e7c93f139368a3a135f265cff9f3729e
|
|
| BLAKE2b-256 |
1fa1d3800de6744eb0fc03410cce5e7b5e3fbb2fae9c0670b4bea8b0653c90ea
|
Provenance
The following attestation bundles were made for whywhytools-0.7.0.tar.gz:
Publisher:
publish_to_pypi.yaml on whywhybug/whywhytools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
whywhytools-0.7.0.tar.gz -
Subject digest:
cbd226dedeb1746aee056f10ef5adeba309c8749e6f0f6a5deabe92954924690 - Sigstore transparency entry: 980603546
- Sigstore integration time:
-
Permalink:
whywhybug/whywhytools@3be7a388a5b148edde65de18cc2e3029838510f1 -
Branch / Tag:
refs/tags/v0.7.0 - Owner: https://github.com/whywhybug
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_to_pypi.yaml@3be7a388a5b148edde65de18cc2e3029838510f1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file whywhytools-0.7.0-py3-none-any.whl.
File metadata
- Download URL: whywhytools-0.7.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0aab182351e2059e73fbeced76def2617d8bbc1ca15253a08cc51f04eb1833bf
|
|
| MD5 |
77de07008d698012ea03263b7b0a1747
|
|
| BLAKE2b-256 |
ae6e76ca8397d9b81fc1027573f55eed902682e28cda3e78f1f587f7d0e3901d
|
Provenance
The following attestation bundles were made for whywhytools-0.7.0-py3-none-any.whl:
Publisher:
publish_to_pypi.yaml on whywhybug/whywhytools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
whywhytools-0.7.0-py3-none-any.whl -
Subject digest:
0aab182351e2059e73fbeced76def2617d8bbc1ca15253a08cc51f04eb1833bf - Sigstore transparency entry: 980603621
- Sigstore integration time:
-
Permalink:
whywhybug/whywhytools@3be7a388a5b148edde65de18cc2e3029838510f1 -
Branch / Tag:
refs/tags/v0.7.0 - Owner: https://github.com/whywhybug
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_to_pypi.yaml@3be7a388a5b148edde65de18cc2e3029838510f1 -
Trigger Event:
push
-
Statement type: