pip install tqdm
Then in the script:
from tqdm import tqdm
for i in tqdm(range(100), desc="Loading..."):
# ...
If the description needed to be updated at each iteration:
from tqdm import tqdm
for i in (pdar := tqdm(range(100))):
pdar.set_description('...')
# ...
List of named colors — Matplotlib 3.9.2 documentation

My preferred ones:
See also:
environment.yml
Exporting the environment.yml file | conda 25.3.2.dev62 documentation
conda env export > environment.yml
Creating an environment with commands | conda 25.3.2.dev62 documentation
conda env create -f environment.yml
Or just add packages to an existed environment:
conda env update -f environment.yml
.env
fileInstall dependency:
pip install python-dotenv
Create .env file:
<key1>='<value1>'
<key2>='<value2>'
Load it from Python:
import os
from dotenv import load_dotenv
load_dotenv('.env')
value1 = os.getenv("key1")
value2 = os.getenv("key2")
Don’t forget to ignore the .env in .gitignore:
.env
import sys
sys.path.append('<path>')
P.S. In Jupyter Notebook, if you’d like to change the executing directory directly, you can use:
%cd <path>
Change IPython/Jupyter notebook working directory - Stack Overflow
By adding this cell to the notebook, package can be automatically reloaded. That’s incredibly important when we are developing & testing a package on the go:
%reload_ext autoreload
%autoreload 2
P.S. It reloads every imported package before running each cell, which may slow down the execution time.
python - How to make VSCode auto-reload external *.py modules? - Stack Overflow
A package can also be reloaded manually:
import importlib
importlib.reload(<pkg>)
Auto refresh imports (support %autoreload magic) · Issue #4555 · microsoft/vscode-jupyter
python - How to run an .ipynb Jupyter Notebook from terminal? - Stack Overflow
Running notebooks from command line have two use cases:
pip install nbconvert
Then:
jupyter nbconvert --execute --to notebook --inplace <notebook>
To make it easier to type:
alias nbx="jupyter nbconvert --execute --to notebook --inplace"
nbx <notebook>
P.S. It can be accompanied by command line arguments, e.g.:
owner=Knpob nbx convert-alipay.ipynb
Then in the notebooks:
import os
try:
owner = os.environ['owner']
except:
pass
git config filter.strip-notebook-output.clean 'jupyter nbconvert --ClearOutputPreprocessor.enabled=True --to=notebook --stdin --stdout --log-level=ERROR'
.gitattributes
file inside the directory with the notebooks. Add *.ipynb filter=strip-notebook-output
to that file:cd <notebook folder>
touch .gitattributes
echo '*.ipynb filter=strip-notebook-output' > .gitattributes
This gist is based on @dirkjot's answer.
How to clear Jupyter Notebook's output in all cells from the Linux terminal? - Stack Overflow
Building and Publishing - Python Packaging User Guide
Publishing package distribution releases using GitHub Actions CI/CD workflows - Python Packaging User Guide
pip install twine build
pyproject.toml
# local install: pip install -e .
# local build: python -m build
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
[project]
name = "<pkg>"
version = "<ver>"
description = "<str>"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.7"
license = { text = "<license>" }
authors = [
{ name = "<name>", email = "<email>" }
]
dependencies = [
"<pkg1>",
"<pkg2>",
]
[project.urls]
Repository = "<repo link>"
# You can also add more links, e.g. Homepage, Documentation, Bug Tracker, etc.
[tool.setuptools.packages.find]
where = ["."]
include = ["<pkg folder>*"]
P.S. The pyproject.toml
can also be used for local install:
pip install -e .
Firstly, to avoid including unnecessary or even sensitive files, e.g. you API keys in .env
files, clone the project to other places. In that folder, build the project:
python -m build
Check:
twine check dist/*
If you want to further confirm the release is OK, firstly upload it to TestPyPi:
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
When you're ready, upload it to PyPI:
twine upload --repository-url dist/*
P.S. You need to signup an account and acquire the API key on both PyPI and TestPyPI, separately.
Clear the dist/
folder:
rm -rf dist/