nbqa 1.9.1


pip install nbqa

  Latest version

Released: Nov 10, 2024


Meta
Author: Marco Gorelli, Girish Pasupathy, Sebastian Weigand
Requires Python: >=3.9

Classifiers

Development Status
  • 4 - Beta

Environment
  • Console

Framework
  • Jupyter

Intended Audience
  • Developers

License
  • OSI Approved :: MIT License

Natural Language
  • English

Operating System
  • OS Independent

Programming Language
  • Python :: 3
  • Python :: 3 :: Only

Topic
  • Software Development :: Quality Assurance

nbQA

Run ruff, isort, pyupgrade, mypy, pylint, flake8, 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

To also install all supported linters/formatters:

$ python -m pip install -U "nbqa[toolchain]"

🚀 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 --float-to-top
Fixing my_notebook.ipynb

Upgrade your syntax with pyupgrade:

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

Format your markdown cells with blacken-docs:

$ nbqa blacken-docs 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

Format .md files saved via Jupytext (requires jupytext to be installed):

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

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

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.9.1
  hooks:
    - id: nbqa-black
      additional_dependencies: [jupytext]  # optional, only if you're using Jupytext
    - id: nbqa-pyupgrade
      args: ["--py37-plus"]
    - id: nbqa-isort
      args: ["--float-to-top"]

If you need to select specific versions 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!

Mani Sarkar, Kaggle 3x expert, contributor

nbQA is an inspiring project, and the team behind it are very knowledgeable and think of things outside the box with ideas and solutions

👥 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
Marco Gorelli

💻 🚧 👀 ⚠️ 🤔
Sebastian Weigand
Sebastian Weigand

🔧 👀 📖 🤔
Girish Pasupathy
Girish Pasupathy

💻 🚇 🐛 👀 🤔
fcatus
fcatus

🚇
HD23me
HD23me

🐛
mani
mani

🤔 🚇
Daniel Mietchen
Daniel Mietchen

🤔
Michał Gacka
Michał Gacka

🐛
Happy
Happy

📖
Nat Taylor
Nat Taylor

🤔 💻 🔧 🐛
Caio Ariede
Caio Ariede

📖
Nikita Sobolev
Nikita Sobolev

🤔 🐛 📖
Amichay Oren
Amichay Oren

🤔
pylang
pylang

🤔
Henry Schreiner
Henry Schreiner

🐛
Kaiqi Dong
Kaiqi Dong

📖
Simon Brugman
Simon Brugman

🐛
John Sandall
John Sandall

🐛
Nathan Cooper
Nathan Cooper

🐛
agruenberger
agruenberger

🐛
Rafal Wojdyla
Rafal Wojdyla

🐛
Bradley Dice
Bradley Dice

🤔 💻
Ivan Cheung
Ivan Cheung

🐛
Tony Hirst
Tony Hirst

🐛
Taneli Hukkinen
Taneli Hukkinen

🚧
Tom Begley
Tom Begley

🤔 💻 📖
Steven DeMartini
Steven DeMartini

📖
vincent d warmerdam
vincent d warmerdam

Daniel Sparing
Daniel Sparing

🐛
asdfCYBER
asdfCYBER

📖
Chris Knight
Chris Knight

🐛
Laura Richter
Laura Richter

🤔
Francesco Ballarin
Francesco Ballarin

🐛
Janosh Riebesell
Janosh Riebesell

🐛 📖
Nicolas Oliver
Nicolas Oliver

🐛
Bas Nijholt
Bas Nijholt

🤔
Ralf Gommers
Ralf Gommers

🤔
Toon Verstraelen
Toon Verstraelen

📖
Trinh Quoc Anh
Trinh Quoc Anh

🐛
Martin K. Scherer
Martin K. Scherer

💻
Felix Williams
Felix Williams

🐛 🚇 🐛
Florian Bär
Florian Bär

📖
Michael Kennedy
Michael Kennedy

🔊
Brian Okken
Brian Okken

🔊
Sydney
Sydney

🐛
fvonbergen
fvonbergen

