No project description provided
Project description
CSV Reader - Optimization Performance CSV Parser for Python
A Optimization performance CSV parsing library written in Rust with Python bindings. Designed for efficiently processing large CSV files with minimal memory footprint.
Features
- High Performance: Parse CSV files significantly faster than Python's native CSV module
- Memory Efficient: Process files in optimized batches to reduce memory usage
- Large File Support: Efficiently handle multi-gigabyte CSV files
- Customizable Batch Size: Control memory usage and batch processing
Installation
pip install rs-csv-reader
# Or if you're using UV
uv pip install rs-csv-reader
Usage
Basic Usage
from csv_reader import CSVParser
# Create a parser with default settings
parser = CSVParser("large_file.csv", batch_size=5000)
# Read the file in batches
batches = parser.read()
# Process each batch
for batch in batches:
for row in batch:
# Each row is a dictionary with column names as keys
print(row['id'], row['amount'])
# Count rows without loading the entire file
total_rows = parser.count_rows()
print(f"Total rows: {total_rows}")
Reading Specific Chunks
Efficiently read specific portions of a CSV file without loading the entire file:
# Read a specific chunk (starting from row 10000, reading 1000 rows)
chunk = parser.read_chunk(start_row=10000, num_rows=1000)
# Process the chunk
for row in chunk:
process_row(row)
Get File Information
# Get file metadata
file_info = parser.get_file_info()
print(f"File size: {file_info['size_mb']} MB")
print(f"Headers: {file_info['headers']}")
Performance
Can see on this repository profiling testing, testing with:
- Intel core i7
- 16 gb memory
- 8 core cpu
Benchmarks on a 2-million row CSV file:
| Parser | Time (s) | Memory (MB) | Rows/sec |
|---|---|---|---|
| Python CSV | 4.23 | 1583.94 | 473028.05 |
| Pandas (full) | 9.42 | 1260.59 | 212226.58 |
| Pandas (chunked) | 9.13 | 1231.05 | 219060.70 |
| CSV Reader | 2.95 | 3183.24 | 678927.10 |
How It Works
This library uses Rust's high-performance CSV parsing capabilities with smart buffering techniques:
- For files under 100MB: Loads the entire file into memory for maximum speed
- For larger files: Uses efficient buffered reading with a 64KB buffer
- Processes data in batches to balance memory usage and performance
Building from Source
Prerequisites
- Rust toolchain (install from rust-lang.org)
- Maturin (
pip install maturin) - Python development headers (
python-devorpython3-devpackage on Linux)
# Clone the repository
git clone https://github.com/yourusername/csv-reader.git
cd csv-reader
# Build the Rust library
maturin build --release
# Install the built wheel
pip install target/wheels/rs_csv_reader-*.whl
You can also use development mode for a faster workflow during development:
maturin develop --release
Requirements
- Python 3.7+
- No additional dependencies required!
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Acknowledgments
- The Rust CSV crate for providing the underlying parsing engine
- PyO3 for making Rust-Python bindings seamless
Profiling Tools
For doing a testing, this the tools for test the CSV reader https://github.com/yosephbernandus/csv_reader_profiling
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 rs_csv_reader-0.1.4.tar.gz.
File metadata
- Download URL: rs_csv_reader-0.1.4.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b3dc5d8bad22de7bcb28e0f82f8fde785326c5f8ad9cd89bab4e9c8e8553ac4
|
|
| MD5 |
79ad062de4b31bce91457687a7b3daa8
|
|
| BLAKE2b-256 |
7dfb3e84c6f5f38d4900a8475c0e7ca488bfd8eaf176d169d823e6c27e9b7898
|
File details
Details for the file rs_csv_reader-0.1.4-cp38-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: rs_csv_reader-0.1.4-cp38-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 252.2 kB
- Tags: CPython 3.8+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76c3484bab14168166708434b7fc83c535d1c9190b3a01e8983371754b08cd17
|
|
| MD5 |
0b61b2da252f070f7859165d7dda5b03
|
|
| BLAKE2b-256 |
b93d98c01df9e9899873b7a74dc536dda437b53f4f4ffc549c23098d79dc8238
|