https://github.com/dfm/black_nbconvert
Apply black to ipynb files
https://github.com/dfm/black_nbconvert
Last synced: about 1 year ago
JSON representation
Apply black to ipynb files
- Host: GitHub
- URL: https://github.com/dfm/black_nbconvert
- Owner: dfm
- License: mit
- Created: 2019-10-02T01:41:48.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-03-03T20:05:51.000Z (about 1 year ago)
- Last Synced: 2025-04-11T05:39:46.059Z (about 1 year ago)
- Language: Python
- Homepage:
- Size: 47.9 KB
- Stars: 46
- Watchers: 4
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# black natively supports Jupyter notebooks
**This project is no longer necessary!**
To replace your `black_nbconvert` `pre-commit` configuration, use:
```yaml
- repo: https://github.com/psf/black
rev: "22.1.0"
hooks:
- id: black-jupyter
```
If you're still using this project, the original README is below:
# black + nbconvert
Tired of having to *think* about formatting in Jupyter notebooks?
Look no further!
This script will correctly format your Jupyter notebooks for you using [black](https://black.readthedocs.io).
**Warning: This project will overwrite your notebooks in place.
It shouldn't change anything except the format, but use at your own risk!**
## Installation & Usage
To install:
```bash
pip install black_nbconvert
```
To check a notebook:
```bash
black_nbconvert --check /path/to/a/notebook.ipynb
```
To fix the formatting in a notebook (in place):
```bash
black_nbconvert /path/to/a/notebook.ipynb
```
If you pass a directory instead of a notebook file, notebooks will be found recursively below that directory.
For example:
```bash
black_nbconvert .
```
will fix the formatting for all notebooks in the current directory and (recursively) below.
*Configuration:* Configuration for `black` in a `pyproject.toml` file above the target files will be respected.
## Version control integration
Use [pre-commit](https://pre-commit.com/).
Once you [have it installed](https://pre-commit.com/#install), add this to the `.pre-commit-config.yaml` in your repository:
```yaml
repos:
- repo: https://github.com/dfm/black_nbconvert
rev: v0.3.0
hooks:
- id: black_nbconvert
```
Then run `pre-commit install` and you're ready to go.