Skip to main content

Run any Python code quality tool on a Jupyter Notebook!

Project description

https://github.com/nbQA-dev/nbQA/raw/master/assets/logo.png

nbQA

https://github.com/nbQA-dev/nbQA/workflows/tox/badge.svg https://codecov.io/gh/nbQA-dev/nbQA/branch/master/graph/badge.svg https://badge.fury.io/py/nbqa.svg https://readthedocs.org/projects/nbqa/badge/?version=latest&style=plastic https://img.shields.io/pypi/pyversions/nbqa.svg https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white http://www.mypy-lang.org/static/mypy_badge.svg https://interrogate.readthedocs.io/en/latest/_static/interrogate_badge.svg https://img.shields.io/badge/code%20style-black-000000.svg https://img.shields.io/badge/pylint-10/10-brightgreen.svg

Adapter to run any code-quality tool on a Jupyter notebook. This is intended to be run as a pre-commit hook and/or during continuous integration.

Documentation is hosted here.

Installation

Install nbqa with pip:

$ pip install nbqa

Quickstart

The general syntax is

nbqa <command> <notebook or directory> <args>

where command is any standard Python code quality tool.

Examples

Check static type annotations:

$ nbqa mypy tweet-sentiment-roberta-pytorch.ipynb --ignore-missing-imports
tweet-sentiment-roberta-pytorch.ipynb:cell_10:5: error: Argument "batch_size" to "get_test_loader" has incompatible type "str"; expected "int"

Check the examples in your docstrings are correct:

$ nbqa doctest tweet-sentiment-roberta-pytorch.ipynb

Format your notebooks using black:

$ nbqa black . --line-length=96 --nbqa-mutate
reformatted tweet-sentiment-roberta-pytorch.ipynb
All done!  🍰 
1 files reformatted.

Configuration

You can configure nbQA either at the command line, or by using a .nbqa.ini file. We’ll see some examples below.

Extra flags

If you wish to pass extra flags (e.g. --ignore W503 to flake8) you can either run

nbqa flake8 my_notebook.ipynb --ignore W503

or you can put the following in your .nbqa.ini file

[flake8]
addopts = --ignore W503

Config file

If you already have a config file for your third-party tool (e.g. .mypy.ini for mypy), you can run

nbqa mypy my_notebook.ipynb --nbqa-config .mypy.ini

or you can put the following in your .nbqa.ini file

[mypy]
config = .mypy.ini

Allow mutations

By default, nbQA won’t modify your notebooks. If you wish to let your third-party tool modify your notebooks, you can either pass the --nbqa-mutate flag at the command-line, e.g.

nbqa black my_notebook.ipynb --nbqa-mutate

or you can put the following in your .nbqa.ini file

[black]
mutate = 1

Usage as pre-commit hook

If you want to use nbqa with pre-commit, here’s an example of what you could add to your .pre-commit-config.yaml file:

- repo: https://github.com/nbQA-dev/nbQA
  rev: 0.1.27
  hooks:
    - id: nbqa
      args: ['flake8']
      name: nbqa-flake8
      alias: nbqa-flake8
      additional_dependencies: ['flake8']
    - id: nbqa
      args: ['isort', '--nbqa-mutate']
      name: nbqa-isort
      alias: nbqa-isort
      additional_dependencies: ['isort']
    - id: nbqa
      args: ['mypy']
      name: nbqa-mypy
      alias: nbqa-mypy
      additional_dependencies: ['mypy']

Supported third party packages

In theory, nbqa can adapt any Python code-quality tool to a Jupyter Notebook.

In practice, here are the tools it’s been tested with:

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.

See Also

Here are some other code quality tools for Jupyter Notebooks:

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

Uploaded Source

Built Distribution

nbqa-0.1.27-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nbqa-0.1.27.tar.gz
  • Upload date:
  • Size: 18.6 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.2

File hashes

Hashes for nbqa-0.1.27.tar.gz
Algorithm Hash digest
SHA256 f708414240e1a73055e8f3e1604055fe1d4f6627d4ab316fd192d12170e13878
MD5 edbea4fc6a06c809616104191707e600
BLAKE2b-256 27bdea546ea1d70849198d08af3d6ec747a8513da853c52f35b350bce5612ced

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: nbqa-0.1.27-py3-none-any.whl
  • Upload date:
  • Size: 17.9 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.2

File hashes

Hashes for nbqa-0.1.27-py3-none-any.whl
Algorithm Hash digest
SHA256 a6116a29b9bfbaf99dc1a2240d2f2d42e6926a2f5058a8ba420f8c8ab95a74f9
MD5 58c9319a4c06d96eede6eaa35f7fef9d
BLAKE2b-256 55663b71961c75fadc3b1544e9b3ab553824349f2b38af4109c2e01a7f85aa7b

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