내 프로젝트 2: Python + Streamlit으로 간단한 메모 앱 만들기

발행: (2025년 11월 30일 오전 06:57 GMT+9)
3 min read
원문: Dev.to

Source: Dev.to

프로젝트 개요

메모 앱을 사용하면 다음을 할 수 있습니다:

  • 새로운 메모 추가
  • memos.json 파일에 저장
  • 저장된 모든 메모 보기

콘솔에서 직접 사용하거나 Streamlit 웹 UI를 통해 사용할 수 있으며, 파일 처리, JSON 저장, UI 변환을 시연합니다.

프로젝트 구조

memo_app/

├── memo_app.py               # 콘솔 버전
├── memo_app_streamlit.py     # Streamlit 버전
└── memos.json                # 메모 저장 파일

콘솔 버전 (memo_app.py)

코드

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 버전 (memo_app_streamlit.py)

코드

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']})")

실행 방법

콘솔 버전

python3 memo_app.py

Streamlit 버전

pip install streamlit
streamlit run memo_app_streamlit.py

Streamlit 명령을 실행하면 기본 브라우저에서 웹 UI가 열립니다.

배운 점

  • JSON 파일을 이용한 데이터 저장
  • 로컬 스토리지의 안전한 읽기/쓰기
  • Streamlit을 활용한 UI 레이어 추가
  • CLI 도구를 웹 앱으로 변환
  • 탄탄한 기초를 다지는 작은 집중 프로젝트의 가치

향후 개선 사항

  • 메모 삭제 기능 추가
  • 메모 편집 기능 추가
  • 저장소를 SQLite로 전환
  • 검색/필터 기능 구현
  • Streamlit에서 다크/라이트 모드 토글 제공
Back to Blog

관련 글

더 보기 »

Anaconda 코드에서 IP2Location.io API 사용 방법

Intro Anaconda Code는 Excel 애드인으로, Excel 내에서 직접 Python 또는 R 코드를 실행할 수 있게 해줍니다. 이를 통해 사용자 정의 Python 함수를 만들어 워크시트에서 사용할 수 있습니다.

Python에서 QR 코드를 생성하는 방법

초보자도 쉽게 따라 할 수 있는 Python ‘qrcode’ 패키지 탐구 튜토리얼 ‘How to Generate QR Codes in Python’ 포스트가 처음으로 Towards Data Science에 게재되었습니다....