DEV Community

Cover image for Build a Simple CLI Task Manager in Python 🚀!!
Nishkarsh Pandey
Nishkarsh Pandey

Posted on

3 2 2 2 2

Build a Simple CLI Task Manager in Python 🚀!!

Managing your daily tasks right from the terminal is super handy. Today, I’ll show you how to build a simple Command Line Interface (CLI) Task Manager in Python — no fancy UI, just pure productivity!

Why Build a CLI Task Manager?
Quick to use from your terminal or SSH session.
Lightweight, no distractions.
Perfect for learning Python scripting and file handling.
Easily extendable as you grow your skills.

Features We’ll Build:

Add new tasks.
View all tasks.
Mark tasks as completed.
Delete tasks.
Save tasks persistently in a file (tasks.txt).

The Code:

import os
TASKS_FILE = "tasks.txt"
def load_tasks():
    if not os.path.exists(TASKS_FILE):
        return []
    with open(TASKS_FILE, "r") as f:
        tasks = [line.strip() for line in f.readlines()]
    return tasks

def save_tasks(tasks):
    with open(TASKS_FILE, "w") as f:
        for task in tasks:
            f.write(task + "\n")

def show_tasks(tasks):
    if not tasks:
        print("No tasks found. Time to chill! 😎")
    else:
        for idx, task in enumerate(tasks, 1):
            status = "[x]" if task.startswith("[x]") else "[ ]"
            task_text = task[3:] if task.startswith("[x]") or task.startswith("[ ]") else task
            print(f"{idx}. {status} {task_text}")

def add_task(tasks):
    task = input("Enter your new task: ").strip()
    if task:
        tasks.append("[ ] " + task)
        print(f'Added task: "{task}"')
    else:
        print("Task cannot be empty!")

def complete_task(tasks):
    show_tasks(tasks)
    try:
        num = int(input("Enter the task number to mark as complete: "))
        if 1 <= num <= len(tasks):
            tasks[num-1] = "[x] " + tasks[num-1][3:]
            print("Task marked as complete!")
        else:
            print("Invalid task number.")
    except ValueError:
        print("Please enter a valid number.")

def delete_task(tasks):
    show_tasks(tasks)
    try:
        num = int(input("Enter the task number to delete: "))
        if 1 <= num <= len(tasks):
            removed = tasks.pop(num-1)
            print(f'Removed task: "{removed[3:]}"')
        else:
            print("Invalid task number.")
    except ValueError:
        print("Please enter a valid number.")

def main():
    tasks = load_tasks()
    while True:
        print("\n--- CLI Task Manager ---")
        print("1. Show Tasks")
        print("2. Add Task")
        print("3. Complete Task")
        print("4. Delete Task")
        print("5. Exit")
        choice = input("Choose an option: ")

        if choice == "1":
            show_tasks(tasks)
        elif choice == "2":
            add_task(tasks)
            save_tasks(tasks)
        elif choice == "3":
            complete_task(tasks)
            save_tasks(tasks)
        elif choice == "4":
            delete_task(tasks)
            save_tasks(tasks)
        elif choice == "5":
            print("Bye! Stay productive! 👋")
            break
        else:
            print("Invalid option, please try again.")

if __name__ == "__main__":
    main()

Enter fullscreen mode Exit fullscreen mode

Output:

Image description

How to Use
Save the script as task_manager.py
Run in terminal:

python task_manager.py
Enter fullscreen mode Exit fullscreen mode

Choose options by typing the number.
Your tasks will be saved in tasks.txt automatically.

What’s Next?

Add task deadlines and reminders.
Sort tasks by priority or date.
Sync tasks with Google Calendar or Todoist APIs.
Add colors using the termcolor or your own termstyle package!

Final Thoughts!!

Building a CLI Task Manager is a great beginner project that combines file handling, user input, and basic data management. Plus, it’s actually useful!

Feel free to fork and improve it on GitHub — and share your version in the comments!

Sonar image

Explore the coding personalities of leading LLMs

Understanding the unique coding "personality" of each LLM—where it excels and where it's likely to make mistakes—is key to generating code safely and securely. Check out this deep-dive study on GPT-4o, Claude, Llama, and more to see how you can use AI responsibly in your dev workflow.

Learn more

Top comments (0)

Developer-first embedded dashboards

Developer-first embedded dashboards

Embed in minutes, load in milliseconds, extend infinitely. Import any chart, connect to any database, embed anywhere. Scale elegantly, monitor effortlessly, CI/CD & version control.

Get early access

👋 Kindness is contagious

Discover fresh viewpoints in this insightful post, supported by our vibrant DEV Community. Every developer’s experience matters—add your thoughts and help us grow together.

A simple “thank you” can uplift the author and spark new discussions—leave yours below!

On DEV, knowledge-sharing connects us and drives innovation. Found this useful? A quick note of appreciation makes a real impact.

Okay