Run isort, pyupgrade, mypy, pylint, flake8, and more on Jupyter Notebooks

Overview

nbQA

Run isort, pyupgrade, mypy, pylint, flake8, mdformat, black, blacken-docs, and more on Jupyter Notebooks

tox codecov pre-commit

versions chat docs

downloads

demo

  • βœ… handles IPython magics robustly
  • βœ… respects your config files
  • βœ… preserves "quiet mode" trailing semicolons
  • βœ… lints both code and markdown cells

Table of contents

πŸŽ‰ Installation

In your virtual environment, run (note: the $ is not part of the command):

$ python -m pip install -U nbqa

Or, if you are using conda:

$ conda install -c conda-forge nbqa

πŸš€ Examples

Command-line

Reformat your notebooks with black:

$ nbqa black my_notebook.ipynb
reformatted my_notebook.ipynb
All done! ✨ 🍰 ✨
1 files reformatted.

Sort your imports with isort:

$ nbqa isort my_notebook.ipynb
Fixing my_notebook.ipynb

Upgrade your syntax with pyupgrade:

$ nbqa pyupgrade my_notebook.ipynb --py36-plus
Rewriting my_notebook.ipynb

Format your markdown cells with mdformat:

$ nbqa mdformat my_notebook.ipynb --nbqa-md --nbqa-diff
Cell 2
------
--- my_notebook.ipynb
+++ my_notebook.ipynb
@@ -1,2 +1 @@
-First level heading
-===
+# First level heading

To apply these changes, remove the `--nbqa-diff` flag

See command-line examples for examples involving doctest, flake8, mypy, pylint, autopep8, pydocstyle, and yapf.

Pre-commit

Here's an example of how to set up some pre-commit hooks: put this in your .pre-commit-config.yaml file (see usage as pre-commit hook)

- repo: https://github.com/nbQA-dev/nbQA
  rev: 1.2.2
  hooks:
    - id: nbqa-black
    - id: nbqa-pyupgrade
      args: [--py36-plus]
    - id: nbqa-isort

If you need to select specific versions of any of these linters/formatters, add them to additional_dependencies.

πŸ₯³ Used by

Click here for (non-exhaustive) list of repos

Is your project missing? Let us know, or open a pull request!

πŸ’¬ Testimonials

Michael Kennedy & Brian Okken, hosts of the Python Bytes podcast:

This is really cool. I think it brings so much of the code formatting and code analysis, clean up to notebooks, which I think had been really lacking

Nikita Sobolev, CTO at wemake.services:

It is amazing!

Alex Andorra, Data Scientist, ArviZ & PyMC Dev, Host of 'Learning Bayesian Statistics' Podcast:

well done on nbqa @MarcoGorelli ! Will be super useful in CI

Matthew Feickert, Postdoc at University of Illinois working on LHC physics:

nbqa in your pre-commit hooks along with @codewithanthony 's pre-commit CI service is amazing! Everyone using Jupyter notebooks should be doing this.

Girish Pasupathy, Software engineer and now core-contributor:

thanks a lot for your effort to create such a useful tool

Simon Brugman, Data scientist & pandas-profiling dev:

nbQA helps us to keep notebooks to the same standards as the rest of the code. If you're serious about your code standards, you should keep them consistent across both notebooks and python scripts. Great addition to the ecosystem, thanks!

Bradley Dice, PhD Candidate in Physics & Scientific Computing:

nbqa is a clean, easy to use, and effective tool for notebook code style. Formatting and readability makes a huge difference when rendering notebooks in a project's documentation!

James Lamb, engineer @saturn_cloud, LightGBM maintainer

today I learned about nbqa, a command-line tool to run linters like flake8 over #Python code in @ProjectJupyter notebooks. Thanks to @jayyqi for pointing me to it. So far, I really really like it.

Lars Yencken, Tech Lead @ Our World In Data

Super useful! I only wish it was built-in to Jupyterlab.

Vincent D. Warmerdam, maintainer @ calmcode.io

Nice. nbQA looks like a great way to prevent the Untitled12.ipynb-phenomenon. I like!

πŸ‘₯ Contributing

I will give write-access to anyone who makes a useful pull request - see the contributing guide for details on how to do so.

Thanks goes to these wonderful people (emoji key):


Marco Gorelli

πŸ’» 🚧 πŸ‘€ ⚠️ πŸ€”

Sebastian Weigand

πŸ”§ πŸ‘€ πŸ“– πŸ€”

Girish Pasupathy

πŸ’» πŸš‡ πŸ› πŸ‘€ πŸ€”

fcatus

πŸš‡

HD23me

πŸ›

mani

πŸ€” πŸš‡

Daniel Mietchen

πŸ€”

MichaΕ‚ Gacka

πŸ›

Happy

πŸ“–

Nat Taylor

πŸ€” πŸ’» πŸ”§ πŸ›

Caio Ariede

πŸ“–

Nikita Sobolev

πŸ€” πŸ› πŸ“–

Amichay Oren

πŸ€”

pylang

πŸ€”

Henry Schreiner

