Skip to main content

Watchdog-based Python auto-formatter using Ruff and Black

Project description

🧼 autofmt

A lightweight, extensible, and colorful CLI tool for automatically formatting Python files using Black and Ruff, triggered by real-time file changes via Watchdog. Ideal for developers who want instant feedback, enforced formatting, and smoother workflows.

🚀 Features

  • 🎯 Watches .py files in real time
  • 🧹 Auto-formats using Black and Ruff
  • 🧠 Runs Python syntax checks before formatting
  • 🎨 Beautiful, structured logs with Rich
  • 🔧 Supports user-defined config via pyproject.toml
  • 📂 Designed for easy integration and extension

📦 Installation

Install using your preferred Python package manager:

With uv

uv add autofmt

With pip

pip install autofmt

⚙️ Configuration

Configure behavior directly in your pyproject.toml under [tool.autofmt]:

[tool.autofmt]
watch_path = "."                 # Directory to watch
formatters = ["black", "ruff"]   # Tools to use
cooldown_seconds = 1.0           # Cooldown between re-runstrue)

🧠 Usage

Start the watcher

autofmt

It will:

  1. Watch for changes in Python files.
  2. Run syntax checks.
  3. Auto-format using Ruff and Black.
  4. Show you real-time logs and success/error messages.

📁 Example Output

starting autofmt watcher...
At: .

Detected change:
  src/autofmt/configurations/load_config.py

Ruff logs:
  src/autofmt/configurations/load_config.py
  All checks passed!

Formatted path:
  src/autofmt/configurations/load_config.py

Detected change:
  src/autofmt/configurations/load_config.py

Detected change:
  src/autofmt/configurations/load_config.py
^C
Stopping watcher...

❗ Requirements

  • Python >=3.13
  • OS Independent

🧪 Testing

Run tests using:

pytest

🛠️ Planned Features

  • 🧩 Plugin support for more formatters
  • 🧪 Test coverage reporting
  • 📊 Per-file formatter summary
  • ⌨️ Command-line flags (e.g., --path)
  • 📁 Multi-folder watch support

🤝 Contributing

Contributions are welcome! Please:

  1. Fork the repo
  2. Create a branch
  3. Submit a PR
  4. Discuss features in the issues

📄 License

MIT License. See the LICENSE file for full details.

👤 Author

For questions or assistance, contact Shailesh at shaileshpandit141@gmail.com

Project details


Download files

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

Source Distribution

autofmt-0.1.1.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

autofmt-0.1.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file autofmt-0.1.1.tar.gz.

File metadata

  • Download URL: autofmt-0.1.1.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.6

File hashes

Hashes for autofmt-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5e15e01672bf696e52c128896734d72b5368adcbcbc2838309e24c4bb429f74c
MD5 e4e6970a5fd0b842fd571666db286232
BLAKE2b-256 c355bc58f0b5a922a4bb8dbdb8c47e02aa30bc9450710fc9d64b77f351f96b50

See more details on using hashes here.

File details

Details for the file autofmt-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: autofmt-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.6

File hashes

Hashes for autofmt-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7f8a194b2d54d0bfad1e4dabd774ce37ef794e7fda4e4f81ce51ed031c119d2e
MD5 5aa3313999e10e33ff5777dd2bffc749
BLAKE2b-256 0961eb08514b768fcd17ac27b2de237c4b9c480562a611d33dc147ec6ef9223b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page