Skip to main content

Run any standard Python code quality tool on a Jupyter Notebook

Project description

nbQA

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

🚀 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 tests/data/notebook_for_testing.ipynb --nbqa-md --nbqa-diff
Cell 2
------
--- tests/data/notebook_for_testing.ipynb
+++ tests/data/notebook_for_testing.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.0
  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

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

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nbqa-1.2.0.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

nbqa-1.2.0-py3-none-any.whl (36.1 kB view details)

Uploaded Python 3

File details

Details for the file nbqa-1.2.0.tar.gz.

File metadata

  • Download URL: nbqa-1.2.0.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for nbqa-1.2.0.tar.gz
Algorithm Hash digest
SHA256 5f60dfd9d24f345daab90d6cbab52a6bf20d28b8a4d1fd5fbb076f3bfdb0ef2b
MD5 de15c1c3b585ee04ce889df5f60da2a5
BLAKE2b-256 53ddb6feae609de85197499072db4d8638e03f6c38f2e84d072a7646cef02120

See more details on using hashes here.

Provenance

File details

Details for the file nbqa-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: nbqa-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 36.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for nbqa-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4259e06f61b5b470bdc8099656bcc562b82c2b8e818820589434582e22669f1a
MD5 ea0bd187513499c14ec9b3f33911037c
BLAKE2b-256 1ce88b1060f9f3f5bc6f9374f85d0b6de58e9dd69eab7a3f102978eaf65ddbdc

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page