Skip to main content

Random Access File Reader

This is a small library that allows for reading any given line in a file without having to read all the lines before it or load the entire file into memory. Only the line indexes and lengths are held in memory, which enables random access even on very large files for a very minuscule memory cost.

Installation

pip install random-access-file-reader

Usage

Usage is very straightforward, and standard csv line endings (newline character), value delimiter (comma), and quotation character (double quote) are the defaults. These can be changed in the constructor.

The get_line() and get_line_dicts() methods return a list of rows.
Plain text file example:
from randomAccessReader import RandomAccessReader

reader = RandomAccessReader('~/myfile.txt')

# single line
line = reader.get_lines(2)[0]
print line

# multiple lines
lines = reader.get_lines(3, 3)
for l in lines:
    print l
Optional arguments in the constructor: - endline_character - self-explanatory (default is endline character \\n) - ignore_blank_lines - if set to True, blank lines in the file will not be read or indexed (default is False)

Csv example:
from randomAccessReader import CsvRandomAccessReader
reader = CsvRandomAccessReader('~/myfile.csv')

# single line
line = reader.get_line_dicts(5)[0]
for x in line:
    print x + " = " line[x]

# multiple lines
lines = reader.get_line_dicts(6, 6)
for l in lines:
    for x in l:
        print x + " = " l[x]
Optional arguments in the constructor: - endline_character - self-explanatory (default is endline character \\n) - ignore_blank_lines - if set to True, blank lines in the file will not be read or indexed (default is True) - values_delimiter - character used by the csv to separate values within a line (default is ,) - quotechar - character used by the csv to surround values that contain the value delimiting character (default is ") - ignore_corrupt - if set to True, lines with an invalid length will return blank instead of raising an exception (default is False)

Metadata

Release files for random-access-file-reader 0.3.0

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

Built distribution (wheel)

Table of built distributions (wheels) for random-access-file-reader 0.3.0
File Interpreter ABI Platform
random_access_file_reader-0.3.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Release files / random_access_file_reader-0.3.0-py2.py3-none-any.whl

Download URL random_access_file_reader-0.3.0-py2.py3-none-any.whl
Size 5.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
16306cafc19777a315ee6aa76c4979436841ad9afd79574100e7db44215eba5b
BLAKE2b-256 checksum
How to use checksums
0d2771531b7eb10e3dabd1dd3830faebdb75a22213b90b9dd6e2140e68b8453e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.3.0 This release

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

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