Skip to main content

def-form logo
Python function definition formatter

Ruff PyPI version PyPI downloads Coverage Status

Overview

def-form is a code formatting tool that focuses specifically on Python function definitions. It helps maintain consistent formatting of function signatures by automatically organizing arguments vertically when they exceed specified thresholds.

Long signatures are hard to scan, and different people break them differently — or not at all. def-form makes that choice for you and applies it everywhere: every definition past your threshold gets one argument per line, with a trailing comma.

Before:

def get_user(session: Session, user_id: int) -> User:
    ...


def create_user(session: Session, name: str, email: str, is_admin: bool = False) -> User:
    ...


class UserRepository:
    def search(self, query: str, *filters: str, limit: int = 20, **options) -> list[User]:
        ...

After def-form format (with max_inline_args = 2):

def get_user(session: Session, user_id: int) -> User:
    ...


def create_user(
    session: Session,
    name: str,
    email: str,
    is_admin: bool = False,
) -> User:
    ...


class UserRepository:
    def search(
        self,
        query: str,
        *filters: str,
        limit: int = 20,
        **options,
    ) -> list[User]:
        ...

get_user is left alone — it stays within the limits. Definitions that are already formatted this way are left untouched too, and a # def-form: skip comment excludes a single definition.

Features

  • Automatic argument formatting: Converts inline function arguments to vertical format based on configurable rules
  • CI/CD integration: Provides both format and check commands for use in development pipelines
  • Configuration file support: Uses pyproject.toml for project-specific settings
  • Customizable thresholds: Control when arguments should be formatted vertically

Installation

pip install def-form

Usage

Format code

  • Format all Python files in a directory:
def-form format src/
  • Format a specific file:
def-form format my_module.py

Check code without formatting

  • Check if code follows formatting rules:
def-form check src/

Clear the cache

Files that pass are remembered in .def_form_cache/, so unchanged files are skipped on the next run. To drop what was remembered:

def-form clean

Example

You can check your code with check command and see the result

(.venv) user@MacBook-Pro def-form % def-form check test_file.py
Checking test_file.py

                           Configuration                           
 ───────────────────────────────────────────────────────────────── 
  Config Path:       /Users/user/Documents/def-form/pyproject.toml  
  Max Inline Args:   2                                             
  Max Def Length:    100                                           
  Indent Size:       4 spaces                                      
  Show Skipped:      No                                            
  Cache:             Yes                                           
  Excluded:          .venv, tests/cases, build                     
 ───────────────────────────────────────────────────────────────── 

Found 1 errors in 1 files

/Users/user/Documents/def-form/test_file.py:19
  • Invalid multiline function parameters indentation (expected 4 spaces)

           Summary           
 ─────────────────────────── 
  Files processed:     1     
  Files with issues:   1     
  Total errors:        1     
  Success rate:        0.0%  
 ─────────────────────────── 

Code style violations found

Or use format

(.venv) user@MacBook-Pro def-form % def-form format test_file.py
Formatting test_file.py

                           Configuration                           
 ───────────────────────────────────────────────────────────────── 
  Config Path:       /Users/user/Documents/def-form/pyproject.toml  
  Max Inline Args:   2                                             
  Max Def Length:    100                                           
  Indent Size:       4 spaces                                      
  Show Skipped:      No                                            
  Cache:             Yes                                           
  Excluded:          build, .venv, tests/cases                     
 ───────────────────────────────────────────────────────────────── 

Found 1 errors in 1 files

/Users/user/Documents/def-form/test_file.py:19
  • Invalid multiline function parameters indentation (expected 4 spaces)

           Summary           
 ─────────────────────────── 
  Files processed:     1     
  Files with issues:   1     
  Total errors:        1     
  Success rate:        0.0%  
 ─────────────────────────── 

Formatting completed

Command line options

There is global options

Usage: def-form [OPTIONS] COMMAND [ARGS]...

Options:
  --verbose  Enable verbose output
  --quiet    Disable all output
  --help     Show this message and exit.

Commands:
  check
  clean
  format

And specific options for check/format

Usage: def-form format [OPTIONS] [PATH]

Options:
  --config FILE              Path to pyproject.toml configuration file
  --no-cache                 Process every file, ignoring the cache
  --show-skipped             Show skipped files and directories
  --exclude PATH             Paths to exclude from processing
  --indent-size INTEGER      Indent size in spaces (default: 4)
  --max-inline-args INTEGER  Maximum number of inline arguments
  --max-def-length INTEGER   Maximum length of function definition
  --help                     Show this message and exit.

Configuration

Create a pyproject.toml file in your project root:

[tool.def-form]
max_def_length = 100  # Maximum allowed characters in a single-line function definition
max_inline_args = 2   # Maximum number of arguments allowed in inline format
indent_size = 4       # Indent for arguments in spaces
cache = true          # Skip files that already passed and have not changed since
exclude = [           # Files or directories you want to exclude
    '.venv',
    'migrations'
]

Metadata

Release files for def-form 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for def-form 0.3.1
File Size Uploaded Provenance Actions
def_form-0.3.1.tar.gz 293.7 kB Without provenance Details for def_form-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for def-form 0.3.1
File Interpreter ABI Platform Actions
def_form-0.3.1-py3-none-any.whl Python 3 none any Details for def_form-0.3.1-py3-none-any.whl

Total release size: 322.9 kB

Release files / def_form-0.3.1.tar.gz

Download URL def_form-0.3.1.tar.gz
Size 293.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e0c7f5e81b9fb449145989ef77025fa00f0f01674400087a8b44ac35b95a149f
BLAKE2b-256 checksum
How to use checksums
cc7fb24b12075fd427f87bda736caa7b54bb4e22c1a106b4105ed2f58df8fd3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / def_form-0.3.1-py3-none-any.whl

Download URL def_form-0.3.1-py3-none-any.whl
Size 29.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
813ee64ac85dfc40b712961cf703dc89783969744cee317f2a31621d0df31176
BLAKE2b-256 checksum
How to use checksums
69ab519f7e1d6cd51ccb535bf21bddb9faf9876c0fb0e4287056a6d11fc0142d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for def-form 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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