HOWTO · Python
How to Print Bold Text in Python
Learn how to print bold text in a Python terminal with ANSI sequences or styling libraries.
On this page
To print bold text in a Python terminal, wrap it in ANSI escape sequences or use a styling library such as termcolor, colorama, simple_colors, or click. These approaches style terminal output; use Markdown or HTML for bold text in a document or web page. The examples below target terminal text, whose appearance depends on ANSI support.
Use the ANSI Escape Sequence Method to Print Bold Text in Python
ANSI escape sequences can change text formatting in a compatible terminal without a Python dependency. The sequence \033[1m starts bold styling and \033[0m restores the normal style. A reusable class keeps those sequences together:
class BoldText:
BOLD = "\033[1m"
RESET = "\033[0m"
print(f"{BoldText.BOLD}Python Programming!{BoldText.RESET}")
[1mPython Programming![0m
Reset after the styled text so the terminal does not carry the formatting into later output. The escape sequences are interpreted only by terminals that support ANSI styling.
Use a Class to Print Bold Text in Python
The BoldText class above exposes BOLD and RESET constants, so the same formatting can be reused in other print calls. Keep the reset sequence at the end of each styled segment. This class only sends ANSI control sequences; it does not detect whether the destination can render them.
Use the termcolor Module to Print Bold Text in Python
termcolor is a package for styling terminal text, and colored() is its formatting function. Install it with python -m pip install termcolor; then call colored("Python", "green", attrs=["bold"]) and print the returned string. The package is not available in this workflow’s Python runtime, so this call is shown inline rather than as an executable example.
To try the same terminal effect in the supplied runtime, use this self-contained ANSI alternative. It does not call termcolor; the package-specific call above is illustrative and requires installing the package in your own environment.
class BoldText:
BOLD = "\033[1m"
RESET = "\033[0m"
print(f"{BoldText.BOLD}Python Programming!{BoldText.RESET}")
[1mPython Programming![0m
Use the colorama Package to Print Bold Text in Python
colorama helps applications use ANSI styling across terminals, including improving ANSI handling on Windows. Install it with python -m pip install colorama, call init(), then print f"{Style.BRIGHT}Bold Text{Style.RESET_ALL}" after importing Style and init from colorama. Style.BRIGHT applies emphasis and Style.RESET_ALL restores the default style. This package is not available in the configured Python runtime, so its usage is described inline and is not an executable example. Initialization does not guarantee that every console or output destination will display bold text.
The following runtime-ready alternative sends the equivalent ANSI styling directly. It does not exercise colorama; use the package calls above after installing the package to test its platform handling.
class BoldText:
BOLD = "\033[1m"
RESET = "\033[0m"
print(f"{BoldText.BOLD}Python Programming!{BoldText.RESET}")
[1mPython Programming![0m
Use the simple-color Package to Print Bold Text in Python
The distribution is installed as simple-colors and imported as simple_colors. Install it with python -m pip install simple-colors, then use green("Python", "bold") from simple_colors. This workflow’s Python runtime does not include the package, so the call is provided inline and has not been run here. Its styling also depends on terminal support.
Here is a runnable standard-library alternative for the same bold terminal text. The simple_colors call above is illustrative and requires installing simple-colors to run.
class BoldText:
BOLD = "\033[1m"
RESET = "\033[0m"
print(f"{BoldText.BOLD}Python Programming!{BoldText.RESET}")
[1mPython Programming![0m
Use the click Library to Print Bold Text in Python
For a command-line application that already uses click, install it with python -m pip install click. click.echo(click.style("Bold Text", bold=True)) formats a string and writes it to the terminal. The configured Python runtime does not include click, so this usage is shown inline rather than as an executable example. As with the other library options, the output environment determines whether the style is visible.
This standalone alternative uses ANSI directly, so it is runnable without click. The click.style() and click.echo() calls above are illustrative and become runnable after installing click.
class BoldText:
BOLD = "\033[1m"
RESET = "\033[0m"
print(f"{BoldText.BOLD}Python Programming!{BoldText.RESET}")
[1mPython Programming![0m
Conclusion
Use ANSI sequences directly for a dependency-free solution, or keep them in a small class when you want reusable constants. The termcolor, colorama, simple_colors, and click libraries provide higher-level helpers. ANSI styling may appear as plain text in terminals that do not interpret it, so choose based on your target environment.