Skip to main content

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!

Metadata

Release files for nbqa 1.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nbqa 1.9.1
File Size Uploaded Provenance Actions
nbqa-1.9.1.tar.gz 38.3 kB With provenance Details for nbqa-1.9.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nbqa 1.9.1
File Interpreter ABI Platform Actions
nbqa-1.9.1-py3-none-any.whl Python 3 none any Details for nbqa-1.9.1-py3-none-any.whl

Total release size: 73.6 kB

Release files / nbqa-1.9.1.tar.gz

Download URL nbqa-1.9.1.tar.gz
Size 38.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a1f4bcf587c597302fed295951001fc4e1be4ce0e77e1ab1b25ac2fbe3db0cdd
BLAKE2b-256 checksum
How to use checksums
aa7662d2609924cf34445148cd6b5de694cf64c179cc416cac93182579620e57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2024.

Transparency log

Release files / nbqa-1.9.1-py3-none-any.whl

Download URL nbqa-1.9.1-py3-none-any.whl
Size 35.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
95552d2f6c2c038136252a805aa78d85018aef922586270c3a074332737282e5
BLAKE2b-256 checksum
How to use checksums
28884789719fbbe166d12d345b3ac66b96105f10001b16e00a9765ba29261a21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2024.

Transparency log

Security for nbqa 1.9.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nbqa-1.9.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2024.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.9.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page