I really enjoy using black and isort to format code. Both tools provide a command line interface and work well with python files. In order to get them to work with Jupyter Notebooks, specifically JupyterLab, there are some additional steps to follow.

First, install this jupyter labextension (be sure to active your virtual environment first!) with:

jupyter labextension install @ryantam626/jupyterlab_code_formatter
pip install jupyterlab_code_formatter
jupyter serverextension enable --py jupyterlab_code_formatter

Then install the python code formatting tools of your choice:

pip install isort black

Then restart the JuypterLab if it is running, and you should be able to run isort and black by selecting cells, then right clicking and selecting Format Cells. See the documentation here for more detailed instructions.