python-typewriter

Getting started

Install

pip install py-typewriter-cli

Typewriter supports Python 3.10 through 3.13.

First run

Given a file like:

from typing import Any, Union

count: int = None
name: str = None
payload: Any = None

def greet(user_id: int = None, msg: Union[str, None] = None) -> Union[str, None]:
    if user_id is None:
        return None
    return f"hello-{user_id}\n{msg}"

Preview the rewrite without changing the file:

typewriter run path/to/example.py --check

In --check mode Typewriter prints a unified diff and exits with:

Apply the same rewrite in place:

typewriter run path/to/example.py

Directory and inline-code runs

Run recursively on Python files in a directory:

typewriter run examples

Transform an in-memory string instead of a file:

typewriter run --code "var: int = None\n"

PATH and --code are mutually exclusive, and literal \n sequences in --code input are interpreted as newlines.