Skip to main content

Run any Python code quality tool on a Jupyter Notebook!

Project description

nbQA

Run any standard Python code quality tool on a Jupyter Notebook

tox codecov versions pre-commit chat

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 --treat-comment-as-code '# %%' --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 pylint, flake8, doctest, and mypy.

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.config]
    isort = "setup.cfg"
    black = "pyproject.toml"
    
    [tool.nbqa.mutate]
    isort = 1
    black = 1
    pyupgrade = 1
    
    [tool.nbqa.addopts]
    isort = ["--treat-comment-as-code", "# %%"]
    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.3.5
      hooks:
        - id: nbqa-black
        - id: nbqa-pyupgrade
        - id: nbqa-isort
    

🥳 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

Alex Andorra, Data Scientist, ArviZ & PyMC Dev, Host of 'Learning Bayesian Statistics' Podcast 🎙️:

well done on nbqa @MarcoGorelli ! Will be super useful in CI 😉

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 contributes anything useful (e.g. pull request / bug report) - 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

🐛

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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: nbqa-0.3.5.tar.gz
  • Upload date:
  • Size: 31.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5

File hashes

Hashes for nbqa-0.3.5.tar.gz
Algorithm Hash digest
SHA256 c0f28c88601ce47072006fe347d6769fe68284e7bfe9012ae7dc073acadac653
MD5 e40761516bcf8450bccd3fcbe57c0490
BLAKE2b-256 160feb0c236de25dac7ea2ec703e22fc570db06c7120fcc29bffbc6c7f3c3514

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: nbqa-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 29.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5

File hashes

Hashes for nbqa-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2313d22399a6ce5c77b2984b8fdfa7f6f38d0831861e1b084dd9f7f9220a8207
MD5 9f0590772717cf96c603b7f596efc634
BLAKE2b-256 e4e0b95edfddf047b17a4e607afac2e84914bec6bbf2a562e817f1cd49945752

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