Python CLI Todo App

Python 15 min min read Updated: Mar 09, 2026 Intermediate
Python CLI Todo App
Intermediate Topic 1 of 5

Building a CLI Todo App in Python

A CLI (Command Line Interface) Todo application is a simple project that allows users to manage their tasks directly from the terminal. It helps developers practice important Python concepts such as file handling, user input, loops, and basic data structures.

Building a Todo application using Python is an excellent beginner-friendly project that demonstrates how to create interactive command-line programs.

What is a CLI Application?

A CLI application is a program that runs in the terminal or command prompt and interacts with the user through text commands instead of graphical interfaces.

Examples of CLI tools include:

  • Git
  • Docker
  • NPM
  • Python package manager (pip)

Features of a CLI Todo App

A basic Todo CLI application usually includes the following features:

  • Add new tasks
  • View existing tasks
  • Mark tasks as completed
  • Delete tasks
  • Save tasks in a file

Basic Todo App Example

The following Python program implements a simple CLI Todo application.

python tasks = [] while True: print("\nTodo Menu") print("1. View Tasks") print("2. Add Task") print("3. Remove Task") print("4. Exit") choice = input("Enter choice: ") if choice == "1": if not tasks: print("No tasks available") else: for i, task in enumerate(tasks, start=1): print(f"{i}. {task}") elif choice == "2": task = input("Enter new task: ") tasks.append(task) print("Task added successfully") elif choice == "3": task_num = int(input("Enter task number to remove: ")) if 0 < task_num <= len(tasks): tasks.pop(task_num - 1) print("Task removed") else: print("Invalid task number") elif choice == "4": print("Exiting application") break else: print("Invalid option")

Saving Tasks to a File

To persist tasks between program runs, tasks can be stored in a file.

python with open("tasks.txt", "w") as file: for task in tasks: file.write(task + "\n")

This saves all tasks into a text file.

Loading Tasks from a File

Tasks can be loaded when the application starts.

python try: with open("tasks.txt", "r") as file: tasks = file.read().splitlines() except FileNotFoundError: tasks = []

This allows the application to retain tasks even after restarting.

Improving the CLI App

The Todo application can be improved by adding features such as:

  • Task priorities
  • Due dates
  • Search functionality
  • Task completion status
  • JSON or database storage

Using argparse for CLI Commands

Advanced CLI tools often use the argparse module to handle command-line arguments.

python import argparse parser = argparse.ArgumentParser() parser.add_argument("task", help="Task description") args = parser.parse_args() print("Task added:", args.task)

This allows users to run commands like:

bash python todo.py "Buy groceries"

Project Structure

todo_app/
│
├── todo.py
├── tasks.txt
└── requirements.txt

This simple structure keeps the application organized.

Real-World CLI Tools Built with Python

Many popular developer tools are built using Python CLI frameworks.

  • AWS CLI
  • Youtube-dl
  • Ansible
  • Cookiecutter

Best Practices

  • Use clear command-line prompts
  • Validate user input
  • Store data persistently
  • Use modules like argparse or click

Conclusion

A CLI Todo application is a simple but practical Python project that demonstrates how to build interactive command-line programs. It helps developers understand user input handling, file storage, and basic program structure.

By enhancing the application with additional features, developers can build powerful CLI tools similar to those used in real-world development environments.

In the next tutorial, we will explore Web Scraper Project in Python and learn how to collect data from websites using Python.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators