Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

µfmt

Safe, atomic formatting with black and µsort

version documentation changelog license

µ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 chance of 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==22.3.0
ufmt==1.3.2
usort==1.0.2

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> ...]

pre-commit hook

µfmt provides a pre-commit hook. To format your diff before every commit, add the following to your .pre-commit-config.yaml file:

  - repo: https://github.com/omnilib/ufmt
    rev: v1.3.2
    hooks:
      - id: ufmt

You can change the rev to any version >= 1.3.0. To pin black and usort, use the additional_dependencies option:

    hooks: 
      - id: ufmt 
        additional_dependencies: 
          - black == 22.3.0
          - usort == 1.0.2

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-2.0.0rc1.tar.gz (66.6 kB view details)

Uploaded Source

Built Distribution

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

ufmt-2.0.0rc1-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file ufmt-2.0.0rc1.tar.gz.

File metadata

  • Download URL: ufmt-2.0.0rc1.tar.gz
  • Upload date:
  • Size: 66.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.1

File hashes

Hashes for ufmt-2.0.0rc1.tar.gz
Algorithm Hash digest
SHA256 90af13fdeef51624368dbdbf7e8903acd37e738f2533d35c929c1d75c9ce33a0
MD5 553f523b604e28caced2cc72b0fe5a2c
BLAKE2b-256 8cae8ee814adae16e81ae0a46f5f80ffb906ce38b7ace8a778c4eb9edb4e8c11

See more details on using hashes here.

File details

Details for the file ufmt-2.0.0rc1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for ufmt-2.0.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 de389839aca42a18b79f1d5832ac6f724b182fe8974ee4002bb44727d50276a1
MD5 d5b669db8235c22ba3a25b262dbff137
BLAKE2b-256 6d7814e5d025fd5d663384780cdeb8a22c007fdd9df3c8be3e5fbc65f2bb8de0

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

This release

2.0.0rc1 This release

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

1.2

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