Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nbqa-dev/nbqa
Run ruff, isort, pyupgrade, mypy, pylint, flake8, and more on Jupyter Notebooks
https://github.com/nbqa-dev/nbqa
black codequality doctest flake8 isort jupyter-notebook lint mypy pre-commit pre-commit-hook pylint python pyupgrade ruff yapf
Last synced: about 2 hours ago
JSON representation
Run ruff, isort, pyupgrade, mypy, pylint, flake8, and more on Jupyter Notebooks
- Host: GitHub
- URL: https://github.com/nbqa-dev/nbqa
- Owner: nbQA-dev
- License: mit
- Created: 2020-07-11T15:30:54.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-11-18T20:41:37.000Z (about 24 hours ago)
- Last Synced: 2024-11-18T20:49:32.638Z (about 24 hours ago)
- Topics: black, codequality, doctest, flake8, isort, jupyter-notebook, lint, mypy, pre-commit, pre-commit-hook, pylint, python, pyupgrade, ruff, yapf
- Language: Python
- Homepage: https://nbqa.readthedocs.io/en/latest/index.html
- Size: 1.47 MB
- Stars: 1,050
- Watchers: 8
- Forks: 41
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Contributing: docs/contributing.rst
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
Run ruff, isort, pyupgrade, mypy, pylint, flake8, black, blacken-docs, and more on Jupyter Notebooks- β handles IPython magics robustly
- β respects your config files
- β preserves "quiet mode" trailing semicolons
- β lints both code and markdown cells## Table of contents
- [Table of contents](#table-of-contents)
- [π Installation](#-installation)
- [π Examples](#-examples)
- [Command-line](#command-line)
- [Pre-commit](#pre-commit)
- [π₯³ Used by](#-used-by)
- [π¬ Testimonials](#-testimonials)
- [π₯ Contributing](#-contributing)## π Installation
In your [virtual environment](https://realpython.com/python-virtual-environments-a-primer/), run (note: the `$` is not part of the command):
```console
$ python -m pip install -U nbqa
```To also install all supported linters/formatters:
```console
$ python -m pip install -U "nbqa[toolchain]"
```## π Examples
### Command-line
Reformat your notebooks with
[black](https://black.readthedocs.io/en/stable/):```console
$ nbqa black my_notebook.ipynb
reformatted my_notebook.ipynb
All done! β¨ π° β¨
1 files reformatted.
```Sort your imports with [isort](https://timothycrosley.github.io/isort/):
```console
$ nbqa isort my_notebook.ipynb --float-to-top
Fixing my_notebook.ipynb
```Upgrade your syntax with [pyupgrade](https://github.com/asottile/pyupgrade):
```console
$ nbqa pyupgrade my_notebook.ipynb --py37-plus
Rewriting my_notebook.ipynb
```Format your markdown cells with [blacken-docs](https://github.com/asottile/blacken-docs):
```console
$ nbqa blacken-docs my_notebook.ipynb --nbqa-md --nbqa-diff
Cell 2
------
--- my_notebook.ipynb
+++ my_notebook.ipynb
@@ -1,2 +1 @@
-First level heading
-===
+# First level headingTo apply these changes, remove the `--nbqa-diff` flag
```Format ``.md`` files saved via [Jupytext](https://github.com/mwouts/jupytext) (requires ``jupytext`` to be installed):
```console
$ nbqa black my_notebook.md
reformatted my_notebook.md
All done! β¨ π° β¨
1 files reformatted.
```See [command-line examples](https://nbqa.readthedocs.io/en/latest/examples.html) for examples involving [doctest](https://docs.python.org/3/library/doctest.html), [flake8](https://flake8.pycqa.org/en/latest/), [mypy](http://mypy-lang.org/), [pylint](https://github.com/PyCQA/pylint), [autopep8](https://github.com/hhatto/autopep8), [pydocstyle](http://www.pydocstyle.org/en/stable/), [yapf](https://github.com/google/yapf), and [ruff](https://github.com/charliermarsh/ruff/).
### Pre-commit
Here's an example of how to set up some pre-commit hooks: put this in your `.pre-commit-config.yaml` file (see [usage as pre-commit hook](https://nbqa.readthedocs.io/en/latest/pre-commit.html))
```yaml
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.9.1
hooks:
- id: nbqa-black
additional_dependencies: [jupytext] # optional, only if you're using Jupytext
- id: nbqa-pyupgrade
args: ["--py37-plus"]
- id: nbqa-isort
args: ["--float-to-top"]
```If you need to select specific versions of these linters/formatters,
add them to [`additional_dependencies`](http://pre-commit.com/#pre-commit-configyaml---hooks).## π₯³ Used by
Click here for (non-exhaustive) list of repos
- https://github.com/ComPWA/ampform
- https://github.com/ComPWA/tensorwaves
- https://github.com/DataS-DHSC/os-maps-example
- https://github.com/Eazhi/World-Happiness-Analysis
- https://github.com/GoogleCloudPlatform/ai-platform-samples
- https://github.com/MRCIEU/epigraphdb
- https://github.com/OpenMined/PyDP
- https://github.com/PlasmaPy/PlasmaPy
- https://github.com/ProjectPythia/pythia-foundations
- https://github.com/SeldonIO/alibi
- https://github.com/TeoZosa/deep-learning-v2-pytorch
- https://github.com/WM-SEMERU/mlproj_template
- https://github.com/alan-turing-institute/sktime
- https://github.com/amor71/LiuAlgoTrader
- https://github.com/bbernst/base_envs
- https://github.com/cheginit/HyRiver-examples
- https://github.com/cheginit/pygeohydro
- https://github.com/cheginit/pynhd
- https://github.com/covid-19-impact-lab/sid-germany
- https://github.com/covid-19-impact-lab/sid
- https://github.com/dapperfu/Python-Simulink
- https://github.com/deepcharles/ruptures
- https://github.com/dhassault/cyclegan_pytorch
- https://github.com/gboeing/osmnx
- https://github.com/glotzerlab/freud-examples
- https://github.com/glotzerlab/hoomd-examples
- https://github.com/glotzerlab/signac-docs
- https://github.com/glotzerlab/signac-examples
- https://github.com/grapl-security/grapl
- https://github.com/hainegroup/oceanspy
- https://github.com/henryiii/python-compiled-minicourse
- https://github.com/intake/intake-esm
- https://github.com/jameslamb/lightgbm-dask-testing
- https://github.com/jdb78/pytorch-forecasting
- https://github.com/jhrcook/advent-of-code_2020
- https://github.com/julian-west/asset_price_correlations
- https://github.com/kratsg/drstorage
- https://github.com/madebr/pyOpt
- https://github.com/matthewfeickert/heputils
- https://github.com/matyama/deep-rl-hands-on
- https://github.com/mayou36/raredecay
- https://github.com/neomatrix369/nlp_profiler
- https://github.com/openforcefield/openff-system
- https://github.com/pandas-profiling/pandas-profiling
- https://github.com/paw-lu/dotfiles
- https://github.com/pawamoy/wps-light
- https://github.com/phinate/clarinet
- https://github.com/pik-primap/climate_categories
- https://github.com/pik-primap/primap2
- https://github.com/pik-primap/unfccc_di_api
- https://github.com/pymc-devs/pymc-examples
- https://github.com/pymc-devs/resources
- https://github.com/saturncloud/examples
- https://github.com/scikit-hep/boost-histogram
- https://github.com/scikit-hep/iminuit
- https://github.com/scikit-hep/mplhep
- https://github.com/scikit-hep/pyhf
- https://github.com/scikit-hep/pylhe
- https://github.com/v-goncharenko/data-science-template
- https://github.com/wemake-services/wemake-python-styleguide
- https://github.com/zfit/phasespace
- https://github.com/zfit/zfit
- https://github.com/zfit/zfit-physics
- https://github.com/zfit/zfit-tutorialsIs your project missing? Let us know, or open a pull request!
## π¬ Testimonials
**Michael Kennedy & Brian Okken**, [hosts of the Python Bytes podcast](https://pythonbytes.fm/episodes/show/204/take-the-psf-survey-and-will-carlton-drop-by):
> 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](https://github.com/nbQA-dev/nbQA/issues/386#issuecomment-718046313):
> It is amazing!
**Alex Andorra**,
[Data Scientist, ArviZ & PyMC Dev, Host of 'Learning Bayesian Statistics' Podcast](https://github.com/pymc-devs/pymc3/pull/4074#pullrequestreview-482589774):> well done on `nbqa` @MarcoGorelli ! Will be super useful in CI
**Matthew Feickert**,
[Postdoc at University of Illinois working on LHC physics](https://twitter.com/HEPfeickert/status/1324823925898027008):> 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](https://github.com/nbQA-dev/nbQA/issues/164#issuecomment-674529528):> thanks a lot for your effort to create such a useful tool
**Simon Brugman**, [Data scientist & pandas-profiling dev](https://github.com/nbQA-dev/nbQA/pull/490):
> nbQA helps us to keep notebooks to the same standards as the rest of the code. If you're serious about your code standards, you should keep them consistent across both notebooks and python scripts. Great addition to the ecosystem, thanks!
**Bradley Dice**, [PhD Candidate in Physics & Scientific Computing](https://github.com/nbQA-dev/nbQA/pull/547#issuecomment-786186156):
> nbqa is a clean, easy to use, and effective tool for notebook code style. Formatting and readability makes a huge difference when rendering notebooks in a project's documentation!
**James Lamb**, [engineer @saturn_cloud, LightGBM maintainer](https://twitter.com/_jameslamb/status/1346537148913221634)
> today I learned about `nbqa`, a command-line tool to run linters like `flake8` over #Python code in @ProjectJupyter notebooks. Thanks to @jayyqi for pointing me to it. So far, I really really like it.
**Lars Yencken**, [Tech Lead @ Our World In Data](https://twitter.com/larsyencken/status/1398171287974039553)
> Super useful! I only wish it was built-in to Jupyterlab.
**Vincent D. Warmerdam**, [maintainer @ calmcode.io](https://calmcode.io/shorts/nbqa.html)
> Nice. nbQA looks like a great way to prevent the Untitled12.ipynb-phenomenon. I like!
**Mani Sarkar**, [Kaggle 3x expert, contributor](https://neomatrix369.wordpress.com/about/)
> nbQA is an inspiring project, and the team behind it are very knowledgeable and think of things outside the box with ideas and solutions
## π₯ Contributing
I will give write-access to anyone who makes a useful pull request - see the
[contributing guide](https://nbqa.readthedocs.io/en/latest/contributing.html)
for details on how to do so.Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/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
π
John Sandall
π
Nathan Cooper
π
agruenberger
π
Rafal Wojdyla
π
Bradley Dice
π€ π»
Ivan Cheung
π
Tony Hirst
π
Taneli Hukkinen
π§
Tom Begley
π€ π» π
Steven DeMartini
π
vincent d warmerdam
β
Daniel Sparing
π
asdfCYBER
π
Chris Knight
π
Laura Richter
π€
Francesco Ballarin
π
Janosh Riebesell
π π
Nicolas Oliver
π
Bas Nijholt
π€
Ralf Gommers
π€
Toon Verstraelen
π
Trinh Quoc Anh
π
Martin K. Scherer
π»
Felix Williams
π π π
Florian BΓ€r
π
Michael Kennedy
π
Brian Okken
π
Sydney
π
fvonbergen
π
GaΓ©tan Lepage
β οΈ
Anurag Nayak
π π
Min RK
π»
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification.
Contributions of any kind welcome!