High-performance numpy.loadtxt replacement using mmap + OpenMP + fast_float
Project description
fast_loadtxt
A high-performance drop-in replacement for numpy.loadtxt, built with mmap + OpenMP + fast_float.
Designed for scientific computing workflows where loading large text data files is a bottleneck — simulation outputs, observational datasets, parameter chains, etc.
Why?
numpy.loadtxt reads the entire file into memory, parses it single-threaded, and creates intermediate Python objects. For large files this is slow and memory-hungry.
fast_loadtxt takes a different approach:
| numpy.loadtxt | fast_loadtxt | |
|---|---|---|
| File access | read() into heap buffer |
mmap (zero-copy, OS-managed) |
| Parsing | Single-threaded, strtod |
OpenMP parallel, fast_float |
| Intermediate allocs | Many (Python objects, lists) | One (the output array) |
| Memory overhead | ~3× file size | ~8 bytes per row (line offsets) |
Architecture
Pass 1 (serial): mmap file → scan bytes for '\n' → build line offset table
Detect column count from first data line
Allocate numpy array (nrows × ncols)
Pass 2 (parallel): OpenMP threads parse chunks of rows
Each thread reads mmap'd bytes → fast_float → writes into numpy buffer
Zero intermediate allocations
Cleanup: munmap (OS reclaims pages), free offset table
Only the numpy array survives
Installation
Requirements: C++17 compiler with OpenMP support, Python ≥ 3.8, NumPy.
pip install .
Or for development:
pip install -e .
Usage
import fast_loadtxt as fl
# Basic — just like numpy.loadtxt
data = fl.loadtxt("simulation_output.dat")
# CSV with header
data = fl.loadtxt("results.csv", skip_rows=1)
# Tune for your hardware
data = fl.loadtxt("huge_file.dat", chunk_size=2000, num_threads=8)
Parameters
filepath— Path to the data file (space/tab/comma delimited)comment— Comment character, default'#'skip_rows— Header rows to skip (after comments), default0chunk_size— Rows per OpenMP chunk, default500num_threads— Thread count, default0(auto)
Benchmarks
Run the benchmark suite:
python benchmarks/bench.py
How It Works (for contributors)
The code is split into four small, focused files:
-
file_mapper.h— POSIX mmap wrapper. Maps the file read-only, callsmadvisefor kernel readahead hints. RAII cleanup. -
line_scanner.h— Sequential byte scan. Counts data rows, detects columns, builds avector<size_t>of byte offsets for each data line. This is the only heap allocation beyond the output array. -
chunk_parser.h— OpenMP parallel loop. Each thread gets a range of row indices, looks up their byte offsets, parses withfast_float, writes directly into the pre-allocated numpy buffer. Zero allocations in the hot loop. -
fast_loadtxt.cpp— pybind11 glue. Calls the above three in sequence, returns the numpy array.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
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 fast_loadtxt-0.1.0.tar.gz.
File metadata
- Download URL: fast_loadtxt-0.1.0.tar.gz
- Upload date:
- Size: 57.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
080ebd2600ef41e87397ea5c87c66a231de3af25a730558a2c59e0dbb3592d7a
|
|
| MD5 |
89ce36a854bd8973710c3bb5cbdff5e0
|
|
| BLAKE2b-256 |
b6cf18946bf8dcb655b4696ccc1e1c69e795974c69756165652ff00e78abc2b3
|
File details
Details for the file fast_loadtxt-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fast_loadtxt-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 187.8 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b23cac33821c4c938aa50844f9eeb1ac430dd69c6d420276abb2c92b67f8b4b
|
|
| MD5 |
15488fec80fdc37e08178ee9a813b211
|
|
| BLAKE2b-256 |
3dfcfbbf3ff6878856b959fd82276b0cb5bd0ebc2cdf6d8cd35fe48cbdbed25c
|
File details
Details for the file fast_loadtxt-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: fast_loadtxt-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 82.0 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66198eec0412d0c2e2b2cc5421949882e6539211aaa8e7a69aeb137e31fe4d43
|
|
| MD5 |
0f45236d9e6072d56f6f7043377bd2b7
|
|
| BLAKE2b-256 |
804db32fad291e89133789b533717332d3f33ae4da6c25b6ecafff93ddffe0e7
|
File details
Details for the file fast_loadtxt-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fast_loadtxt-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 187.9 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f06ba099687e929ed6d7b2eb08fc2a5d4f6078ee8d3ee581ecedd3c87dc61e4
|
|
| MD5 |
ae8c6b9578949ce33bb24d5b80339595
|
|
| BLAKE2b-256 |
71aed45d2ab3b7e7e83f9a715bab1d36711b9f2ea4a6f918757463f98c9789f5
|
File details
Details for the file fast_loadtxt-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: fast_loadtxt-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 82.0 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
753a8a2d5daec43858acddb4cfb397497cb099f187984b8a224e3da1c705420d
|
|
| MD5 |
c00b7d8638cc6024f1a3afcf70e9dd5d
|
|
| BLAKE2b-256 |
91e53d9ba334e83135b21a82b7c72cce2763c5f90c218883bf2d45eaed96063e
|
File details
Details for the file fast_loadtxt-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fast_loadtxt-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 188.1 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5c8fbd17d9978cd45c3c30f1f252fbdb5d22e08daf2445545c3337f5fdcfa50
|
|
| MD5 |
5e06236dff49fd235d99312be16fa6ec
|
|
| BLAKE2b-256 |
b959cadb0d3bf8a424323c10d2d53f39ba592afa63392b6f7db62c74fbfeab86
|
File details
Details for the file fast_loadtxt-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: fast_loadtxt-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 80.6 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4936413eeece0531a63bf08ac1fcea159f79d5cb4e0dc9b6a795571a64b173df
|
|
| MD5 |
ef923d86b27be9030324152cf9abd85d
|
|
| BLAKE2b-256 |
1d055bf00d1b0789f8315f5cfa7b9ce22d1213035a2a9c115ba2045c77860ccf
|
File details
Details for the file fast_loadtxt-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fast_loadtxt-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 186.4 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6810c7a85a9149d13c973213b794fc6a4e0ba92cfb6a1dbc6f27057c2eb861b
|
|
| MD5 |
3d61de752f2184ed76dcd3e73778c596
|
|
| BLAKE2b-256 |
c4df923d3fc6f810f33ada44c9c518dfc0f4b4a9ffe567f3d5bb53c7538bb930
|
File details
Details for the file fast_loadtxt-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: fast_loadtxt-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 79.2 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52fff61e2945e0b9dcba896123476128e223d52b577a2163df2188088787a879
|
|
| MD5 |
828d7090e75bf1c93e9f7828b88ace51
|
|
| BLAKE2b-256 |
7a01ed6e59b86066db06773797b806f1fcac9dee9267b6018ba1d1c1c15ff5a2
|
File details
Details for the file fast_loadtxt-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fast_loadtxt-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 186.6 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce9fdcf6dec4c45945636fecbd6c0ffd636399e2882b9ae0fbc0eb37fbda4dd9
|
|
| MD5 |
e33299bb167dc553758ef60bd3a60bd5
|
|
| BLAKE2b-256 |
d5664c1076ee745d5b7913b5a39fa0be508df173bd597733b75276a179333674
|
File details
Details for the file fast_loadtxt-0.1.0-cp39-cp39-macosx_11_0_arm64.whl.
File metadata
- Download URL: fast_loadtxt-0.1.0-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 79.3 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bf1906d11f51703225d869db3465794463bda089e0a0a941e91158777a694f4
|
|
| MD5 |
6fb67d1400c179dc33f0ded977724709
|
|
| BLAKE2b-256 |
3f02a1f7799a5e1c83e9b15f0cb97e9f23e877538934f60fd197fbd183bb4523
|