My Project 2: Building a Simple Memo App with Python + Streamlit
Source: Dev.to
Project Overview
The memo app lets you:
- Add a new memo
- Store it in a
memos.jsonfile - View all saved memos
It can be used either from the console or through a Streamlit web UI, demonstrating file handling, JSON storage, and UI transformation.
Project Structure
memo_app/
│
├── memo_app.py # Console version
├── memo_app_streamlit.py # Streamlit version
└── memos.json # Memo storage file
Console Version (memo_app.py)
Code
import json
import os
from datetime import datetime
now = datetime.now().strftime("%Y-%m-%d")
FILE_NAME = "memos.json"
# Ensure the storage file exists
if not os.path.exists(FILE_NAME):
with open(FILE_NAME, "w") as f:
json.dump([], f)
def load_memos():
with open(FILE_NAME, "r") as f:
return json.load(f)
def save_memos(memos):
with open(FILE_NAME, "w") as f:
json.dump(memos, f, indent=2)
print("=== Sabin's Memo App ===")
print("1) Add Memo")
print("2) Show Memos")
choice = input("Select option: ")
if choice == "1":
memo = input("Write memo: ")
memos = load_memos()
memos.append({"text": memo, "date": now})
save_memos(memos)
print("Memo saved!")
elif choice == "2":
memos = load_memos()
print("=== Memo List ===")
for i, m in enumerate(memos, start=1):
print(f"{i}. {m['text']} ({m['date']})")
else:
print("Invalid option.")
Streamlit Version (memo_app_streamlit.py)
Code
import streamlit as st
import json
import os
from datetime import datetime
FILE_NAME = "memos.json"
# Ensure the storage file exists
if not os.path.exists(FILE_NAME):
with open(FILE_NAME, "w") as f:
json.dump([], f)
def load_memos():
with open(FILE_NAME, "r") as f:
return json.load(f)
def save_memos(memos):
with open(FILE_NAME, "w") as f:
json.dump(memos, f, indent=2)
st.title("📝 Sabin's Memo App (Streamlit Version)")
menu = st.radio("Select an option:", ["Add Memo", "Show Memos"])
if menu == "Add Memo":
text = st.text_input("Write your memo:")
if st.button("Save Memo"):
if text.strip() == "":
st.warning("Memo cannot be empty.")
else:
now = datetime.now().strftime("%Y-%m-%d")
memos = load_memos()
memos.append({"text": text, "date": now})
save_memos(memos)
st.success("Memo saved!")
elif menu == "Show Memos":
memos = load_memos()
if not memos:
st.info("No memos yet.")
else:
st.subheader("📄 Memo List")
for i, memo in enumerate(memos, start=1):
st.write(f"**{i}. {memo['text']}** ({memo['date']})")
How to Run
Console Version
python3 memo_app.py
Streamlit Version
pip install streamlit
streamlit run memo_app_streamlit.py
The Streamlit command will launch the web UI in your default browser.
What I Learned
- Storing data with JSON files
- Safe read/write of local storage
- Adding a UI layer using Streamlit
- Converting a CLI tool into a web app
- The value of small, focused projects for building solid foundations
Future Improvements
- Add memo deletion
- Add memo editing
- Switch storage to SQLite
- Implement search/filter functionality
- Provide a dark/light mode toggle in Streamlit