Registry / data / file-read-backwards

file-read-backwards

JSON →
library3.2.0pypypi✓ verified 87d ago

file-read-backwards is a Python library (current version 3.2.0) providing a memory-efficient way to read text files line-by-line starting from the end of the file. It supports ASCII, Latin-1, and UTF-8 encodings, and handles various newline characters (\r, \r\n, \n). The library is actively maintained with a stable release cadence.

pip install file-read-backwards
INSTALL
IMPORT
SIG · FILE-READ-BACKWARD
F
file-read-backwards
datapythonv3.2.0
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FileReadBackwards
from file_read_backwards import FileReadBackwards

Demonstrates reading a file line by line from the end using the context manager and iterating over the lines.

import os from file_read_backwards import FileReadBackwards # Create a dummy file for demonstration file_path = "example_log.txt" with open(file_path, "w", encoding="utf-8") as f: f.write("Line 1\n") f.write("Line 2\n") f.write("Line 3\n") f.write("Line 4\n") print(f"Reading '{file_path}' backwards:") with FileReadBackwards(file_path, encoding="utf-8") as frb: for line in frb: print(line.strip()) # Clean up the dummy file os.remove(file_path)
Debug
Known issues
breakingIn version 2.0.0, the internal behavior of `FileReadBackwards` changed; it no longer creates multiple iterators. Additionally, the `readline()` method was introduced, which returns one line at a time with `os.linesep` as the trailing newline, potentially altering behavior for users migrating from 1.x versions.
fix
Review code that implicitly relied on old iterator behavior or the exact newline characters returned by `readline()` in 1.x. Explicitly strip newlines if strict control is needed (`line.strip()`).
affects: 2.0.0 and later
gotchaWhile the library supports `ascii`, `latin-1`, and `utf-8` encodings, incorrect specification of the `encoding` parameter or attempting to read files with inconsistent or unsupported encodings can lead to `UnicodeDecodeError` or unexpected output.
fix
Always specify the correct encoding for your file if it's known. If uncertain, `utf-8` is a common default, but verify file content for other encodings, especially `latin-1` or `cp1252` for legacy files.
affects: All versions
Errors
Common errors & fixes
ImportError: cannot import name 'FileReadBackwardsIterator'
This error occurs when attempting to import an internal, non-public class named `FileReadBackwardsIterator` directly. This class is not intended for public use and may have been refactored or not exposed at the top level of the package.
fix
The main class for backward file reading is `FileReadBackwards`. Use `from file_read_backwards import FileReadBackwards` instead.
MemoryError / Application hangs when trying to read large files in reverse.
Attempting to read large files into memory entirely (e.g., using `file.readlines()` and then reversing the list) consumes excessive RAM, leading to `MemoryError` or very slow processing, especially on systems with limited memory.
fix
Utilize `file-read-backwards` as intended for memory-efficient processing. It reads files in chunks from the end, avoiding loading the entire file into memory. Example: `with FileReadBackwards('large_file.txt') as frb: for line in frb: ...`
Upgrade
Version history
3.2.0latest on PyPI · released Apr 21, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources
file-read-backwards — pip install file-read-backwards · libregistry