{"id":13520334,"url":"https://github.com/disrupted/blackd-client","last_synced_at":"2025-03-31T16:31:16.990Z","repository":{"id":38330256,"uuid":"362433428","full_name":"disrupted/blackd-client","owner":"disrupted","description":"⬛ Faster Python code formatting using Black","archived":false,"fork":false,"pushed_at":"2023-07-18T08:15:22.000Z","size":168,"stargazers_count":26,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-23T23:47:02.649Z","etag":null,"topics":["blackd","formatter","neovim","python","python-black","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/disrupted.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-28T10:51:14.000Z","updated_at":"2024-06-07T23:48:50.320Z","dependencies_parsed_at":"2024-06-07T23:48:47.730Z","dependency_job_id":"87c2c5e1-6bcf-42ef-b864-89269f3b68fe","html_url":"https://github.com/disrupted/blackd-client","commit_stats":{"total_commits":54,"total_committers":3,"mean_commits":18.0,"dds":0.2777777777777778,"last_synced_commit":"33d40f99cc27d04c5d8fc73c97ea763d08c55561"},"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/disrupted%2Fblackd-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/disrupted%2Fblackd-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/disrupted%2Fblackd-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/disrupted%2Fblackd-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/disrupted","download_url":"https://codeload.github.com/disrupted/blackd-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222670691,"owners_count":17020513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blackd","formatter","neovim","python","python-black","rust"],"created_at":"2024-08-01T05:02:17.875Z","updated_at":"2024-11-02T03:31:20.137Z","avatar_url":"https://github.com/disrupted.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# blackd-client\n\n\u003e Tiny HTTP client for the Black (`blackd`) Python code formatter\n\n[Black](https://github.com/psf/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.\n\nLuckily there's [blackd](https://black.readthedocs.io/en/stable/usage_and_configuration/black_as_a_server.html), 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.\n\n**blackd-client** is a simple helper that provides a single executable to communicate with Black, mainly for me to learn Rust.\n\nIf you're using Black (or writing Python code in general) I recommend you to check it out!\n\n## Install\n\n1. Install Black\n\n```sh\npip install black\n```\n\nor using Homebrew on macOS (preferred)\n\n```sh\nbrew install black\n```\n\n2. Install blackd-client\n\n- Download binary from https://github.com/disrupted/blackd-client/releases\n- Rename to `blackd-client` and put it somewhere on your `PATH`\n\nAlternatively if you have Rust toolchain installed:\n\n```sh\ncargo install blackd-client\n```\n\n3. Start blackd daemon\n\n```sh\nblackd\n```\n\nor as a launchd service using Homebrew on macOS (preferred)\n\n```sh\nsudo brew services start black\n```\n\n## Usage\n\npipe file contents to stdin, e.g.\n\n```sh\ncat main.py | blackd-client\n```\n\noutput is formatted using Black :sparkles:\n\n## Benchmark comparison\n\nNormal `black --fast`\n\n```sh\n❯ hyperfine 'cat subclean/core/parser.py | black --fast -'\n  Time (mean ± σ):     296.8 ms ±  41.3 ms    [User: 228.7 ms, System: 51.1 ms]\n  Range (min … max):   260.7 ms … 403.6 ms    10 runs\n```\n\nUsing `blackd-client`\n\n```sh\n❯ hyperfine 'cat subclean/core/parser.py | blackd-client'\n  Time (mean ± σ):      23.7 ms ±   3.7 ms    [User: 2.7 ms, System: 4.8 ms]\n  Range (min … max):    19.2 ms …  35.7 ms    84 runs\n```\n\n**Result:** blackd is more than 10x faster! :rocket:\n\n## Neovim integration\n\nEditor integration for Neovim can be done using a general purpose language server.\nThere are two options to choose from:\n\n1. [null-ls](https://github.com/disrupted/dotfiles/blob/1f5d36a195a41b602ca68d7629360e54654e3db2/.config/nvim/lua/plugins/lsp.lua#L33) (what I use)\n\n2. [EFM](https://github.com/disrupted/dotfiles/blob/253dc440ed954a4289a72dad885c71c16d0f90a4/.config/nvim/lua/efm/blackd.lua)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdisrupted%2Fblackd-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdisrupted%2Fblackd-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdisrupted%2Fblackd-client/lists"}