What "tools" are available in Python standard library
Question:
I’m currently aware of two tools:
-
base64 encoder/decoder:
python -m base64 -e <input
python -m base64 -d <input
-
json validator and pretty printer
python -m json.tool <input
where input can be stdin or file.
I’m curious if there are other tools exposed by SPL that work in similar fashion?
Answers:
Many.
$ grep "if __name__ == '__main__':" /usr/lib64/python2.7/* | wc -l
55
Not all work as a filter though, so examine the module in question before running.
Not a complete list…
Encoding
Base64 en/decoding:
python -m base64 -d [file]
python -m base64 -e [file]
ROT-13 en/decoder:
python -m encodings.rot_13
Macintosh BinHex:
# binhex <file> to <file>.hqx, and unbinhex <file>.hqx to <file>.viahqx
python -m binhex <file>
UUencode/decode:
python -m uu [infile [outfile]] # encode
python -m uu -d [infile [outfile]] # decode
MIME quoted-printable en/decoding:
python -m mimify -e [infile [outfile]] # encode
python -m mimify -d [infile [outfile]] # decode
Quoted-printable en/decoding:
python -m quopri [file] # encode
python -m quopri -d [file] # decode
Compression
GZip:
python -m gzip [file] # compress
python -m gzip -d [file] # decompress
Zipfile extraction, etc.:
python -m zipfile -l <file> # list
python -m zipfile -t <file> # test
python -m zipfile -e <file> <dir> # extract
python -m zipfile -c <file> sources... # create
Internet
HTTP servers:
python -m BaseHTTPServer
python -m CGIHTTPServer
python -m SimpleHTTPServer
Simple FTP client:
python -m ftplib host [-l<dir-to-list>] [-d<dir-to-cwd>] [-p] [file-to-retrieve]
HTML Text extraction:
python -m htmllib <file>
JSON Validator and pretty-printer:
python -m json.tool [infile [outfile]]
List POP3 mailbox:
python -m poplib <server> <username> <password>
SMTP server:
python -m smtpd
Send a mail message (to localhost):
python -m smtplib
Telnet client:
python -m telnetlib [host [port]]
MIME type/extension database:
python -m mimetypes file.ext # print type for filename
python -m mimetypes -e mime/type # print extension for type
Open webbrowser:
python -m webbrowser -n <url> # new window
python -m webbrowser -t <url> # new tab
python -m antigravity
Python
Pure-Python REPL:
python -m code
Python bytecode batch compiler:
python -m compileall
Python code profiler:
python -m cProfile <script>
python -m profile <script>
python -m pstats <filename> # print profiling statistics
Python doctest executor:
python -m doctest <script>
Python benchmark:
python -m test.pystone [iterations]
python -m hotshot.stones
Python interactive debugger:
python -m pdb
Extract Python classes and methods from a module:
python -m pyclbr <script>
Python documentation browser:
python -m pydoc <topic>
python -m pydoc -g # graphical browser
python -m pydoc -p <port> # start HTTP docs server on port
Python snippet timer:
python -m timeit
Misc
Calendar (like cal
, but can do HTML and various fancy formatting stuff):
python -m calendar
Directory comparer:
python -m filecmp [-r] dir1 dir2 # -r for recursive directory compare
Paragraph formatting:
python -m formatter [file]
Show current platform (like uname
but simpler):
python -m platform
There’s also -m compatible packages on the Cheeseshop. Try “e” or “oo” 🙂
Also, there is:
python -m this
I’m currently aware of two tools:
-
base64 encoder/decoder:
python -m base64 -e <input
python -m base64 -d <input
-
json validator and pretty printer
python -m json.tool <input
where input can be stdin or file.
I’m curious if there are other tools exposed by SPL that work in similar fashion?
Many.
$ grep "if __name__ == '__main__':" /usr/lib64/python2.7/* | wc -l
55
Not all work as a filter though, so examine the module in question before running.
Not a complete list…
Encoding
Base64 en/decoding:
python -m base64 -d [file]
python -m base64 -e [file]
ROT-13 en/decoder:
python -m encodings.rot_13
Macintosh BinHex:
# binhex <file> to <file>.hqx, and unbinhex <file>.hqx to <file>.viahqx
python -m binhex <file>
UUencode/decode:
python -m uu [infile [outfile]] # encode
python -m uu -d [infile [outfile]] # decode
MIME quoted-printable en/decoding:
python -m mimify -e [infile [outfile]] # encode
python -m mimify -d [infile [outfile]] # decode
Quoted-printable en/decoding:
python -m quopri [file] # encode
python -m quopri -d [file] # decode
Compression
GZip:
python -m gzip [file] # compress
python -m gzip -d [file] # decompress
Zipfile extraction, etc.:
python -m zipfile -l <file> # list
python -m zipfile -t <file> # test
python -m zipfile -e <file> <dir> # extract
python -m zipfile -c <file> sources... # create
Internet
HTTP servers:
python -m BaseHTTPServer
python -m CGIHTTPServer
python -m SimpleHTTPServer
Simple FTP client:
python -m ftplib host [-l<dir-to-list>] [-d<dir-to-cwd>] [-p] [file-to-retrieve]
HTML Text extraction:
python -m htmllib <file>
JSON Validator and pretty-printer:
python -m json.tool [infile [outfile]]
List POP3 mailbox:
python -m poplib <server> <username> <password>
SMTP server:
python -m smtpd
Send a mail message (to localhost):
python -m smtplib
Telnet client:
python -m telnetlib [host [port]]
MIME type/extension database:
python -m mimetypes file.ext # print type for filename
python -m mimetypes -e mime/type # print extension for type
Open webbrowser:
python -m webbrowser -n <url> # new window
python -m webbrowser -t <url> # new tab
python -m antigravity
Python
Pure-Python REPL:
python -m code
Python bytecode batch compiler:
python -m compileall
Python code profiler:
python -m cProfile <script>
python -m profile <script>
python -m pstats <filename> # print profiling statistics
Python doctest executor:
python -m doctest <script>
Python benchmark:
python -m test.pystone [iterations]
python -m hotshot.stones
Python interactive debugger:
python -m pdb
Extract Python classes and methods from a module:
python -m pyclbr <script>
Python documentation browser:
python -m pydoc <topic>
python -m pydoc -g # graphical browser
python -m pydoc -p <port> # start HTTP docs server on port
Python snippet timer:
python -m timeit
Misc
Calendar (like cal
, but can do HTML and various fancy formatting stuff):
python -m calendar
Directory comparer:
python -m filecmp [-r] dir1 dir2 # -r for recursive directory compare
Paragraph formatting:
python -m formatter [file]
Show current platform (like uname
but simpler):
python -m platform
There’s also -m compatible packages on the Cheeseshop. Try “e” or “oo” 🙂
Also, there is:
python -m this