Skip to main content

Run any standard Python code quality tool on a Jupyter Notebook

Project description

nbQA

Run any standard Python code quality tool on a Jupyter Notebook

tox codecov pre-commit

versions chat docs

downloads

demo

Table of contents

๐ŸŽ‰ Installation

In your virtual environment, run one of the following:

  • python -m pip install -U nbqa
  • conda install -c conda-forge nbqa

๐Ÿš€ Examples

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: 0.13.1
  hooks:
    - id: nbqa-black
      args: [--nbqa-mutate]
    - id: nbqa-pyupgrade
      args: [--nbqa-mutate, --py36-plus]
    - id: nbqa-isort
      args: [--nbqa-mutate]

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

Command-line

Reformat your notebooks with black:

$ nbqa black my_notebook.ipynb --nbqa-mutate
reformatted my_notebook.ipynb
All done! โœจ ๐Ÿฐ โœจ
1 files reformatted.

Sort your imports with isort:

$ nbqa isort my_notebook.ipynb --nbqa-mutate
Fixing my_notebook.ipynb

Upgrade your syntax with pyupgrade:

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

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

๐Ÿฅณ 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.

๐Ÿ‘ฅ 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

๐Ÿ›

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-0.13.1.tar.gz (29.2 kB view details)

Uploaded Source

Built Distribution

nbqa-0.13.1-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nbqa-0.13.1.tar.gz
  • Upload date:
  • Size: 29.2 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.61.1 CPython/3.6.13

File hashes

Hashes for nbqa-0.13.1.tar.gz
Algorithm Hash digest
SHA256 4ccd86911e2ebf5ceb5e1244e44d73af68f44b0124dad40a74118037b727255e
MD5 cf88ba4ec99e1141d0150284c82861b2
BLAKE2b-256 bb840f97cce134b510ffa51c407afdbe84cf49a6c6b892251c33acce2cec125f

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: nbqa-0.13.1-py3-none-any.whl
  • Upload date:
  • Size: 29.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.61.1 CPython/3.6.13

File hashes

Hashes for nbqa-0.13.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3eb4ba8067dbc9c2f64c0f53ac3dcee156a0282ce8f083c379d085dfe3ada636
MD5 6971d7ee2c5a3afbcbee360e35c000e5
BLAKE2b-256 c749a09a1e29499dc4a8fd64754cf0f461d3b367f7c6fda69f7a521a4258ebc0

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