Skip to main content

Run any Python code quality tool on a Jupyter Notebook!

Project description

https://github.com/MarcoGorelli/nbQA/raw/master/assets/output-onlinepngtools.png

nbQA

https://dev.azure.com/megorelli/megorelli/_apis/build/status/MarcoGorelli.nbQA?branchName=master https://img.shields.io/azure-devops/coverage/megorelli/megorelli/1/master.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

Adapter to run any code-quality tool on a Jupyter notebook. Documentation is hosted here.

Prerequisites

If you don’t have pip installed, this Python installation guide can guide you through the process.

Installation

Install nbqa with

$ pip install nbqa

Check your installation with

$ nbqa --version
nbqa 0.1.3

Quickstart

The general syntax is

nbqa <command> <notebook or directory> <flags>

For example, you could run:

$ nbqa flake8 my_notebook.ipynb
$ nbqa black my_notebook.ipynb --check
$ nbqa mypy my_notebook.ipynb --ignore-missing-imports
$ nbqa pytest my_notebook.ipynb --doctest-modules

You can also pass an entire directory instead of a single file, e.g. nbqa flake8 my_notebooks.

Examples

Format your notebooks using black:

$ nbqa black .
reformatted tweet-sentiment-roberta-pytorch.ipynb
All done!  🍰 
1 files reformatted.

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 any examples in your docstrings are correct:

$ nbqa pytest tweet-sentiment-roberta-pytorch.ipynb --doctest-modules
============================= test session starts ==============================
platform linux -- Python 3.8.2, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
rootdir: /home/marco/tweet-sentiment-extraction
plugins: cov-2.10.0
collected 3 items

tweet-sentiment-roberta-pytorch.ipynb .                                  [100%]

============================== 1 passed in 0.03s ===============================

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:

See Also

Here are some other code quality tools for Jupyter Notebooks:

Project template from cookiecutter.

History

0.1.2 (2020-07-17)

  • First release on PyPI.

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.3.tar.gz (122.3 kB view hashes)

Uploaded Source

Built Distribution

nbqa-0.1.3-py3-none-any.whl (14.3 kB view hashes)

Uploaded Python 3

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