File Read Backwards

3.2.0 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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)

view raw JSON →