Skip to main content

Python Module Scripts

·537 words·3 mins·
Python Utils
Table of Contents

This article is related with python modules

Intro
#

Trey Hunner shared this insightful article where one can take advantage of one functionality that some python modules bring.

Please check his article if you want to deep dive on the topic.

How it works
#

Running Python with the -m command-line argument tells Python to run a given Python module as if it were a Python script.

One can execute the following command line to spin up a web server to that list local files

python -m http.server

Depending on the python module you may have a quick way to execute task.

python -m json.tool file.json

The previous example allow you to pretty format the file.json quickly

Module List
#

Here’s a quick summary of every command-line tool in Python:

Module/ScriptPurposeCategory
http.serverStart a simple web serverGeneral
webbrowserLaunch your web browserGeneral
json.toolNicely format JSON dataGeneral
calendarShow a command-line calendarGeneral
uuidLike uuidgen CLI utilityLinux-like
sqlite3Like sqlite3 CLI utilityLinux-like
zipfileLike zip & unzip CLI utilitiesLinux-like
gzipLike gzip & gunzip CLI utilitiesLinux-like
tarfileLike the tar CLI utilityLinux-like
base64Like the base64 CLI utilityLinux-like
ftplibLike the ftp utilityLinux-like
smtplibLike the sendmail utilityLinux-like
poplibLike using curl to read emailLinux-like
imaplibLike using curl to read emailLinux-like
telnetlibLike the telnetutilityLinux-like
pipInstall third-party Python packagesPython
venvCreate a virtual environmentPython
pdbRun the Python DebuggerPython
unittestRun unittest tests in a directoryPython
pydocShow documentation for given stringPython
doctestRun doctests for a given Python filePython
ensurepipInstall pip if it’s not installedPython
idlelibLaunch Python’s IDLE graphical REPLPython
zipappTurn Python module into runnable ZIPPython
python -m compileallPre-compile Python files to bytecodePython
tokenizeBreak Python module into “tokens”Inspect code
astShow abstract syntax tree for codeInspect code
disDisassemble Python code to bytecodeInspect code
inspectinspect source code of a Python objectInspect code
pyclbrSee overview of a module’s objectsInspect code
asyncioLaunch an asyncio-aware REPLDeep Python
cProfileProfile a Python programDeep Python
profileProfile Python program with PythonDeep Python
pstatsShow stats on cProfile-generated fileDeep Python
pickleReadably display pickle file contentsDeep Python
pickletoolsDisassemble a pickle fileDeep Python
tabnannyCheck file for mixed tabs & spacesDeep Python
thisDisplay the Zen of Python (PEP 20)Fun
__hello__Print Hello world!Fun
antigravityOpen XKCD 353 in a web browserFun
turtledemoSee turtle module demosFun
codeRun a Python REPLPython
runpyRun a Python module as a scriptPython
timeitTime a Python expressionPython
siteSee “site” information about PythonDeep Python
sysconfigShow Python configuration detailsDeep Python
platformDisplay current platform informationGeneral
mimetypesShow file mimetype/extension detailsGeneral
quopriEncode/decode raw email dataGeneral
filecmpCompare contents of 2 directoriesGeneral
encodings.rot_13ROT-13 encode/decode textGeneral

These are just the Python scripts included in the Python standard library. Any third-party module that can be run as a script can also be launched via python -m MODULE_NAME as well.

References
#