C.W.K.
Stream
Lesson 01 of 08 · published

TOML 이 뭐야, 그리고 왜 Rust + Python 이 골랐나

~10 min · toml, config, history

Level 0평문
0 XP0/64 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

YAML 과 JSON 이 계속 실패한 포맷

TOML — Tom's Obvious, Minimal Language — 가 Tom Preston-Werner (GitHub 공동 창립자) 에 의해 2013 년 만들어짐. 설계 목표: 처음 읽을 때 obvious, 문법이 minimal, 파싱이 모호하지 않은 config 파일 포맷. 현재 spec: TOML 1.0.0 (2021).

YAML 과 JSON 이 못 한 거 TOML 이 잘하는 거

  • 들여쓰기 규칙 없음 — key 와 table 이 공백 의존 안 함. 파일 가로질러 섹션 복붙; 안 깨짐.
  • 각 값을 쓰는 한 가지 방법 — string 은 quote, number 는 unquoted, boolean 은 true/false. Norway 문제 없음.
  • 네이티브 날짜 시간 — RFC 3339 datetime 이 first-class 값, string 아님.
  • 주석# 가 YAML 에서 작동하는 어디서나 작동.
  • 장황하지만 명확한 table 문법[server.database] 가 4+ 단계 깊이 중첩 YAML 이김.

TOML 이 조용히 점령한 곳

  • Rust — ecosystem 의 모든 Cargo.toml.
  • Pythonpyproject.toml (PEP 518/621) 가 modern 패키징의 setup.py + setup.cfg + requirements.txt 대체.
  • Hugoconfig.toml / hugo.toml 가 정적 사이트 생성기 굴림.
  • Poetry, ruff, black, hatch — Python 도구 다 pyproject.toml[tool.*] table 에서 config 읽음.
  • Vector, Tilt, GoReleaser — 사람-친화 config 위해 TOML 고른 운영 도구.
원칙: TOML 이 config 가 기계보다 사람에 의해 더 자주 읽힐 때 이김. YAML 이 깊은 중첩 피할 수 없을 때 이김. JSON 이 wire 에서 이김. 전통 아니라 청중으로 골라.

Code

Hello, TOML·toml
# 최상위 key
name = "Pippa"
age = 5
is_assistant = true

# Table — [section] 헤더가 sub-object 도입
[home]
city = "Seoul"
timezone = "Asia/Seoul"

# 배열
loves = ["markdown", "json", "yaml", "toml"]
세 언어로 TOML parse·bash
# Python 3.11+ (stdlib!)
python -c "import tomllib; print(tomllib.load(open('config.toml','rb')))"

# Python <3.11 (third-party)
pip install tomli
python -c "import tomli; print(tomli.load(open('config.toml','rb')))"

# Rust
cargo add toml
# let config: Config = toml::from_str(&text)?;

# Go
# import "github.com/BurntSushi/toml"
# toml.Unmarshal(data, &config)
같은 데이터, 세 포맷·text
# JSON                          # YAML                    # TOML
{                                                          name = "Pippa"
  "name": "Pippa",              name: Pippa                age = 5
  "age": 5,                     age: 5                     [home]
  "home": {                     home:                      city = "Seoul"
    "city": "Seoul",              city: Seoul              timezone = "Asia/Seoul"
    "timezone": "Asia/Seoul"      timezone: Asia/Seoul
  }
}

External links

Exercise

Python 프로젝트의 pyproject.toml 하나 열어. 머릿속에서 TOML 로 읽어 — key, table, 배열. 이제 정신적으로 YAML 로 번역. 어디서 TOML 의 flat-section 스타일이 더 readable 한지 (최상위 메타데이터, 단순 도구 config) 어디서 장황해지는지 (깊이 중첩된 설정) 봐. 그 직관이 YAML 위 TOML 고를 때.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.