Skip to main content

High-performance CSV parsing library for Python with SIMD optimizations

Project description

FastCSV

High-performance CSV parsing library for Python with SIMD optimizations (AVX2/SSE4.2).

Features

  • 🚀 High Performance: Up to 7x faster than Python's standard csv module for large files
  • 🔌 Drop-in Replacement: Full compatibility with Python's csv module API
  • ⚡ SIMD Optimizations: Uses AVX2/SSE4.2 instructions for maximum performance
  • 📦 Batch Processing: Efficient handling of large CSV files with memory-mapped I/O
  • 🎯 Dialect Support: Full support for CSV dialects (register_dialect, get_dialect, list_dialects)
  • 🔍 Sniffer: Automatic format detection
  • 📚 Standard Dialects: Built-in support for excel, excel-tab, unix dialects

Installation

From PyPI (Recommended)

pip install pyfastcsv

From Source

See INSTALL.md for detailed installation instructions, including platform-specific requirements.

Quick start:

git clone https://github.com/baksvell/FastCSV.git
cd FastCSV
pip install -e .

Quick Start

Basic Usage

import fastcsv

# Read CSV file
with open('data.csv', 'r') as f:
    reader = fastcsv.reader(f)
    for row in reader:
        print(row)

# Write CSV file
with open('output.csv', 'w', newline='') as f:
    writer = fastcsv.writer(f)
    writer.writerow(['Name', 'Age', 'City'])
    writer.writerow(['John', '30', 'New York'])

Dictionary Reader/Writer

import fastcsv

# Read as dictionary
with open('data.csv', 'r') as f:
    reader = fastcsv.DictReader(f)
    for row in reader:
        print(row['Name'], row['Age'])

# Write from dictionary
with open('output.csv', 'w', newline='') as f:
    fieldnames = ['Name', 'Age', 'City']
    writer = fastcsv.DictWriter(f, fieldnames=fieldnames)
    writer.writeheader()
    writer.writerow({'Name': 'John', 'Age': '30', 'City': 'New York'})

Memory-Mapped Reader (for large files)

import fastcsv

# Efficient reading of large files
reader = fastcsv.mmap_reader('large_file.csv')
for row in reader:
    print(row)

Custom Dialects

import fastcsv

# Register custom dialect
fastcsv.register_dialect('semicolon', delimiter=';', quotechar='"')

# Use custom dialect
with open('data.csv', 'r') as f:
    reader = fastcsv.reader(f, dialect='semicolon')
    for row in reader:
        print(row)

Automatic Format Detection

import fastcsv

# Detect CSV format
with open('data.csv', 'rb') as f:
    sample = f.read(1024)
    dialect = fastcsv.Sniffer().sniff(sample.decode('utf-8', errors='ignore'))
    
    f.seek(0)
    reader = fastcsv.reader(f, dialect=dialect)
    for row in reader:
        print(row)

Performance

FastCSV is optimized for performance, especially with large files:

  • Small files (100 rows): ~1.5x faster
  • Medium files (1000 rows): ~1.5x faster
  • Large files (10000 rows): Up to 7x faster

Performance may vary depending on your hardware and CSV file structure.

Requirements

  • Python 3.10+
  • C++ compiler with C++17 support (GCC, Clang, or MSVC)
  • CMake 3.15+
  • pybind11 2.10+

Note: For detailed installation instructions and troubleshooting, see INSTALL.md

API Compatibility

FastCSV provides full compatibility with Python's standard csv module:

  • fastcsv.reader() - equivalent to csv.reader()
  • fastcsv.writer() - equivalent to csv.writer()
  • fastcsv.DictReader() - equivalent to csv.DictReader()
  • fastcsv.DictWriter() - equivalent to csv.DictWriter()
  • fastcsv.register_dialect() - equivalent to csv.register_dialect()
  • fastcsv.get_dialect() - equivalent to csv.get_dialect()
  • fastcsv.list_dialects() - equivalent to csv.list_dialects()
  • fastcsv.Sniffer() - equivalent to csv.Sniffer()

Additional Features

Memory-Mapped Reader

For very large files, use the memory-mapped reader:

import fastcsv

reader = fastcsv.mmap_reader('large_file.csv')
for row in reader:
    process(row)

This uses memory-mapped I/O for efficient handling of files that don't fit in memory.

More Examples

For comprehensive examples and use cases, see EXAMPLES.md.

Troubleshooting

Installation Issues

Problem: "CMake not found"

Problem: "C++ compiler not found" (Windows)

Problem: "pybind11 not found"

  • Solution: pip install pybind11

Problem: Build fails with SIMD errors

  • Solution: Your CPU might not support AVX2/SSE4.2. The code should fall back gracefully, but if not, check your CPU capabilities.

Runtime Issues

Problem: "ImportError: cannot import name '_native'"

  • Solution: The native module wasn't built. Run pip install -e . to rebuild.

