blackd-client
Tiny HTTP client for the Black (
blackd
) Python code formatter
Black is a brilliant, opinionated formatter for Python. However it can be quite slow when using an editor integration with format on save, since the process is cold-started every time you call it.
Luckily there's blackd, which is a small HTTP server that keeps the Black process running in the background so that it can be called directly without the lenghty startup time.
blackd-client is a simple helper that provides a single executable to communicate with Black, mainly for me to learn Rust.
If you're using Black (or writing Python code in general) I recommend you to check it out!
Install
- Install Black
or using Homebrew on macOS (preferred)
- Install blackd-client
- Download binary from https://github.com/disrupted/blackd-client/releases
- Rename to
blackd-client
and put it somewhere on yourPATH
Alternatively if you have Rust toolchain installed:
- Start blackd daemon
or as a launchd service using Homebrew on macOS (preferred)
Usage
pipe file contents to stdin, e.g.
|
output is formatted using Black :sparkles:
Benchmark comparison
Normal black --fast
)
)
Using blackd-client
)
)
Result: blackd is more than 10x faster! :rocket:
Neovim integration
Editor integration for Neovim can be done using a general purpose language server. There are two options to choose from: