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

demo

Table of contents

๐ŸŽ‰ Installation

In your virtual environment, run one of the following:

  • python -m pip install -U nbqa (minimal installation)
  • python -m pip install -U nbqa[toolchain] (install supported code quality tools as well)
  • conda install -c conda-forge nbqa (if you use conda)

๐Ÿš€ Examples

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 autoflake, check-ast, doctest, flake8, mypy, and pylint.

Pre-commit

Here's an example of how to set up some pre-commit hooks:

  1. Put this in your pyproject.toml file (see configuration for details)

    [tool.nbqa.mutate]
    isort = 1
    black = 1
    pyupgrade = 1
    
    [tool.nbqa.addopts]
    pyupgrade = ["--py36-plus"]
    
  2. Put this in your .pre-commit-config.yaml file (see usage as pre-commit hook)

    - repo: https://github.com/nbQA-dev/nbQA
      rev: 0.5.2
      hooks:
        - id: nbqa-black
          additional_dependencies: [black==20.8b1]
        - id: nbqa-pyupgrade
          additional_dependencies: [pyupgrade==2.7.3]
        - id: nbqa-isort
          additional_dependencies: [isort==5.6.4]
    

๐Ÿฅณ Used by

Take some inspiration from their config files ๐Ÿ˜‰

๐Ÿ’ฌ 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

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

๐Ÿ›

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

Uploaded Source

Built Distribution

nbqa-0.5.2-py2.py3-none-any.whl (32.7 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: nbqa-0.5.2.tar.gz
  • Upload date:
  • Size: 33.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.5

File hashes

Hashes for nbqa-0.5.2.tar.gz
Algorithm Hash digest
SHA256 4bdc82181c77464706594586a17759c2b2caaa9284d1fe765d3d9a3b73c408cd
MD5 2d1b419446928ee839c4484a0beaa331
BLAKE2b-256 608858eb0d2be9f8bce5268c31db136155e50828c829857187cf8f65916c3c55

See more details on using hashes here.

Provenance

File details

Details for the file nbqa-0.5.2-py2.py3-none-any.whl.

File metadata

  • Download URL: nbqa-0.5.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.5

File hashes

Hashes for nbqa-0.5.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9d114873294808aa5f04cc81bb67362d7460ba24faf1693f94ffb3585cd2586f
MD5 c0e11ef139a39302a9c00db7faac79c3
BLAKE2b-256 098b7b902e2880a0caa070f8ec3e39e21b618a79fe11996e3858815e35eb09d3

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