Python bash libraries

http.server

# python2
python -m SimpleHTTPServer

# python3
python3 -m http.server

json pretty printing

$ echo '{"json":"obj"}' | python -m json.tool

{
    "json": "obj"
}

pip

# unistall all existing packages
pip freeze | xargs pip uninstall -y

pycodestyle

pycodestyle ./project_name

virtual environment

# create new vierualenv with venv without pip
python3.6 -m venv $ENV_NAME --without-pip
source $ENV_NAME/bin/activate
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py

# or with pip just
python3.6 -m venv $ENV_NAME

# with virtualenv
virtualenv -p /usr/local/bin/python2.7 env_name

Working with archives

# Create a new TAR archive
$ python3 -m tarfile -c <tarname>.tgz <file> <file>

# Extract from an existing TAR archive
$ python3 -m tarfile -e <tarname>.tgz

# pack directory into archive and make it executable
$ python3 -m zipapp myapp
$ python3 myapp.pyz
# <output from myapp>