{"id":678,"library":"prettytable","title":"PrettyTable","description":"PrettyTable is a Python library for easily displaying tabular data in a visually appealing ASCII table format. It supports various output formats including ASCII, HTML, CSV, JSON, LaTeX, and MediaWiki. The library is actively maintained with regular releases, currently at version 3.17.0.","status":"active","version":"3.17.0","language":"python","source_language":"en","source_url":"https://github.com/prettytable/prettytable","tags":["table","ascii-table","display","cli","formatting","html","csv","json"],"install":[{"cmd":"pip install prettytable","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used for correct width calculation of wide characters in ASCII tables.","package":"wcwidth","optional":false}],"imports":[{"symbol":"PrettyTable","correct":"from prettytable import PrettyTable"},{"note":"Use ColorTable for ANSI color support.","symbol":"ColorTable","correct":"from prettytable.colortable import ColorTable"},{"note":"Also HRuleStyle, VRuleStyle for granular styling enums.","symbol":"TableStyle","correct":"from prettytable import TableStyle"}],"quickstart":{"code":"from prettytable import PrettyTable\n\ntable = PrettyTable()\ntable.field_names = [\"City name\", \"Area\", \"Population\"]\ntable.add_row([\"Adelaide\", 1295, 1158259])\ntable.add_row([\"Brisbane\", 5905, 1857594])\ntable.add_row([\"Sydney\", 2058, 4336374])\n\nprint(table)\n\n# Example with alignment and style\ntable.align[\"City name\"] = \"l\"\ntable.align[\"Population\"] = \"r\"\n\n# To use custom styles, import TableStyle\nfrom prettytable import TableStyle\ntable.set_style(TableStyle.MARKDOWN)\nprint(table)","lang":"python","description":"Initialize a PrettyTable, define column headers using `field_names`, add data row by row with `add_row`, and then print the table. Customization for alignment and built-in styles is also demonstrated."},"warnings":[{"fix":"Upgrade Python to 3.10+ or pin `prettytable<3.17.0`.","message":"PrettyTable 3.17.0 dropped support for Python 3.9. Users on Python 3.9 or older should use an earlier version of PrettyTable (e.g., 3.16.0 or below) or upgrade their Python interpreter.","severity":"breaking","affected_versions":">=3.17.0"},{"fix":"Replace `prettytable.FRAME` with `HRuleStyle.FRAME` or `TableStyle.DEFAULT` etc. as appropriate.","message":"The direct constants `hrule` and `tableStyle` were deprecated in version 3.12.0. Use the corresponding enum values from `HRuleStyle`, `VRuleStyle`, and `TableStyle` instead for clarity and type safety.","severity":"deprecated","affected_versions":">=3.12.0"},{"fix":"Ensure `pip install prettytable` is run in the *same* Python environment where your script is executed. Verify the active Python interpreter in your IDE.","message":"`ModuleNotFoundError: No module named 'prettytable'` is a common issue, often caused by installing `prettytable` in a different Python environment (e.g., virtual environment) than the one your IDE or script is using.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to `prettytable>=3.15.1` or ensure the list passed to `add_rows()` is not empty before calling.","message":"Prior to 3.15.1, `add_rows()` could raise an `IndexError` if provided with an empty list that was not handled gracefully.","severity":"gotcha","affected_versions":"<3.15.1"},{"fix":"Upgrade to `prettytable>=3.14.0` or set `sortby` explicitly on the table instance (`table.sortby = \"Column\"`) after initialization or when calling `get_string()`.","message":"In versions prior to 3.14.0, specifying `sortby` directly at class declaration might not have been correctly applied, requiring it to be set after instantiation or via `get_string()` arguments.","severity":"gotcha","affected_versions":"<3.14.0"}],"env_vars":null,"last_verified":"2026-05-12T17:45:17.882Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"pip install prettytable","cause":"The 'prettytable' package is not installed in the Python environment where the script is being executed.","error":"ModuleNotFoundError: No module named 'prettytable'"},{"fix":"Rename your local file from 'prettytable.py' to something else (e.g., 'my_table_script.py') and delete any associated '.pyc' files.","cause":"A local Python file named 'prettytable.py' exists in the same directory as your script, shadowing the installed 'prettytable' library and preventing the correct module from being imported.","error":"AttributeError: 'module' object has no attribute 'PrettyTable'"},{"fix":"Pass a list or tuple of values to 'add_row()', for example: `table.add_row([value1, value2, value3])`.","cause":"The 'add_row()' method expects a single iterable (like a list or tuple) containing all the values for the row as its argument, but individual values are being passed as separate arguments.","error":"TypeError: PrettyTable.add_row() takes 2 positional arguments but X were given"},{"fix":"Instead of `table.set_field_names(['Header 1', 'Header 2'])`, use `table.field_names = ['Header 1', 'Header 2']`.","cause":"The 'set_field_names()' method was deprecated and removed in PrettyTable version 0.6. Field names are now set directly via the 'field_names' attribute.","error":"AttributeError: 'module' object has no attribute 'set_field_names'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"3.17.0","install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":1.4,"disk_size":"18.7M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.4,"disk_size":"18.6M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.6,"import_time_s":0.07,"mem_mb":1.4,"disk_size":"19M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.08,"mem_mb":1.4,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":1.6,"disk_size":"20.6M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.08,"mem_mb":1.6,"disk_size":"20.5M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.7,"import_time_s":0.08,"mem_mb":1.6,"disk_size":"21M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":1.6,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.3,"disk_size":"12.5M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":1.3,"disk_size":"12.3M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.6,"import_time_s":0.06,"mem_mb":1.3,"disk_size":"13M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":1.3,"disk_size":"13M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.3,"disk_size":"12.2M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.3,"disk_size":"12.0M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.6,"import_time_s":0.05,"mem_mb":1.1,"disk_size":"13M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.1,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.4,"disk_size":"18.2M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.4,"disk_size":"18.1M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.9,"import_time_s":0.02,"mem_mb":1.4,"disk_size":"19M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.4,"disk_size":"19M"}]},"quickstart_checks":{"last_tested":"2026-04-24","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}