πŸ›

Kaiqi Dong

πŸ“–

Simon Brugman

πŸ›

John Sandall

πŸ›

Nathan Cooper

πŸ›

agruenberger

πŸ›

Rafal Wojdyla

πŸ›

Bradley Dice

πŸ€” πŸ’»

Ivan Cheung

πŸ›

Tony Hirst

πŸ›

Taneli Hukkinen

🚧

Tom Begley

πŸ€” πŸ’» πŸ“–

Steven DeMartini

πŸ“–

vincent d warmerdam

βœ…

Daniel Sparing

πŸ›

asdfCYBER

πŸ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

Type stubs for the lxml package

lxml-stubs About This repository contains external type annotations (see PEP 484) for the lxml package. Installation To use these stubs with mypy, you

25 Dec 26, 2022
❄️ A flake8 plugin to help you write better list/set/dict comprehensions.

flake8-comprehensions A flake8 plugin that helps you write better list/set/dict comprehensions. Requirements Python 3.6 to 3.9 supported. Installation

Adam Johnson 398 Dec 23, 2022
A plugin for Flake8 that checks pandas code

pandas-vet pandas-vet is a plugin for flake8 that provides opinionated linting for pandas code. It began as a project during the PyCascades 2019 sprin

Jacob Deppen 146 Dec 28, 2022
A Pylint plugin to analyze Flask applications.

pylint-flask About pylint-flask is Pylint plugin for improving code analysis when editing code using Flask. Inspired by pylint-django. Problems pylint

Joe Schafer 62 Sep 18, 2022
Flake8 extension to provide force-check option

flake8-force Flake8 extension to provide force-check option. When this option is enabled, flake8 performs all checks even if the target file cannot be

Kenichi Maehashi 9 Oct 29, 2022
Utilities for pycharm code formatting (flake8 and black)

Pycharm External Tools Extentions to Pycharm code formatting tools. Currently supported are flake8 and black on a selected code block. Usage Flake8 [P

Haim Daniel 13 Nov 03, 2022
Custom Python linting through AST expressions

bellybutton bellybutton is a customizable, easy-to-configure linting engine for Python. What is this good for? Tools like pylint and flake8 provide, o

H. Chase Stevens 249 Dec 31, 2022
A static-analysis bot for Github

Imhotep, the peaceful builder. What is it? Imhotep is a tool which will comment on commits coming into your repository and check for syntactic errors

Justin Abrahms 221 Nov 10, 2022
Tool for automatically reordering python imports. Similar to isort but uses static analysis more.

reorder_python_imports Tool for automatically reordering python imports. Similar to isort but uses static analysis more. Installation pip install reor

Anthony Sottile 589 Dec 26, 2022
Flake8 plugin for managing type-checking imports & forward references

flake8-type-checking Lets you know which imports to put in type-checking blocks. For the imports you've already defined inside type-checking blocks, i

snok 67 Dec 16, 2022
MyPy types for WSGI applications

WSGI Types for Python This is an attempt to bring some type safety to WSGI applications using Python's new typing features (TypedDicts, Protocols). It

Blake Williams 2 Aug 18, 2021
The mypy playground. Try mypy with your web browser.

mypy-playground The mypy playground provides Web UI to run mypy in the sandbox: Features Web UI and sandbox for running mypy eas

Yusuke Miyazaki 57 Jan 02, 2023
Silence mypy by adding or removing code comments

mypy-silent Automatically add or remove # type: ignore commends to silence mypy. Inspired by pylint-silent Why? Imagine you want to add type check for

Wu Haotian 8 Nov 30, 2022
Convert relative imports to absolute

absolufy-imports A tool and pre-commit hook to automatically convert relative imports to absolute. Installation $ pip install absolufy-imports Usage a

Marco Gorelli 130 Dec 30, 2022
Static Typing for Python

Python static typing home. Contains the source for typing_extensions and the documentation. Also hosts a user help forum.

Python 1.3k Jan 06, 2023
Mypy stubs for the PyQt5 framework

Mypy stubs for the PyQt5 framework This repository holds the stubs of the PyQt5 framework. It uses the stub files that are produced during compilation

62 Nov 22, 2022
A static type analyzer for Python code

pytype - πŸ¦† βœ” Pytype checks and infers types for your Python code - without requiring type annotations. Pytype can: Lint plain Python code, flagging c

Google 4k Dec 31, 2022
flake8 plugin that integrates isort

Flake8 meet isort Use isort to check if the imports on your python files are sorted the way you expect. Add an .isort.cfg to define how you want your

Gil Forcada Codinachs 139 Nov 08, 2022
Flake8 extension for checking quotes in python

Flake8 Extension to lint for quotes. Major update in 2.0.0 We automatically encourage avoiding escaping quotes as per PEP 8. To disable this, use --no

Zachary Heller 157 Dec 13, 2022
Flake8 Type Annotation Checking

flake8-annotations flake8-annotations is a plugin for Flake8 that detects the absence of PEP 3107-style function annotations and PEP 484-style type co

S. Co1 118 Jan 05, 2023