Enhanced CSV reader and writer with automatic type inference.
Project description
philiprehberger-csv-kit
Enhanced CSV reader and writer with automatic type inference.
Install
pip install philiprehberger-csv-kit
Usage
Reading CSV
from philiprehberger_csv_kit import read_csv
rows = read_csv("data.csv")
# [{"name": "Alice", "age": 30, "score": 9.5}, ...]
Values are automatically cast to int, float, bool, or None. Disable with typed=False:
rows = read_csv("data.csv", typed=False)
# [{"name": "Alice", "age": "30", "score": "9.5"}, ...]
Writing CSV
from philiprehberger_csv_kit import write_csv
rows = [
{"name": "Alice", "age": 30, "score": 9.5},
{"name": "Bob", "age": 25, "score": 8.0},
]
write_csv("output.csv", rows)
write_csv("output.csv", rows, columns=["name", "age"]) # select columns
Type Inference
from philiprehberger_csv_kit import infer_types
raw = [{"val": "42"}, {"val": "3.14"}, {"val": "true"}, {"val": ""}]
typed = infer_types(raw)
# [{"val": 42}, {"val": 3.14}, {"val": True}, {"val": None}]
API
| Function | Description |
|---|---|
read_csv(path, typed=True, encoding="utf-8") |
Read CSV file, return list of dicts. Infers types when typed=True. |
write_csv(path, rows, columns=None, encoding="utf-8") |
Write list of dicts to CSV. Optional column filter. |
infer_types(rows) |
Cast string values to int, float, bool, or None where possible. |
Development
pip install -e .
python -m pytest tests/ -v
License
MIT
Project details
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 philiprehberger_csv_kit-0.1.0.tar.gz.
File metadata
- Download URL: philiprehberger_csv_kit-0.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6268efaae953ae91fbd35c89ef3c3dd10098825aa9d430fdd3ebcabc4e794857
|
|
| MD5 |
e80ab1c3938ca58b2ea0b5dd3929350d
|
|
| BLAKE2b-256 |
65d4144acc33b36bb7085dc1e14ef964fb9de0414452e83befcff9453f02c641
|
File details
Details for the file philiprehberger_csv_kit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_csv_kit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f44a4a21682b17aaec95b21338ef67968778ff744f317f71f5b20613e612d78
|
|
| MD5 |
0937fd181aed9d6f0f518591554ead26
|
|
| BLAKE2b-256 |
176a4724debdc0cab326e5bba516dbb7a51fd7e68a6929cac4b03c9cdbc7e64b
|