https://github.com/wasm-fmt/ruff_fmt
A WASM Based Python Formatter
https://github.com/wasm-fmt/ruff_fmt
dprint formatter formatting python ruff wasm webassembly
Last synced: 3 months ago
JSON representation
A WASM Based Python Formatter
- Host: GitHub
- URL: https://github.com/wasm-fmt/ruff_fmt
- Owner: wasm-fmt
- License: mit
- Created: 2023-08-08T14:21:58.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2026-03-22T12:47:08.000Z (3 months ago)
- Last Synced: 2026-03-23T04:26:00.698Z (3 months ago)
- Topics: dprint, formatter, formatting, python, ruff, wasm, webassembly
- Language: Rust
- Homepage:
- Size: 824 KB
- Stars: 14
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/wasm-fmt/ruff_fmt/actions/workflows/test.yml)
# Install
[](https://www.npmjs.com/package/@wasm-fmt/ruff_fmt)
```bash
npm install @wasm-fmt/ruff_fmt
```
[](https://jsr.io/@fmt/ruff-fmt)
```bash
npx jsr add @fmt/ruff-fmt
```
# Usage
## Node.js / Deno / Bun / Bundler
```javascript
import { format } from "@wasm-fmt/ruff_fmt";
const input = `x = { 'a':37,'b':42,
'c':927}
y = 'hello ''world'
z = 'hello '+'world'
a = 'hello {}'.format('world')
class foo ( object ):
def f (self ):
return 37*-+2
def g(self, x,y=42):
return y
def f ( a ) :
return 37+-+a[42-x : y**3]`;
const formatted = format(input, "main.py", {
indent_style: "space",
indent_width: 4,
line_width: 88,
quote_style: "double",
magic_trailing_comma: "respect",
});
console.log(formatted);
```
## Web
For web environments, you need to initialize WASM module manually:
```javascript
import init, { format } from "@wasm-fmt/ruff_fmt/web";
await init();
const input = `x = { 'a':37,'b':42,
'c':927}`;
const formatted = format(input, "main.py");
console.log(formatted);
```
### Vite
```JavaScript
import init, { format } from "@wasm-fmt/ruff_fmt/vite";
await init();
// ...
```
Or use the `./bundler` entry with [vite-plugin-wasm](https://www.npmjs.com/package/vite-plugin-wasm)
```javascript
import { format } from "@wasm-fmt/ruff_fmt/bundler";
```
## Entry Points
- `.` - Auto-detects environment (Node.js uses node, Webpack uses bundler, default is ESM)
- `./node` - Node.js environment (no init required)
- `./esm` - ESM environments like Deno (no init required)
- `./bundler` - Bundlers like Webpack (no init required)
- `./web` - Web browsers (requires manual init)
- `./vite` - Vite bundler (requires manual init)
# dprint plugin
> [!NOTE]
> dpint plugin is deprecated, please use https://dprint.dev/plugins/ruff instead.
# How does it work?
[Ruff] is an extremely fast Python linter, written in Rust.
This package is a WebAssembly build of Ruff formatter, with a JavaScript wrapper.
[Ruff]: https://github.com/astral-sh/ruff