nbqa is a command-line tool that allows you to run any standard Python code quality tool on Jupyter Notebooks. It robustly handles IPython magics, respects your existing configuration files (like `pyproject.toml`), and can lint both code and markdown cells. The current version is 1.9.1, with frequent minor point releases.
pip install nbqaNo compatibility data collected yet for this library.
This quickstart demonstrates how to install `nbqa` and `black`, then use `nbqa` to format a Jupyter Notebook. Remember to install the specific code quality tools (like `black`, `flake8`, `isort`) you wish to use alongside `nbqa`.
Review `nbqa`'s documentation on known limitations and how specific tool configurations interact with its conversion process. Consider alternative configuration methods via `pyproject.toml` or `nbqa`'s own `--nbqa-files` and `--nbqa-exclude` flags.
Use `--nbqa-dont-skip-bad-cells` cautiously for syntax errors. Be aware that magics like `%%time` or `%matplotlib inline` are generally ignored or cannot be processed by underlying tools.
Carefully manage your configuration sources. Prefer `pyproject.toml` for consistent project-wide settings and use command-line arguments only for temporary overrides or specific runs. Consult the documentation of the specific code quality tool for how it handles duplicate or conflicting arguments.
For interactive in-notebook formatting, consider JupyterLab extensions like `jupyterlab_code_formatter`. `nbqa` is best utilized as a pre-commit check or a batch process.
Manually review and update the versions of your `additional_dependencies` in your `.pre-commit-config.yaml` to ensure you are using the desired versions of code quality tools. Pinning versions is recommended for reproducibility.
Install the missing tool using pip; for example, `pip install black` or `pip install "nbqa[toolchain]"` to install all supported tools.
Ensure nbqa is installed (`pip install nbqa`) and that your Python scripts directory (e.g., `~/.local/bin` on Linux/macOS or `Scripts` in your Python installation on Windows) is correctly added to your system's PATH. Restart your terminal after making changes.
Inspect the code in the specified notebook cell for syntax errors or problematic IPython magics. You might need to adjust the code, or for certain magics, consider using `nbqa`'s `--nbqa-process-cells` flag. Upgrading both `nbqa` and `black` to their latest versions may also resolve compatibility issues.
Configure the linter to ignore these specific errors for notebooks. You can add `ignore = E302,E305` to your `pyproject.toml` or `.flake8` configuration file under the `[flake8]` section, or pass `--extend-ignore=E302,E305` directly to the `nbqa flake8` command.