strip-hints
Function and command-line program to strip Python type hints.
What it is and what it does
strip-hints is a command-line tool and Python library that removes type annotations from Python source files while attempting to preserve the syntactic structure and line/column correspondence of the original code. It was originally designed to allow Python 2 code to be developed with type hints on Python 3 but executed on Python 2; though Python 2 is no longer maintained, the tool remains useful for stripping hints from any codebase that needs to run on interpreters without type-hint support.
The package provides both a console command and importable functions for programmatic use. It includes a general-purpose TokenList class that operates on Python tokens using a string-like interface, which can be useful for other token-level code transformations. The tool handles edge cases like line breaks within type hints in annotated assignments and return type specifications, with configurable options to control how strictly line numbers are preserved.
Use it for:
- Maintain a single codebase with type hints that must also run on older Python versions without type-hint support
- Automatically strip hints from imported modules in the same directory to enable runtime compatibility
- Preprocess Python code before execution on interpreters that do not support type annotations
- Build custom code transformation tools using the TokenList class for token-level operations
- Test or verify that code remains syntactically valid after type-hint removal
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Strips type hints from Python source code while preserving line and column numbers, leaving syntactically valid code that can run on interpreters without type-hint support.
Yes, if you need to strip type hints from Python code. The package is stable, has no known vulnerabilities, and carries a permissive MIT license. Install friction is minimal. The aging maintenance status (539 days since last release) is a minor concern but not a blocker, as the tool's scope is narrow and the repository remains active. Suitable for build pipelines, compatibility layers, or one-off code transformations.
Install
strip-hints on PyPI
pip
pip install strip-hintsuv
uv add strip-hintspoetry
poetry add strip-hintsInstalling strip-hints
Before you install
Low friction: pure Python wheel with only wheel as a runtime dependency. Maintenance is aging—last release was 539 days ago, though the repository remains active with a recent commit on 2025-02-21.
License in practice
MIT license grants broad permission to use, modify, and distribute. No notable restrictions for most use cases.
Quickstart
pip install strip-hints
strip-hints your_file_with_hints.py
Or programmatically:
from strip_hints import strip_file_to_string
code_string = strip_file_to_string(filename)
Verify before relying
- Whether the package still works reliably with modern Python 3 versions (classifiers list 3.3–3.5 but latest release is recent)
- Whether the TokenList class and token-level API are documented or stable for external use
Package facts
| License | The MIT License (MIT) Copyright (c) 2017 Allen Barker Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the… (full text in the JSON record) (unclear) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — wheel |
| Maintenance | aging — 539 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,267,977/month — #3,179 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: strip_hints-0.1.13-py3-none-any.whl
Keywords: annotations, hints, strip, type, typing
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
strip-markdownConverts markdown text to plain text, removing…
permissive · top 15,000 on PyPI
ansi2txtConverts ANSI escape sequences (color codes,…
unclear · top 15,000 on PyPI
typed-astProvides Python 2.7 and Python 3 AST parsers…
permissive · top 5,000 on PyPI
strip-ansiRemoves ANSI escape sequences (color codes,…
unclear · top 15,000 on PyPI
mdit-plainConverts markdown documents to plain text by…
permissive · top 15,000 on PyPI
jaraco.textProvides utility functions for common text…
permissive · top 5,000 on PyPI
untokenizeConverts Python tokens back into source code…
permissive · top 15,000 on PyPI
striprtfConverts Rich Text Format (RTF) files to plain…
permissive · top 5,000 on PyPI
cleancoCleanco strips legal suffixes (Ltd, Corp, LLC,…
permissive · top 5,000 on PyPI
ast-decompilerConverts Python abstract syntax trees (ASTs)…
permissive · top 15,000 on PyPI