Skip to main content

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

Release files for pyfastcsv 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyfastcsv 0.2.0
File Size Uploaded
pyfastcsv-0.2.0.tar.gz 46.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pyfastcsv 0.2.0
File
pyfastcsv-0.2.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
pyfastcsv-0.2.0-cp312-cp312-win32.whl CPython 3.12 CPython 3.12 Windows x86-32 Details
pyfastcsv-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
pyfastcsv-0.2.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-32 Details
pyfastcsv-0.2.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
pyfastcsv-0.2.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
pyfastcsv-0.2.0-cp311-cp311-win32.whl CPython 3.11 CPython 3.11 Windows x86-32 Details
pyfastcsv-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
pyfastcsv-0.2.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-32 Details
pyfastcsv-0.2.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
pyfastcsv-0.2.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
pyfastcsv-0.2.0-cp310-cp310-win32.whl CPython 3.10 CPython 3.10 Windows x86-32 Details
pyfastcsv-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
pyfastcsv-0.2.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-32 Details
pyfastcsv-0.2.0-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details

Total release size: 2.1 MB

Release files / pyfastcsv-0.2.0.tar.gz

Download URL pyfastcsv-0.2.0.tar.gz
Size 46.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a6bb0aba2497af00e0dbde7ef2d2aea4e7f64eb6805bef80bec71c8de1d4d7ae
BLAKE2b-256 checksum
How to use checksums
e0e2814732f32433978bb183c36813379599905e6b0e14555aba9b379c7e3384
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyfastcsv-0.2.0-cp312-cp312-win_amd64.whl

Download URL pyfastcsv-0.2.0-cp312-cp312-win_amd64.whl
Size 116.3 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
76d273064d71f2580ba4a9aeeaa539bd8df5a7b78dfddb885a28b9081bfcef0d
BLAKE2b-256 checksum
How to use checksums
c5785badfd9a8aa4ad3d7f002a3704c95a58bcdfbe24ddd5562e9a004c5abac4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyfastcsv-0.2.0-cp312-cp312-win32.whl

Download URL pyfastcsv-0.2.0-cp312-cp312-win32.whl
Size 107.2 kB
Tags CPython 3.12 Windows x86-32
SHA-256 checksum
How to use checksums
48fa31a6a9110c725fed38f3cacb8add21bbebd75ecce1277315933c5aa0e221
BLAKE2b-256 checksum
How to use checksums
409a595d2ebd8a74e6892504cabcfce0ff31121ae08cf9574ffc09c0b607a69c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyfastcsv-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyfastcsv-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 172.4 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
5844700252d54673c77d39d758fbaeddbcf70ac11cb9e500ec7ffc7b47feec41
BLAKE2b-256 checksum
How to use checksums
cbc2ff91ee4faa048cc8634fa61b83d467f043a4e7e851ce28687e6ac1b9b380
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyfastcsv-0.2.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL pyfastcsv-0.2.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl
Size 183.2 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-32
SHA-256 checksum
How to use checksums
6d3e1a53aa691a39b5a7df07ffd40c599b58204f3465e73178ffab705e5826f5
BLAKE2b-256 checksum
How to use checksums
c21cbf9091f7d801f7bfe66b267baedd45698691c62124cdd1414c3386405138
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyfastcsv-0.2.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL pyfastcsv-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Size 124.1 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3d3fc35d3267ad282b5d9e62be4f9fdb1ee3fef495a16ada3202462a1eaa8b20
BLAKE2b-256 checksum
How to use checksums
20156178b93d419aab20a3ca977fb19e8100d8c4596ea889a5852b7f72293fca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyfastcsv-0.2.0-cp311-cp311-win_amd64.whl

Download URL pyfastcsv-0.2.0-cp311-cp311-win_amd64.whl
Size 115.2 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
c4e0f246b7c34b8da83be667d9abfeb0f5ebe234470d8ec37161ca957eeeaea7
BLAKE2b-256 checksum
How to use checksums
1252d214967606527be7ea7bb2063f9ddf9af97506ab43ce67f45d4cb4495821
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyfastcsv-0.2.0-cp311-cp311-win32.whl

