Skip to main content

flake8-nb

PyPi Version Conda Version Supported Python Versions Pre-commit License

Actions Status Documentation Status Testing Coverage Documentation Coverage

Codacy Badge All Contributors Code style Python: black Binder

flake8 checking for jupyter notebooks.

This tool is mainly aimed towards writing tutorials/lecture material, where one might also want to show off bad practices and/or errors, while still keeping the rest of the code clean and without adding the complexity of tooling to the readers (see docs on cell tags).

Basically this is a hack on the flake8's Application class, which adds parsing and a cell based formatter for *.ipynb files.

This is NOT A PLUGIN but a stand alone CLI tool/pre-commit hook to be used instead of the flake8 command/hook.

Features

  • flake8 CLI tests for jupyter notebooks
  • Full base functionality of flake8 and its plugins
  • Input cell based error formatting (Execution count/code cell count/total cellcount)
  • Report fine tuning with cell-tags (flake8-noqa-tags see usage)
  • pre-commit hook

Examples

Default reporting

If you had a notebook with name example_notebook.ipynb, where the code cell which was executed as 34th cell (In[34]) had the following code:

bad_formatted_dict = {"missing":"space"}

running flake8_nb would result in the following output.

Execution count

$ flake8_nb example_notebook.ipynb
example_notebook.ipynb#In[34]:1:31: E231 missing whitespace after ':'

Custom reporting

If you prefer the reports to show the cell number rather then the execution count you can use the --notebook-cell-format option, given that the cell is the 5th code cell and 10th total cell (taking raw and markdown cells into account), you will get the following output.

Code cell count

$ flake8_nb --notebook-cell-format '{nb_path}:code_cell#{code_cell_count}' example_notebook.ipynb
example_notebook.ipynb:code_cell#5:1:31: E231 missing whitespace after ':'

Total cell count

$ flake8_nb --notebook-cell-format '{nb_path}:cell#{total_cell_count}' example_notebook.ipynb
example_notebook.ipynb:cell#10:1:31: E231 missing whitespace after ':'

Similar projects

  • nbQA: Run isort, pyupgrade, mypy, pylint, flake8, mdformat, black, blacken-docs, and more on Jupyter Notebooks

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Sebastian Weigand
Sebastian Weigand

💻 🤔 🚧 📆 🚇 ⚠️ 📖
Jt Miclat
Jt Miclat

🐛
Philipp Eisenhauer
Philipp Eisenhauer

🐛
Shoma Okamoto
Shoma Okamoto

⚠️
Marco Gorelli
Marco Gorelli

🔧 📖
Tony Hirst
Tony Hirst

🤔
Dobatymo
Dobatymo

🐛
Alp Arıbal
Alp Arıbal

🐛
1kastner
1kastner

🐛
Dominique Sydow
Dominique Sydow

🐛
Liam Keegan
Liam Keegan

🐛 💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Release files for flake8-nb 0.5.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flake8-nb 0.5.3
File Size Uploaded
flake8_nb-0.5.3.tar.gz 37.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flake8-nb 0.5.3
File Interpreter ABI Platform
flake8_nb-0.5.3-py3-none-any.whl Python 3 none any Details

Total release size: 61.5 kB

Release files / flake8_nb-0.5.3.tar.gz

Download URL flake8_nb-0.5.3.tar.gz
Size 37.8 kB
Tags Source
SHA-256 checksum
How to use checksums
00b447f4a4d649f85e35aad437d3df1477115dce081bc364f09d718cf928ca75
BLAKE2b-256 checksum
How to use checksums
b1e8660afa7a10f8211145d82a9b74affd9407b1c9f06459bfe92320f7ada850
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.2

Release files / flake8_nb-0.5.3-py3-none-any.whl

Download URL flake8_nb-0.5.3-py3-none-any.whl
Size 23.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
09f6287a3dd3147c2abe8ed9d807042b414befa4755a935a124b5a3674044952
BLAKE2b-256 checksum
How to use checksums
1ecbf27f39623e441c74148175068abb3ec9b766afe4254177adeed8be297f53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.5.3 This release

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page