Skip to main content

µfmt

Safe, atomic formatting with black and µsort

version documentation changelog license build status code coverage

µfmt is a safe, atomic code formatter for Python built on top of black and µsort:

Black makes code review faster by producing the smallest diffs possible. Blackened code looks the same regardless of the project you’re reading.

μsort is a safe, minimal import sorter. Its primary goal is to make no “dangerous” changes to code, and to make no changes on code style.

µfmt formats files in-memory, first with µsort and then with black, before writing any changes back to disk. This enables a combined, atomic step in CI/CD workflows for checking or formatting files, without any with conflict or intermediate changes between the import sorter and the code formatter.

Install

µfmt requires Python 3.6 or newer. You can install it from PyPI:

$ pip install ufmt

If you want to prevent unexpected formatting changes that can break your CI workflow, make sure to pin your transitive dependencies–including black, µsort, and µfmt–to your preferred versions.

If you use requirements.txt, this might look like:

black==20.8b1
ufmt==1.2
usort==0.6.3

Usage

To format one or more files or directories in place:

$ ufmt format <path> [<path> ...]

To validate files are formatted correctly, like for CI workflows:

$ ufmt check <path> [<path> ...]

To validate formatting and generate a diff of necessary changes:

$ ufmt diff <path> [<path> ...]

License

µfmt is copyright John Reese, and licensed under the MIT license. I am providing code in this repository to you under an open source license. This is my personal repository; the license you receive to my code is from me and not from my employer. See the LICENSE file for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ufmt-1.2.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ufmt-1.2-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file ufmt-1.2.tar.gz.

File metadata

  • Download URL: ufmt-1.2.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for ufmt-1.2.tar.gz
Algorithm Hash digest
SHA256 2493bb47ec9181b362408b5a8ae303cd754cec74b6ef947818bf54ec4cb102c5
MD5 8e6e77b1fdb5808a27c4065919b4e705
BLAKE2b-256 c3f829138f0e04a0cd4ea23f7c54534b9417d05ea373818c011665b558eb2e89

See more details on using hashes here.

File details

Details for the file ufmt-1.2-py3-none-any.whl.

File metadata

  • Download URL: ufmt-1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for ufmt-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 391473b7630046020ea1a57cfd84f7aae909b83f204df10d0027ccb22ca47a6a
MD5 78329750566573cb2de18570997b8b4a
BLAKE2b-256 0df2b4a6d55598391b1f3b336fedbdfb07574dc288b339a302f8223117026e33

See more details on using hashes here.

Release history Release notifications | RSS feed

2.9.1

2 files

2.9.0

2 files

2.8.0

2 files

2.7.3

2 files

2.7.2

2 files

2.7.1

2 files

2.7.0

2 files

2.6.0

2 files

2.5.1

2 files

2.5.0

2 files

2.4.0

2 files

2.3.0

2 files

2.2.0

2 files

2.1.0

2 files

2.0.1

2 files

2.0.0

2 files

1.3.3

2 files

1.3.2

2 files

1.3.1.post1

2 files

1.3.1

2 files

1.3.0

2 files

1.2.1

2 files

This release

1.2 This release

2 files

1.1

2 files

1.0

2 files

0

2 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