autopage

0.6.0 · active · verified Sat Apr 11

Autopage is a Python library designed to automatically display terminal output from a program in a pager (like `less`) when the output is extensive, and behave normally otherwise. It ensures consistent, user-friendly console output, preserves colors, and correctly handles output redirection. The current version is 0.6.0, released on January 29, 2026. While there isn't a strict stated release cadence, releases tend to be infrequent, occurring roughly every 6-18 months.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `autopage.AutoPager` as a context manager to pipe extensive console output through a system pager (like `less`). It generates a large amount of text, first printing it directly to `stdout` and then routing it through `AutoPager` to show the difference. For `autopage` to function, a pager (e.g., `less`) must be installed and accessible in the system's PATH.

import sys
import autopage

# Function to generate lines of text
def generate_lines(num_lines):
    for i in range(1, num_lines + 1):
        yield f"This is line {i} of the generated output. " * 5 + "\n"

if __name__ == "__main__":
    print("--- Output without autopage (might scroll rapidly) ---")
    for line in generate_lines(20): # Generate a few lines
        sys.stdout.write(line)
    print("--- End without autopage ---\n")

    print("--- Output with autopage (will use a pager like 'less' if output exceeds screen) ---")
    try:
        with autopage.AutoPager() as out:
            for line in generate_lines(100): # Generate many lines to trigger the pager
                out.write(line)
    except Exception as e:
        print(f"An error occurred with autopage: {e}")
        print("Ensure a pager like 'less' is installed and available in your PATH.")
    print("--- End with autopage ---\n")

view raw JSON →