🐛
Gaétan Lepage
Gaétan Lepage

⚠️
Anurag Nayak
Anurag Nayak

🐛 🚇
Min RK
Min RK

💻

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

1.9.1 Nov 10, 2024
1.9.0 Aug 27, 2024
1.8.7 Aug 05, 2024
1.8.6 Aug 05, 2024
1.8.5 Mar 26, 2024
1.8.4 Mar 07, 2024
1.8.3 Mar 03, 2024
1.8.2 Mar 03, 2024
1.7.1 Nov 25, 2023
1.7.0 Apr 02, 2023
1.6.4 Mar 19, 2023
1.6.3 Feb 16, 2023
1.6.1 Jan 09, 2023
1.6.0 Dec 26, 2022
1.5.3 Oct 20, 2022
1.5.2 Sep 28, 2022
1.5.1 Sep 20, 2022
1.5.0 Sep 18, 2022
1.4.0 Jul 17, 2022
1.3.1 Mar 09, 2022
1.3.0 Mar 05, 2022
1.2.3 Jan 11, 2022
1.2.2 Nov 25, 2021
1.2.1 Nov 21, 2021
1.2.0 Nov 20, 2021
1.1.1 Sep 12, 2021
1.1.0 Aug 01, 2021
1.0.0 Jul 21, 2021
0.13.1 Jun 25, 2021
0.13.0 Jun 15, 2021
0.12.0 Jun 10, 2021
0.11.1 Jun 07, 2021
0.10.0 May 30, 2021
0.9.0 May 23, 2021
0.8.1 May 15, 2021
0.8.0 May 02, 2021
0.7.1 Apr 28, 2021
0.7.0 Apr 18, 2021
0.6.1 Apr 16, 2021
0.6.0 Apr 04, 2021
0.5.9 Feb 22, 2021
0.5.8 Feb 20, 2021
0.5.7 Jan 26, 2021
0.5.6 Dec 29, 2020
0.5.5 Dec 10, 2020
0.5.4 Dec 06, 2020
0.5.3 Dec 04, 2020
0.5.2 Nov 30, 2020
0.5.1 Nov 25, 2020
0.5.0 Nov 22, 2020
0.4.1 Nov 11, 2020
0.4.0 Nov 05, 2020
0.3.6 Oct 30, 2020
0.3.5 Oct 25, 2020
0.3.4 Oct 23, 2020
0.3.3 Oct 21, 2020
0.3.2 Oct 17, 2020
0.3.1 Oct 16, 2020
0.3.0 Oct 12, 2020
0.2.3 Oct 06, 2020
0.2.2 Oct 01, 2020
0.2.1 Sep 27, 2020
0.2.0 Sep 26, 2020
0.1.32 Sep 22, 2020
0.1.31 Sep 18, 2020
0.1.30 Sep 16, 2020
0.1.29 Sep 08, 2020
0.1.28 Sep 06, 2020
0.1.27 Sep 04, 2020
0.1.26 Sep 02, 2020
0.1.25 Sep 01, 2020
0.1.24 Aug 31, 2020
0.1.23 Aug 22, 2020
0.1.22 Aug 16, 2020
0.1.21 Aug 09, 2020
0.1.20 Aug 04, 2020
0.1.19 Aug 02, 2020
0.1.18 Aug 02, 2020
0.1.17 Aug 01, 2020
0.1.16 Aug 01, 2020
0.1.15 Jul 31, 2020
0.1.14 Jul 30, 2020
0.1.13 Jul 28, 2020
0.1.12 Jul 26, 2020
0.1.11 Jul 26, 2020
0.1.10 Jul 24, 2020
0.1.9 Jul 21, 2020
0.1.8 Jul 21, 2020
0.1.7 Jul 19, 2020
0.1.6 Jul 19, 2020
0.1.5 Jul 19, 2020
0.1.4 Jul 18, 2020
0.1.3 Jul 18, 2020
0.1.2 Jul 17, 2020

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
autopep8 (>=1.5)
ipython (>=7.8.0)
tokenize-rt (>=3.2.0)
tomli