Skip to main content
POST
Format Document

Overview

Automatically format your Python code according to PEP 8 style guidelines. This tool provides the same formatting you get from tools like Black, autopep8, or yapf.

Request

string
required
File URI (e.g., file:///workspace/main.py)
object
Formatting options

Response

array
Array of text edits to apply
number
Number of changes made

Example Request

Example Response

What Gets Formatted

Indentation

Consistent spaces/tabs and nesting levels

Line Length

Wraps long lines to stay under limit

Spacing

Proper spacing around operators and commas

Imports

Organizes and sorts import statements

Formatting Examples

Before and After

Import Organization

Line Wrapping

Formatting Styles

Choose your preferred line length:

Use Cases

Format on Save

Pre-Commit Hook

Code Review Automation

Configuration Options

Tab Size

Line Length

Performance Tips

Format on Demand: Don’t format constantly - only on save or commit
Cache Results: If file hasn’t changed, formatting result is the same
Batch Format: Format multiple files in sequence, not parallel

Error Responses

Rate Limits

Best Practices

Team Consistency: Use the same line length across your team
Version Control: Configure formatting before committing to avoid large diffs
IDE Integration: Set up format-on-save in your editor
CI/CD: Add formatting checks to your build pipeline

Get Diagnostics

Check for style violations

Apply Workspace Edit

Apply formatting changes

Get Code Actions

Get quick fixes for issues

Rename Symbol

Refactor code safely