Skip to main content

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-dev or python3-dev package 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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Acknowledgments

  • The Rust CSV crate for providing the underlying parsing engine
  • PyO3 for making Rust-Python bindings seamless

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

rs_csv_reader-0.1.3.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rs_csv_reader-0.1.3-cp38-abi3-manylinux_2_34_x86_64.whl (252.2 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.34+ x86-64

File details

Details for the file rs_csv_reader-0.1.3.tar.gz.

File metadata

  • Download URL: rs_csv_reader-0.1.3.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.3

File hashes

Hashes for rs_csv_reader-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0440c0098cf83df4c6e003af7f1684d71a697b2e255d28fda2fbea574f88d538
MD5 3cac2fc38f32237fb880d4886b3fcf1f
BLAKE2b-256 d57eca35b7fef0ca7535a1bed7a864d5eaa8103089650a2e9ee07984735eb990

See more details on using hashes here.

File details

Details for the file rs_csv_reader-0.1.3-cp38-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for rs_csv_reader-0.1.3-cp38-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 aec0e2823943c4e88f9843ec2049440cb818fb5b169833c016dba23cc0c089d5
MD5 4816029f0172d3cd41fb0ad760bd3b25
BLAKE2b-256 ed8210c2541d1bacf9278cbec29a7b18096bd1337c7924d2f9796131c5c0440e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page