02-reusable-code-python โ Python ์ฌ์ฌ์ฉ ์ฝ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
ํ๋ก์ ํธ์ ๋ณต์ฌํ์ฌ ์ฌ์ฉํ๋ Python ์ฝ๋ ๋ถํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
๊ฐ์
๋ฐ์ดํฐ ๋ถ์, ๋ณด๊ณ ์ ์์ฑ, ์ค๋์ค ์ฒ๋ฆฌ, AI ๋ชจ๋ธ, API ํจํด ๋ฑ Python ํ๋ก์ ํธ์์ ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ์ฝ๋ ๋ถํ์ ๊ด๋ฆฌํฉ๋๋ค. 02-reusable-code/์ Python ๋ฒ์ ์ผ๋ก, ๋์ผํ 3๊ณ์ธต ๋ชจ๋ธ์ "๋ถํ" ๊ณ์ธต์ ์ํฉ๋๋ค.
3๊ณ์ธต ๋ชจ๋ธ์์์ ์์น
02-reusable-design โ "์ฌ๋ฃ" (์์, ํฐํธ, ์ ๋๋ฉ์ด์
์ ์)
โ ์ฐธ์กฐ
02-reusable-code โ "๋ถํ" โ
(TS/React)
02-reusable-code-python โ "๋ถํ" โ
(Python)
โ ์กฐํฉ
02-reusable-page โ "์์ฑํ" (Footer, Header, Hero)
| ๊ณ์ธต | ํ๋จ ๊ธฐ์ค | ์์ |
|---|---|---|
| design | ๊ฐ/์ค์ ์ธ๊ฐ? | --color-primary: #6366f1, @keyframes fadeIn |
| code / code-python | ๋์ํ๋ ์ฝ๋์ธ๊ฐ? | useDebounce(), excel_reader.py, whisper_engine.py |
| page | ํ๋ฉด์ ํ ์์ญ์ธ๊ฐ? | <Footer>, <HeroSection>, <Sidebar> |
Python์ ์ฃผ๋ก ๋ฐฑ์๋/๋ฐ์ดํฐ ์ฒ๋ฆฌ์ด๋ฏ๋ก designยทpage์ ์ง์ ์ฐ๊ฒฐ๋๋ ๊ฒฝ์ฐ๋ ๋๋ฌผ์ง๋ง, ๋์ผํ ์ถ์ถยท๊ด๋ฆฌ ์ฒด๊ณ(
/kdyextract,/kdypick)๋ฅผ ๊ณต์ ํฉ๋๋ค.
๊ตฌ์กฐ
02-reusable-code-python/
โโโ utils/
โ โโโ excel_reader.py โ ์์
ํ์ผ ์ฝ๊ธฐ/๋ถ์
โ โโโ pdf_reader.py โ PDF ํ
์คํธ/ํ
์ด๋ธ ์ถ์ถ
โ โโโ hwpx_generator.py โ HWPX ํ๊ธ ๋ฌธ์ ์์ฑ
โ โโโ audio_processor.py โ ์ค๋์ค ๋ณํ/๋ฌด์๊ฐ์ง/ํํ๊ณ์ฐ
โ โโโ device_detector.py โ GPU/CPU ๋๋ฐ์ด์ค ์๋ ๊ฐ์ง
โ โโโ sqlite_session.py โ SQLite ๋ฒ์ฉ ์ธ์
๊ด๋ฆฌ
โโโ api/
โ โโโ fastapi_auth.py โ FastAPI API Key ์ธ์ฆ ๋ฏธ๋ค์จ์ด
โ โโโ fastapi_dependencies.pyโ FastAPI DI (ํ์ด์ง๋ค์ด์
, ์ธ์ฆ, ์ค์ )
โ โโโ websocket_handler.py โ FastAPI WebSocket ์คํธ๋ฆฌ๋ฐ ํธ๋ค๋ฌ
โโโ ai/
โ โโโ whisper_engine.py โ faster-whisper STT ์์ง ๋ํผ
โโโ httpx_utils/
โ โโโ httpx_client.py โ AsyncClient + ์ฌ์๋ + ๋์์ฑ ์ ํ
โโโ models/
โ โโโ pydantic_patterns.py โ Pydantic v2 ๊ฒ์ฆ/์ค์ /์ง๋ ฌํ ํจํด
โโโ async/
โ โโโ asyncio_patterns.py โ TaskGroup, Semaphore, Queue, ์ฃผ๊ธฐ์ ํ์คํฌ
โ โโโ file_message_queue.py โ F-MES ํ์ผ ๊ธฐ๋ฐ ๋ฉ์์ง ๊ตํ ํ (QHDE ์ฐ๊ตฌ)
โ โโโ agent_lock.py โ Agent_Lock JSON ์ธ๋งํฌ์ด ํ๋กํ ์ฝ (QHDE ์ฐ๊ตฌ)
โ โโโ file_semaphore.py โ ํ์ผ ๊ธฐ๋ฐ ์นด์ดํ
์ธ๋งํฌ์ด (QHDE ์ฐ๊ตฌ)
โโโ structlog_utils/
โ โโโ structlog_setup.py โ structlog ์ค์ + ContextVars + JSON ํฌ๋งคํฐ
โโโ news/
โ โโโ __init__.py โ ํจํค์ง exports
โ โโโ models.py โ Pydantic ๋ชจ๋ธ (NewsItem, TrendSignal, AppOpportunity ๋ฑ)
โ โโโ collector.py โ ๋ฉํฐ์์ค ๋น๋๊ธฐ ๋ด์ค ์์ง๊ธฐ
โ โโโ analyzer.py โ ํธ๋ ๋ ์ถ์ถ + ๊ธฐํ ์ ์ ๋ถ์๊ธฐ
โ โโโ reporter.py โ ๋งํฌ๋ค์ด ๋ณด๊ณ ์ ์์ฑ๊ธฐ
โ โโโ sources/
โ โโโ base.py โ BaseNewsSource ํ๋กํ ์ฝ
โ โโโ hackernews.py โ HackerNews Firebase API ์ด๋ํฐ
โ โโโ reddit.py โ Reddit ๊ณต๊ฐ JSON API ์ด๋ํฐ
โ โโโ github_trending.py โ GitHub REST API ์ด๋ํฐ
โ โโโ google_news_rss.py โ Google News RSS ์ด๋ํฐ
โ โโโ producthunt.py โ ProductHunt ์น ๊ฒ์ ์ด๋ํฐ
โโโ pipelines/
โ โโโ __init__.py โ ํจํค์ง exports
โ โโโ types.py โ PipelineStage, StageStatus, OutputType ์ด๊ฑฐํ
โ โโโ models.py โ Pydantic v2 ๋ชจ๋ธ (SourceInput, StageResult, PipelineConfig, PipelineReport)
โ โโโ orchestrator.py โ 4๋จ๊ณ ํ์ดํ๋ผ์ธ ์์ง (IngestโSynthesizeโCreateโPublish)
โ โโโ recipes.py โ 5๊ฐ ์ฌ์ ์ ์ ๋ ์ํผ (research-to-article ๋ฑ)
โ โโโ hooks.py โ ์๋ช
์ฃผ๊ธฐ ํ
(Logging, Timing, Checkpoint)
โโโ testing/
โโโ pytest_patterns.py โ fixture, conftest, parametrize, mock ํจํด
ํธํ์ฑ
- Python: 3.10+ (ํ์
ํํธ
X | None๋ฌธ๋ฒ ์ฌ์ฉ) - ์ปจ๋ฒค์
:
docs/rules/reusable-code.md์ฐธ์กฐ
ํ์ ํจํค์ง
๊ธฐ๋ณธ (๋ฌธ์ ์ฒ๋ฆฌ)
pip install openpyxl pandas pdfplumber
์ค๋์ค ์ฒ๋ฆฌ
pip install numpy soundfile librosa
AI (์์ฑ์ธ์)
pip install faster-whisper
# GPU ์ฌ์ฉ ์: pip install torch (CUDA ๋ฒ์ )
API
pip install fastapi uvicorn
HTTP ํด๋ผ์ด์ธํธ
pip install httpx tenacity
๋ฐ์ดํฐ ๋ชจ๋ธ
pip install pydantic pydantic-settings
๊ตฌ์กฐํ ๋ก๊น
pip install structlog
๋ด์ค ์์ง/๋ถ์
pip install httpx pydantic feedparser
ํ ์คํ
pip install pytest pytest-asyncio httpx
๋ชจ๋๋ณ ์ฌ์ฉ ์์
์์ ์ฝ๊ธฐ
from utils.excel_reader import read_excel_file, analyze_excel_structure
df = read_excel_file("data.xlsx")
structure = analyze_excel_structure("data.xlsx")
PDF ํ ์คํธ ์ถ์ถ
from utils.pdf_reader import extract_text_from_pdf, extract_tables_from_pdf
text = extract_text_from_pdf("document.pdf")
tables = extract_tables_from_pdf("document.pdf")
HWPX ๋ฌธ์ ์์ฑ
from utils.hwpx_generator import generate_hwpx
generate_hwpx(
output_path="report.hwpx",
title="๋ณด๊ณ ์ ์ ๋ชฉ",
content="๋ณธ๋ฌธ ๋ด์ฉ",
tables=[...],
header_org="์กฐ์ง๋ช
"
)
์ค๋์ค ์ฒ๋ฆฌ
from utils.audio_processor import bytes_to_float32, detect_silence, compute_waveform
# ์ค๋์ค ํ์ผ โ float32 ๋ฐฐ์ด (16kHz ๋ชจ๋
ธ)
with open("audio.wav", "rb") as f:
audio = bytes_to_float32(f.read(), source_format="wav")
# ๋ฌด์ ๊ตฌ๊ฐ ๊ฐ์ง
silences = detect_silence(audio, threshold=0.01, min_silence_ms=500)
# ์๊ฐํ์ฉ ํํ ๋ฐ์ดํฐ
waveform = compute_waveform(audio, num_points=200)
GPU/CPU ๊ฐ์ง
from utils.device_detector import detect_device, get_device_info
device, compute_type = detect_device()
# โ ("cuda", "float16") ๋๋ ("cpu", "int8")
info = get_device_info()
# โ {"device": "cuda", "gpu_name": "RTX 4090", "vram_gb": 24.0, ...}
SQLite ์ธ์ ๊ด๋ฆฌ
from utils.sqlite_session import get_session_manager
manager = get_session_manager("./data/sessions.db")
# ํญ๋ชฉ ์ถ๊ฐ (์ธ์
์๋ ์์ฑ)
manager.add_entry(
session_id="abc-123",
entry_data={"text": "์๋
ํ์ธ์", "confidence": 0.95},
metadata={"language": "ko"},
)
# ์ธ์
์กฐํ
sessions = manager.get_sessions(limit=50)
session = manager.get_session("abc-123")
FastAPI API Key ์ธ์ฆ
from fastapi import FastAPI, Depends
from api.fastapi_auth import create_api_key_dependency
app = FastAPI()
verify_key = create_api_key_dependency(env_var="MY_API_KEY")
@app.get("/protected", dependencies=[Depends(verify_key)])
async def protected():
return {"message": "์ธ์ฆ๋จ"}
FastAPI WebSocket ์คํธ๋ฆฌ๋ฐ
from fastapi import FastAPI, WebSocket
from api.websocket_handler import create_websocket_handler
app = FastAPI()
async def process_audio(audio_buffer, params):
# ์ค๋์ค ์ฒ๋ฆฌ ๋ก์ง
return {"text": "๋ณํ ๊ฒฐ๊ณผ", "confidence": 0.95}
ws_handler = create_websocket_handler(process_fn=process_audio)
@app.websocket("/ws/stream")
async def ws_endpoint(websocket: WebSocket):
await ws_handler(websocket)
httpx ๋น๋๊ธฐ HTTP ํด๋ผ์ด์ธํธ
from httpx_utils.httpx_client import get_client, fetch_json
async with get_client() as client:
data = await fetch_json(client, "https://api.example.com/users")
Pydantic ๋ฐ์ดํฐ ๋ชจ๋ธ
from models.pydantic_patterns import BaseSchema, PaginatedResponse
class UserCreate(BaseSchema):
name: str
email: str
asyncio ๋์์ฑ ์ ์ด
from async.asyncio_patterns import run_with_limit, process_queue
results = await run_with_limit(tasks, max_concurrent=5)
structlog ๊ตฌ์กฐํ ๋ก๊น
from structlog_utils.structlog_setup import setup_logging, get_logger
setup_logging(level="INFO", json_format=True)
logger = get_logger("my_module")
logger.info("์๋ฒ ์์", port=8000)
Whisper STT ์์ง
from ai.whisper_engine import get_engine
engine = get_engine()
engine.load_model(model_size="base", device="auto")
# ์ค๋์ค ๋ณํ
result = engine.transcribe(audio_float32_array, language="ko")
print(result["text"])
print(f"์ ๋ขฐ๋: {result['confidence']:.2f}")
๋ด์ค ์์ง/๋ถ์
from news import NewsCollector, TrendAnalyzer, ReportGenerator
# ์์ง
collector = NewsCollector(keywords=["AI", "LLM"], days=7)
result = await collector.collect()
# ๋ถ์
analyzer = TrendAnalyzer(min_frequency=2, top_opportunities=5)
report = analyzer.analyze(result)
# ๋ณด๊ณ ์ ์์ฑ
reporter = ReportGenerator(report_dir="docs/intel")
reporter.save_report(report)
reporter.save_opportunity_cards(report)
# CLI ์คํ
uv run -m news.collector --domains ai,saas --days 7 --output raw.json
uv run -m news.analyzer --input raw.json --output analysis.json
uv run -m news.reporter --input analysis.json --output-dir docs/intel
ํ์ดํ๋ผ์ธ ์ค์ผ์คํธ๋ ์ด์
from pipelines import PipelineOrchestrator, PipelineStage, get_recipe
from pipelines import create_config_from_recipe, SourceInput
# ๋ ์ํผ ๊ธฐ๋ฐ ์ค์
source = SourceInput(type="url", content="https://example.com/article")
config = create_config_from_recipe("research-to-article", source)
# ์ค์ผ์คํธ๋ ์ดํฐ ์คํ
orchestrator = PipelineOrchestrator()
orchestrator.register_handler(PipelineStage.INGEST, my_ingest_handler)
report = await orchestrator.run(config)
print(report.summary())
# ์ฌ์ฉ ๊ฐ๋ฅํ ๋ ์ํผ ๋ชฉ๋ก
# research-to-article, trend-to-content, lecture-to-study-kit,
# docs-to-training, news-to-briefing
์ถ์ถ ์ด๋ ฅ
| ๋ ์ง | ์ถ์ฒ | ์ถ์ถ ํญ๋ชฉ |
|---|---|---|
| 2026-03-18 | claude-world/notebooklm-skill | pipelines 6๊ฐ (types, models, orchestrator, recipes, hooks, init) โ 4๋จ๊ณ ํ์ดํ๋ผ์ธ ์์ง |
| 2026-03-08 | 00-general-pro | news 12๊ฐ (models, collector, analyzer, reporter, sources 5๊ฐ, base, init 2๊ฐ) |
| 2026-02-16 | GitHub-์ปค๋ฎค๋ํฐ | http 1๊ฐ, models 1๊ฐ, api 1๊ฐ, async 1๊ฐ, logging 1๊ฐ, testing 1๊ฐ |
| 2026-02-15 | 260208 kcsi-smpa | utils 3๊ฐ (excel_reader, pdf_reader, hwpx_generator) |
| 2026-02-15 | voice-to-text-v2 | utils 3๊ฐ, api 2๊ฐ, ai 1๊ฐ (์ค๋์ค/์ธ์ /๋๋ฐ์ด์ค/์ธ์ฆ/WS/Whisper) |
๊ด๋ จ ๋ฌธ์
- 02-reusable-code โ TS/React ์ฌ์ฌ์ฉ ์ฝ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ (๋ถํ ๊ณ์ธต)
- 02-reusable-design โ ๋์์ธ ์์ฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ (์ฌ๋ฃ ๊ณ์ธต)
- 02-reusable-page โ ํ์ด์ง ์น์ ์ปดํฌ๋ํธ (์์ฑํ ๊ณ์ธต)
- ์ฝ๋ฉ ์ปจ๋ฒค์ โ ์ฌ์ฌ์ฉ ์ฝ๋ ํต์ผ ๊ท์น
/kdypickโ ์ฌ์ฌ์ฉ ์ฝ๋ ์ ํ ๋ฐ ํ๋ก์ ํธ์ ์ ์ฉ/kdyextractโ ํ๋ก์ ํธ์์ ๋ฒ์ฉ ์ฝ๋ ์ถ์ถ