prettytable

ASCII table formatting for Python — generates formatted table output for terminal display and text reports. prettytable features: PrettyTable() for table creation, add_row()/add_rows() for data, field_names for column headers, get_string() for ASCII output, get_html_string() for HTML tables, get_json_string() for JSON, get_csv_string() for CSV, sortby/reversesort for ordering, border/header/hrules for styling, align for column alignment (l/r/c), max_width for column truncation, start/end for pagination, and from_csv()/from_json()/from_db_cursor() for data import.

Evaluated Mar 06, 2026 (0d ago) v3.x
Homepage ↗ Repo ↗ Developer Tools python prettytable table ascii terminal formatting cli tabular
⚙ Agent Friendliness
67
/ 100
Can an agent use this?
🔒 Security
91
/ 100
Is it safe for agents?
⚡ Reliability
86
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
85
Error Messages
82
Auth Simplicity
99
Rate Limits
99

🔒 Security

TLS Enforcement
92
Auth Strength
92
Scope Granularity
90
Dep. Hygiene
92
Secret Handling
90

Table formatting library with no network calls. HTML output from get_html_string() is not XSS-safe if cell values contain user-controlled data — always HTML-escape values before adding to table for web output. ASCII output is always safe for terminal display.

⚡ Reliability

Uptime/SLA
85
Version Stability
88
Breaking Changes
85
Error Recovery
85
AF Security Reliability

Best When

Generating formatted ASCII or HTML tables for CLI output and text reports — prettytable's simple API converts lists of data to aligned tables with minimal code.

Avoid When

Large datasets (memory), real-time updates (use rich.live), or Pandas DataFrames (use df.to_string()).

Use Cases

  • Agent status report — from prettytable import PrettyTable; t = PrettyTable(['Agent', 'Status', 'Tasks', 'Uptime']); t.add_row(['agent-1', 'running', 42, '2h 15m']); t.add_row(['agent-2', 'idle', 0, '5h 3m']); print(t) — formatted table; agent status dashboard in terminal; add_rows() for bulk data insertion
  • Agent leaderboard — t = PrettyTable(['Rank', 'Model', 'Score', 'Latency']); t.sortby = 'Score'; t.reversesort = True; for i, row in enumerate(results): t.add_row([i+1, row.model, f'{row.score:.3f}', f'{row.latency}ms']) — sorted table; agent benchmark comparison sorted by score; terminal leaderboard display
  • Agent database query display — from prettytable import from_db_cursor; cursor.execute('SELECT * FROM tasks LIMIT 20'); t = from_db_cursor(cursor); print(t) — direct from cursor; agent displays query results as formatted table; column names from cursor.description
  • Agent HTML report — t = PrettyTable(['Event', 'Time', 'Details']); for event in events: t.add_row([event.type, event.time, event.summary]); html = t.get_html_string(attributes={'class': 'report-table'}); email.send(body=f'<html>{html}</html>') — HTML table for email; agent generates HTML report from data
  • Agent aligned columns — t = PrettyTable(['Name', 'Count', 'Percentage']); t.align['Name'] = 'l'; t.align['Count'] = 'r'; t.align['Percentage'] = 'r'; t.float_format = '0.1' — column alignment; agent metrics table with right-aligned numbers and left-aligned names; float_format controls decimal display

Not For

  • Large datasets — prettytable loads all data in memory; for large tabular data use rich.table with pagination or click's style functions
  • Real-time streaming tables — prettytable generates complete static tables; for live-updating tables use rich.live or urwid
  • Pandas DataFrames — for DataFrame display use df.to_string() or rich's DataFrame support

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

No auth — local table formatting library.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

prettytable is BSD licensed. Free for all use.

Agent Metadata

Pagination
offset
Idempotent
Full
Retry Guidance
Not documented

Known Gotchas

  • field_names must be set before adding rows — PrettyTable() without args, then t.field_names = ['A', 'B']; or PrettyTable(['A', 'B']) at creation; calling add_row() before field_names raises Exception: set field names first; agent code building tables dynamically must set field_names from first row
  • add_row() requires exact column count — t = PrettyTable(['A', 'B', 'C']); t.add_row([1, 2]) raises Exception for wrong column count; agent code building rows from dynamic data must pad or truncate to match column count; zip() with field_names to ensure alignment
  • sort is on string representation by default — t.sortby = 'Count' sorts column as strings unless field data is numeric; '10' < '9' in string sort; agent code sorting numeric columns must ensure values are actual ints/floats not strings: add_row([agent, 42, ...]) not add_row([agent, '42', ...])
  • max_width truncates with ellipsis — t.max_width = 30 truncates long strings; truncated strings show '...' at end; agent code with long descriptions in tables must balance readability vs truncation; use max_table_width for total width limit instead of per-column
  • get_html_string() generates unsafe HTML — table cell content is not HTML-escaped by default; if cell values contain HTML characters (<, >, &), output is malformed HTML; agent code using get_html_string() for web output must sanitize input values before add_row(): html.escape(str(value))
  • from_db_cursor() consumes cursor — from_db_cursor(cursor) fetches all rows and creates table; subsequent cursor iteration returns empty; agent code needs result data for other processing must fetch first: rows = cursor.fetchall(); t = PrettyTable(cursor.description); t.add_rows(rows)

Alternatives

Full Evaluation Report

Comprehensive deep-dive: security analysis, reliability audit, agent experience review, cost modeling, competitive positioning, and improvement roadmap for prettytable.

AI-powered analysis · PDF + markdown · Delivered within 30 minutes

$99

Package Brief

Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.

Delivered within 10 minutes

$3

Score Monitoring

Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.

Continuous monitoring

$3/mo

Scores are editorial opinions as of 2026-03-06.

5229
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered