
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
trimmargin
Advanced tools
trimMargin and friends for Python — with a tiny CLI\ntrim_margin() strips leading whitespace + a margin prefix (default |)replace_indent_by_margin() like Kotlin’s, with a custom replacement indenttrim_indent() / replace_indent() built on textwrap.dedent/indentprepend_indent() behaves like Kotlin (blank-line quirk covered)# uv (recommended)
uv pip install trimmargin
# or pip
pip install trimmargin
from trimmargin import trim_margin, replace_indent_by_margin
text = """
|hello
|world
"""
print(trim_margin(text))
# hello
# world
print(replace_indent_by_margin(text, new_indent=">>> "))
# >>> hello
# >>> world
\r\n, \n, or \r; output uses \n.The trimmargin command reads a file or stdin and writes to stdout.
# default: trim-margin on stdin using prefix "|"
trimmargin < input.txt
# file input
trimmargin input.txt
# modes
trimmargin --mode replace-by-margin --new-indent ">>> " input.txt
trimmargin --mode trim-indent < input.txt
trimmargin --mode replace-indent --new-indent " " < input.txt
trimmargin --mode prepend --indent ">> "
# change margin prefix
trimmargin --prefix "§" < input.txt
# version
trimmargin --version
Modes
trim-margin (default): remove leading whitespace + prefix
replace-by-margin: same detection as above, then add new-indent
trim-indent: remove common indent via textwrap.dedent
replace-indent: dedent then indent non-blank lines with new-indent
prepend: prepend indent to non-blank lines; blank-line quirk matches Kotlin:
len(line) < len(indent): line becomes exactly indent# setup
uv sync --extra dev
# tests
uv run pytest
# lint & types
uv run ruff check .
uv run mypy src
# format
uv run ruff format .
# build & publish
uv build
uv publish
textwrap.dedent/indent are great, but Kotlin’s margin-aware trimming is handy for multiline literals embedded in code and docs.
FAQs
Kotlin-style trimMargin utilities for Python, with a tiny CLI.
We found that trimmargin demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.