# 파이썬 표준 라이브러리에 숨겨진 CLI 도구들

> Clean Markdown view of GeekNews topic #9548. Use the original source for factual precision when an external source URL is present.

## Metadata

- GeekNews HTML: [https://news.hada.io/topic?id=9548](https://news.hada.io/topic?id=9548)
- GeekNews Markdown: [https://news.hada.io/topic/9548.md](https://news.hada.io/topic/9548.md)
- Type: news
- Author: [xguru](https://news.hada.io/@xguru)
- Published: 2023-06-30T09:50:27+09:00
- Updated: 2023-06-30T09:50:27+09:00
- Original source: [til.simonwillison.net](https://til.simonwillison.net/python/stdlib-cli-tools)
- Points: 16
- Comments: 3

## Topic Body

- 파이썬 표준 라이브러리에는 터미널에서 실행할 수 있는 숨겨진 CLI 도구가 포함되어 있음  
  - `python -m gzip --decompress pypi.db.gz` 처럼 gzip 을 활용 가능   
- 파이썬 모듈이 `if __name__ == "__main__"` 블록이 있다면 `python -m 모듈명` 으로 실행 가능하기 때문  
- 이렇게 활용 가능한 모듈중 일부   
  - `python -m http.server 8001`  
  - `python -m asyncio` 파이썬 콘솔에서 탑레벨 await 가능해짐   
  - `python -m tokenize cgi.py | head -n 10` 파이썬 토크나이저 디버그 모드   
  - `python -m ast cgi.py | head -n 10` AST 디버그 모드   
  - `python -m json.tool` JSON 프리티 프린트 가능   
  - `python -m nntplib` 기본으로 gmane.comp.python.general 뉴스그룹의 최신 글들을 보여줌(아쉽게도 다른 그룹은 불가)  
  - `python -m calendar` 올해 달력 출력 `-t html` 로 HTML 출력도 가능   
- 파이썬 표준 라이브러리에는 이 외에도 많은 멋진 작은 도구들이 숨겨져 있음

## Comments



### Comment 16880

- Author: botplaysdice
- Created: 2023-06-30T16:37:16+09:00
- Points: 1

웹서버 요긴하게 씁니다. 회사에서 scp로 옮기면 쓰로틀링을 심하게 걸어서 (나름 보안을 위해서인듯;;;), 삼바 접근도 엄청 느리고.... 파일 큰거 받을때 파이썬 웹서버로....

### Comment 16875

- Author: mckabi
- Created: 2023-06-30T11:28:44+09:00
- Points: 1

- `python -m base64` : `echo "test string" | python -m base64 -e | python -m base64 -d`  
- `python -m imghdr IMAGE_FILENAME`  
- `python -m sndhdr SOUND_FILENAME`  
- tarfile, gzip, zip  
- locale, platform, sysconfig  
- `python -m inspect PYTHON_PKG`  
  
아쉬울 때가 언젠가는 있더군요.

### Comment 16870

- Author: neo
- Created: 2023-06-30T09:50:27+09:00
- Points: 2

###### [Hacker News 의견](http://news.ycombinator.com/item?id=36515531)   
- 파이썬 표준 라이브러리의 `re.Scanner` 도구는 공식 문서에 누락된 정규식 기반 토크나이저입니다.  
- 이 도구는 한 번에 토큰 목록을 처리하며 연속된 일치를 보장합니다.  
- `if __name__ == "__main__":` 블록을 사용하면 모듈을 단일 *.py 파일로 실행할 수 있습니다.  
- 파이썬 3.12에는 표준 라이브러리에 SQLite CLI/REPL이 포함될 예정입니다.  
- `zipfile` 모듈은 명령줄에서 zip 파일을 압축 해제하고 압축하는 데 사용할 수 있습니다.  
- `json.tool` 모듈은 명령줄에서 JSON을 예쁘게 출력하는 데 사용할 수 있습니다.  
- `http.server` 모듈은 로컬 네트워크에서 파일을 공유하는 데 유용합니다.  
- 표준 라이브러리의 모듈을 명령줄에서 사용하는 것은 보안 위험을 가질 수 있습니다.  
- 파이썬 표준 라이브러리에는 문서화되지 않은 많은 숨겨진 도구와 기능이 있습니다.