Download URL pyfastcsv-0.2.0-cp311-cp311-win32.whl
Size 106.5 kB
Tags CPython 3.11 Windows x86-32
SHA-256 checksum
How to use checksums
e184c80b7a040aaf427b479f0e0284b8e5ebabdf22235050fcdf0875e9ce4427
BLAKE2b-256 checksum
How to use checksums
5c4603884e5a905a98d805ba2c343731642b458bdab818d1f7271f5b386c70a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyfastcsv-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyfastcsv-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 173.0 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
75c8afc2053e30ee195bdd43dfc439a87a5ad813c1fabcd373982e6d279a1cab
BLAKE2b-256 checksum
How to use checksums
492076a0f5d55522517e6b1e0c0fb9a0884908515647a5950dad9c0f42e3afc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyfastcsv-0.2.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL pyfastcsv-0.2.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl
Size 182.9 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-32
SHA-256 checksum
How to use checksums
05c65083ca2d286e99859867b8e14ca1ef99abe1a81cceae22416d082fef6d4e
BLAKE2b-256 checksum
How to use checksums
c46af036bae4519830da8ed8e5870774c532f02f75d7805418f338037d3ffe26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyfastcsv-0.2.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL pyfastcsv-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Size 123.5 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f51a4110c7bcdc573c4c260518ff58f0d0d5ade7c5c74b4875462cce300fa3b8
BLAKE2b-256 checksum
How to use checksums
bd8fdf835821f4b7dda25d248bb4209119dc7b12758f0c592007ba7fcf18b4a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyfastcsv-0.2.0-cp310-cp310-win_amd64.whl

Download URL pyfastcsv-0.2.0-cp310-cp310-win_amd64.whl
Size 114.4 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
cf9d52bfad656722eb89b735790e7c84dee240e01781ae5f6502f45f1ae6b318
BLAKE2b-256 checksum
How to use checksums
e3b3aa6048419abd31f0b3c5d3c1740c7115c2c7fc788c0dacc73ee8ca02fbf8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyfastcsv-0.2.0-cp310-cp310-win32.whl

Download URL pyfastcsv-0.2.0-cp310-cp310-win32.whl
Size 105.7 kB
Tags CPython 3.10 Windows x86-32
SHA-256 checksum
How to use checksums
2fa7dfa9bef1558bf026c31d96bf71cd264a8735eb0428d58f5d894ff3be9bb4
BLAKE2b-256 checksum
How to use checksums
bceac77b80039caa2649a1d10c0a6f2938b36a28e11f69f37abc6a7d1dba7f60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyfastcsv-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyfastcsv-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 171.9 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
6c6459eea70efff425f8ee43b076210dd4bb72666cab2bb7558425d4a230ddc4
BLAKE2b-256 checksum
How to use checksums
45130f3a9ec127b02884770d372fd33172343b89628c89959ce4f86b7637aaa6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyfastcsv-0.2.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL pyfastcsv-0.2.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl
Size 181.8 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-32
SHA-256 checksum
How to use checksums
b0c8d7cc773d6219f24287840a4cd4817dcf3f7bf05bb78de314efb284c74761
BLAKE2b-256 checksum
How to use checksums
612cc814ede517aa15d7ea6aec5eaaac458b7a530f11fea80dea6e6ec9cc521f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pyfastcsv-0.2.0-cp310-cp310-macosx_11_0_arm64.whl

Download URL pyfastcsv-0.2.0-cp310-cp310-macosx_11_0_arm64.whl
Size 122.4 kB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a71142ba2a2e6770ac4f675d9612229b2eb17d4fdf11ce1e4d426b17a4ed8213
BLAKE2b-256 checksum
How to use checksums
2a46c33ec040ff69296c4da6d4c2c3c0763e0c0b7e08b74a74184f6f4d6f2d32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.2.0 This release

16 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page