Problem: Performance is not as expected

  • Solution: Ensure your CPU supports AVX2/SSE4.2. Check with: python -c "import fastcsv; print(fastcsv.__version__)" after pip install pyfastcsv

License

MIT License

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Changelog

0.2.0

  • Fixed bug with quoted fields in multi-line buffers
  • Performance optimizations
  • Improved error handling

0.1.0

  • Initial release
  • Basic CSV parsing functionality
  • SIMD optimizations
  • Dialect support
  • Sniffer implementation

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

pyfastcsv-0.2.0.tar.gz (46.8 kB view details)

Uploaded Source

Built Distributions

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

pyfastcsv-0.2.0-cp312-cp312-win_amd64.whl (116.3 kB view details)

Uploaded CPython 3.12Windows x86-64

pyfastcsv-0.2.0-cp312-cp312-win32.whl (107.2 kB view details)

Uploaded CPython 3.12Windows x86

pyfastcsv-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (172.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyfastcsv-0.2.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (183.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ i686

pyfastcsv-0.2.0-cp312-cp312-macosx_11_0_arm64.whl (124.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyfastcsv-0.2.0-cp311-cp311-win_amd64.whl (115.2 kB view details)

Uploaded CPython 3.11Windows x86-64

pyfastcsv-0.2.0-cp311-cp311-win32.whl (106.5 kB view details)

Uploaded CPython 3.11Windows x86

pyfastcsv-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (173.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyfastcsv-0.2.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (182.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ i686

pyfastcsv-0.2.0-cp311-cp311-macosx_11_0_arm64.whl (123.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyfastcsv-0.2.0-cp310-cp310-win_amd64.whl (114.4 kB view details)

Uploaded CPython 3.10Windows x86-64

pyfastcsv-0.2.0-cp310-cp310-win32.whl (105.7 kB view details)

Uploaded CPython 3.10Windows x86

pyfastcsv-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (171.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyfastcsv-0.2.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (181.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ i686

pyfastcsv-0.2.0-cp310-cp310-macosx_11_0_arm64.whl (122.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file pyfastcsv-0.2.0.tar.gz.

File metadata

  • Download URL: pyfastcsv-0.2.0.tar.gz
  • Upload date:
  • Size: 46.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyfastcsv-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a6bb0aba2497af00e0dbde7ef2d2aea4e7f64eb6805bef80bec71c8de1d4d7ae
MD5 fea1b26053be3a90c85c900fab36dbc6
BLAKE2b-256 e0e2814732f32433978bb183c36813379599905e6b0e14555aba9b379c7e3384

See more details on using hashes here.

File details

Details for the file pyfastcsv-0.2.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pyfastcsv-0.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 116.3 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyfastcsv-0.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 76d273064d71f2580ba4a9aeeaa539bd8df5a7b78dfddb885a28b9081bfcef0d
MD5 c476143d3a71278367916ef99d2baf4c
BLAKE2b-256 c5785badfd9a8aa4ad3d7f002a3704c95a58bcdfbe24ddd5562e9a004c5abac4

See more details on using hashes here.

File details

Details for the file pyfastcsv-0.2.0-cp312-cp312-win32.whl.

File metadata

  • Download URL: pyfastcsv-0.2.0-cp312-cp312-win32.whl
  • Upload date:
  • Size: 107.2 kB
  • Tags: CPython 3.12, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyfastcsv-0.2.0-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 48fa31a6a9110c725fed38f3cacb8add21bbebd75ecce1277315933c5aa0e221
MD5 915a8c0642027c5f3c809c2a710278fb
BLAKE2b-256 409a595d2ebd8a74e6892504cabcfce0ff31121ae08cf9574ffc09c0b607a69c

See more details on using hashes here.

File details

Details for the file pyfastcsv-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyfastcsv-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5844700252d54673c77d39d758fbaeddbcf70ac11cb9e500ec7ffc7b47feec41
MD5 dffae7ecc3f6803831ff04c3aaccb7df
BLAKE2b-256 cbc2ff91ee4faa048cc8634fa61b83d467f043a4e7e851ce28687e6ac1b9b380

See more details on using hashes here.

File details

Details for the file pyfastcsv-0.2.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for pyfastcsv-0.2.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 6d3e1a53aa691a39b5a7df07ffd40c599b58204f3465e73178ffab705e5826f5
MD5 241936939f789fd6747a3876ecfd1e27
BLAKE2b-256 c21cbf9091f7d801f7bfe66b267baedd45698691c62124cdd1414c3386405138

See more details on using hashes here.

File details

Details for the file pyfastcsv-0.2.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyfastcsv-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3d3fc35d3267ad282b5d9e62be4f9fdb1ee3fef495a16ada3202462a1eaa8b20
MD5 aa43a368c6fab72cfaa5b6cacc76e280
BLAKE2b-256 20156178b93d419aab20a3ca977fb19e8100d8c4596ea889a5852b7f72293fca

See more details on using hashes here.

File details

Details for the file pyfastcsv-0.2.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pyfastcsv-0.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 115.2 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyfastcsv-0.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c4e0f246b7c34b8da83be667d9abfeb0f5ebe234470d8ec37161ca957eeeaea7
MD5 6cc6cd6bf7419ff43ec1357d78439f86
BLAKE2b-256 1252d214967606527be7ea7bb2063f9ddf9af97506ab43ce67f45d4cb4495821

See more details on using hashes here.

File details

Details for the file pyfastcsv-0.2.0-cp311-cp311-win32.whl.

File metadata

  • Download URL: pyfastcsv-0.2.0-cp311-cp311-win32.whl
  • Upload date:
  • Size: 106.5 kB
  • Tags: CPython 3.11, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyfastcsv-0.2.0-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 e184c80b7a040aaf427b479f0e0284b8e5ebabdf22235050fcdf0875e9ce4427
MD5 c5e91c835b87cfc26fe78c1686f4116e
BLAKE2b-256 5c4603884e5a905a98d805ba2c343731642b458bdab818d1f7271f5b386c70a1

See more details on using hashes here.

File details

Details for the file pyfastcsv-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyfastcsv-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 75c8afc2053e30ee195bdd43dfc439a87a5ad813c1fabcd373982e6d279a1cab
MD5 a116d43b1be6bd478318dcdd4b89c093
BLAKE2b-256 492076a0f5d55522517e6b1e0c0fb9a0884908515647a5950dad9c0f42e3afc5

See more details on using hashes here.

File details

Details for the file pyfastcsv-0.2.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for pyfastcsv-0.2.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 05c65083ca2d286e99859867b8e14ca1ef99abe1a81cceae22416d082fef6d4e
MD5 8b8c51c1e5555e004b09241aba80fd00
BLAKE2b-256 c46af036bae4519830da8ed8e5870774c532f02f75d7805418f338037d3ffe26

See more details on using hashes here.

File details

Details for the file pyfastcsv-0.2.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyfastcsv-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f51a4110c7bcdc573c4c260518ff58f0d0d5ade7c5c74b4875462cce300fa3b8
MD5 0482680083f61aa5042aabc1f3522d21
BLAKE2b-256 bd8fdf835821f4b7dda25d248bb4209119dc7b12758f0c592007ba7fcf18b4a8

See more details on using hashes here.

File details

Details for the file pyfastcsv-0.2.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pyfastcsv-0.2.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 114.4 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyfastcsv-0.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 cf9d52bfad656722eb89b735790e7c84dee240e01781ae5f6502f45f1ae6b318
MD5 cc18ef68b90200121bd86920daab8e26
BLAKE2b-256 e3b3aa6048419abd31f0b3c5d3c1740c7115c2c7fc788c0dacc73ee8ca02fbf8

See more details on using hashes here.

File details

Details for the file pyfastcsv-0.2.0-cp310-cp310-win32.whl.

File metadata

  • Download URL: pyfastcsv-0.2.0-cp310-cp310-win32.whl
  • Upload date:
  • Size: 105.7 kB
  • Tags: CPython 3.10, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyfastcsv-0.2.0-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 2fa7dfa9bef1558bf026c31d96bf71cd264a8735eb0428d58f5d894ff3be9bb4
MD5 a918be8f85d1dc729a9ab6e9d94c9400
BLAKE2b-256 bceac77b80039caa2649a1d10c0a6f2938b36a28e11f69f37abc6a7d1dba7f60

See more details on using hashes here.

File details

Details for the file pyfastcsv-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyfastcsv-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6c6459eea70efff425f8ee43b076210dd4bb72666cab2bb7558425d4a230ddc4
MD5 3cf8dcc3e0e4bbbdd77526e6b631343f
BLAKE2b-256 45130f3a9ec127b02884770d372fd33172343b89628c89959ce4f86b7637aaa6

See more details on using hashes here.

File details

Details for the file pyfastcsv-0.2.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for pyfastcsv-0.2.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b0c8d7cc773d6219f24287840a4cd4817dcf3f7bf05bb78de314efb284c74761
MD5 feb60c32745b69e42c86fe162907bbde
BLAKE2b-256 612cc814ede517aa15d7ea6aec5eaaac458b7a530f11fea80dea6e6ec9cc521f

See more details on using hashes here.

File details

Details for the file pyfastcsv-0.2.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyfastcsv-0.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a71142ba2a2e6770ac4f675d9612229b2eb17d4fdf11ce1e4d426b17a4ed8213
MD5 bec2d72cb5872783bf64989b69736e42
BLAKE2b-256 2a46c33ec040ff69296c4da6d4c2c3c0763e0c0b7e08b74a74184f6f4d6f2d32

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