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!

mypy plugin to type check Kubernetes resources

kubernetes-typed mypy plugin to dynamically define types for Kubernetes objects. Features Type checking for Custom Resources Type checking forkubernet

Artem Yarmoliuk 16 Oct 10, 2022
Rust like Option and Result types in Python

Option Rust-like Option and Result types in Python, slotted and fully typed. An Option type represents an optional value, every Option is either Some

45 Dec 13, 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
πŸ¦† Better duck-typing with mypy-compatible extensions to Protocol

πŸ¦† Quacks If it walks like a duck and it quacks like a duck, then it must be a duck Thanks to PEP544, Python now has protocols: a way to define duck t

Arie Bovenberg 9 Nov 14, 2022
mypy plugin for loguru

loguru-mypy A fancy plugin to boost up your logging with loguru mypy compatibility logoru-mypy should be compatible with mypy=0.770. Currently there

Tomasz TrΔ™bski 13 Nov 02, 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
πŸ‘» Phantom types for Python

phantom-types Phantom types for Python will help you make illegal states unrepresentable and avoid shotgun parsing by enabling you to practice "Parse,

Anton Agestam 118 Dec 22, 2022
A simple program which checks Python source files for errors

Pyflakes A simple program which checks Python source files for errors. Pyflakes analyzes programs and detects various errors. It works by parsing the

Python Code Quality Authority 1.2k Dec 30, 2022
Reference implementation of sentinels for the Python stdlib

Sentinels This is a reference implementation of a utility for the definition of sentinel values in Python. This also includes a draft PEP for the incl

Tal Einat 22 Aug 27, 2022
Plugin for mypy to support zope.interface

Plugin for mypy to support zope.interface The goal is to be able to make zope interfaces to be treated as types in mypy sense. Usage Install both mypy

Shoobx 36 Oct 29, 2022
Python classes with types validation at runtime.

typedclasses Python classes with types validation at runtime. (Experimental & Under Development) Installation You can install this library using Pytho

Izhar Ahmad 8 Feb 06, 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
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
Flake8 plugin that checks import order against various Python Style Guides

flake8-import-order A flake8 and Pylama plugin that checks the ordering of your imports. It does not check anything else about the imports. Merely tha

Python Code Quality Authority 270 Nov 24, 2022
A Python Parser

parso - A Python Parser Parso is a Python parser that supports error recovery and round-trip parsing for different Python versions (in multiple Python

Dave Halter 520 Dec 26, 2022
An open-source, mini imitation of GitHub Copilot for Emacs.

Second Mate An open-source, mini imitation of GitHub Copilot using EleutherAI GPT-Neo-2.7B (via Huggingface Model Hub) for Emacs. This is a much small

Sam Rawal 238 Dec 27, 2022
The official GitHub mirror of https://gitlab.com/pycqa/flake8

Flake8 Flake8 is a wrapper around these tools: PyFlakes pycodestyle Ned Batchelder's McCabe script Flake8 runs all the tools by launching the single f

Python Code Quality Authority 2.6k Jan 03, 2023
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
Flake8 plugin to find commented out or dead code

flake8-eradicate flake8 plugin to find commented out (or so called "dead") code. This is quite important for the project in a long run. Based on eradi

wemake.services 277 Dec 27, 2022
Tool to automatically fix some issues reported by flake8 (forked from autoflake).

autoflake8 Introduction autoflake8 removes unused imports and unused variables from Python code. It makes use of pyflakes to do this. autoflake8 also

francisco souza 27 Sep 08, 2022