What you will build and what you need

This project is a small command-line inventory for devices on a home network. You can add a device, list saved devices, or search for one by name. The information stays in a CSV file on your computer; the program does not scan your network or connect to any device. That makes it a manageable way to practice loops, functions, file handling, and user input.

You need Python 3.10 or later and a text editor. The example uses only Python’s standard library, so there are no packages to install. Create a folder for the project and save the program below as inventory.py. Run it from that folder with python inventory.py, or python3 inventory.py if that is how Python is named on your system. The program will create devices.csv in the same folder when you add your first entry.

Choose useful fields without collecting secrets

Each record has three fields: name, type, and location. A name might be “Desk laptop,” the type might be “Computer,” and the location might be “Study.” These descriptions are enough to distinguish many household devices without recording login details, passwords, or router settings. If you are unsure how to describe devices in your own setup, Home Networks · IFDR Tech Explained is a place to browse related home-network topics.

CSV is a convenient format here because a row represents one device and common spreadsheet programs can open the file. It is not a database: this simple version has no duplicate detection, editing command, or protection against two copies of the program writing at once. Keep one copy of the program running, and treat the file as a small personal list rather than a definitive map of your network.

Write the inventory program

Copy the following plain-text Python into inventory.py. The write function adds a header only when the file does not yet exist. The read function returns an empty list before the first entry is saved, so listing and searching also work on a new installation.

import csv from pathlib import Path FILE = Path(__file__).with_name("devices.csv") FIELDS = ["name", "type", "location"] def read_devices(): if not FILE.exists(): return [] with FILE.open("r", newline="", encoding="utf-8") as stream: return list(csv.DictReader(stream)) def add_device(): device = {} for field in FIELDS: value = input(f"{field.title()}: ").strip() if not value: print("All fields are required; nothing was saved.") return device[field] = value new_file = not FILE.exists() with FILE.open("a", newline="", encoding="utf-8") as stream: writer = csv.DictWriter(stream, fieldnames=FIELDS) if new_file: writer.writeheader() writer.writerow(device) print("Device saved.") def show_devices(devices): if not devices: print("No matching devices.") for device in devices: print(f"{device['name']} | {device['type']} | {device['location']}") while True: choice = input("Add, list, search, or quit? ").strip().lower() if choice == "add": add_device() elif choice == "list": show_devices(read_devices()) elif choice == "search": term = input("Name contains: ").strip().casefold() matches = [d for d in read_devices() if term in d["name"].casefold()] show_devices(matches) elif choice == "quit": break else: print("Choose add, list, search, or quit.")

The csv module handles commas and quotation marks inside field values, so a location such as “Kitchen, upstairs” remains one field. The search compares names without case sensitivity. It does not search types or locations; limiting the first version to one searchable field keeps its behavior easy to understand.

Run a few checks

Start the program and choose list before adding anything. You should see “No matching devices.” Next, choose add and enter “Desk laptop,” “Computer,” and “Study” at the three prompts. Choose list to see that entry, then search for “LAPTOP” to check that matching ignores case. Quit, start the program again, and list the devices once more: the saved entry should still appear.

Try an empty name next. The program should say that nothing was saved, and the existing entries should remain unchanged. For a separate CSV check, add a device whose location contains a comma, quit, and inspect devices.csv in a text editor. You may see quotation marks around that location; they are part of valid CSV formatting. Avoid editing the file while the program is running.

Keep the list modest and extend it carefully

An inventory can be useful without becoming a store of sensitive information. Leave out passwords, recovery codes, and private notes you would not want someone else using the computer to read. A local CSV file is not encrypted. For broader background on everyday security habits, browse Cybersecurity Basics · IFDR Tech Explained; for other approachable technology topics, explore IFDR Tech Explained. Neither destination is needed to run this project.

As a next exercise, add a search option for device type or a confirmation prompt before saving. If you add an edit or delete command, consider writing the revised rows to a temporary file before replacing the original, and keep a backup while testing. Those changes introduce new questions about mistakes and data loss, making them useful follow-up projects once the basic add, list, and search flow feels familiar.

Back to category ↗