Skip to main content

typo-shield 🛡️

PyPI version Python versions License: Apache 2.0 Tests

Security guard against typosquatting in Python dependencies

A CLI tool and pre-commit hook that detects suspicious package names and imports in your git diff to protect against supply chain attacks.

🚀 Quick Start

# Install
pip install typo-shield

# Scan staged changes
typo-shield scan

# Scan commit range
typo-shield scan --diff-range main...feature

# JSON output for CI
typo-shield scan --format json

📋 Features

  • ✅ Detects typosquatting in dependencies (Levenshtein distance)
  • ✅ Scans Python imports (AST-based)
  • ✅ Parses requirements.txt and pyproject.toml (PEP 621 + Poetry)
  • ✅ Identifies missing dependencies
  • ✅ Pre-commit hook support
  • ✅ JSON output for CI/CD
  • ✅ Configurable via .typo-shield.toml

📦 Installation

Requirements: Python 3.10 or newer

pip install typo-shield

Development installation:

git clone https://github.com/kszmigiel/typo-shield
cd typo-shield
pip install -e ".[dev]"

🔍 Usage

Basic scanning

# Scan staged changes (default)
typo-shield scan

# Scan specific commit range
typo-shield scan --diff-range main...feature

# Strict mode (fail on unknown imports)
typo-shield scan --strict-imports

# Fail on warnings too
typo-shield scan --fail-on warn

Output formats

# Human-readable text (default)
typo-shield scan

# JSON for CI/CD
typo-shield scan --format json

Exclude patterns

# Exclude test files
typo-shield scan --exclude "tests/**" --exclude "*.pyc"

🪝 Pre-commit Hook

Integrate typo-shield with pre-commit to automatically check your dependencies on every commit.

Add to your .pre-commit-config.yaml:

repos:
  - repo: https://github.com/kszmigiel/typo-shield
    rev: v0.1.0  # Use the latest version
    hooks:
      - id: typo-shield

For stricter checking (fail on warnings too):

repos:
  - repo: https://github.com/kszmigiel/typo-shield
    rev: v0.1.0
    hooks:
      - id: typo-shield-strict

Then install the pre-commit hook:

pre-commit install

Now typo-shield will run automatically before each commit! 🎉

Note: Pre-commit hooks run on staged changes only. If you want to scan a specific commit range, use the CLI directly.

⚙️ Configuration

Create .typo-shield.toml in your repository root:

[policy]
fail_on = "fail"
strict_imports = false

[allow]
deps = ["internal-lib", "private-package"]
modules = ["internalpkg"]

[exclude]
paths = ["tests/**", "docs/**"]

🚦 Exit Codes

  • 0 - No issues found
  • 1 - Security issues detected (FAIL or WARN based on --fail-on)
  • 2 - Tool error (git not found, invalid config, etc.)

📊 Example Output

🔍 typo-shield scan

Summary: 1 FAIL, 2 WARN, 5 INFO

❌ FAILURES (1)
──────────────────────────────────────────────────────
[TS001] Suspected typosquat
  File: requirements.txt:12
  Package: reqeusts
  Reason: Very similar to popular package "requests" (distance: 1)
  Suggestion: Did you mean "requests"?

⚠️  WARNINGS (2)
──────────────────────────────────────────────────────
[TS101] Import without declared dependency
  File: app.py:5
  Module: numpy
  Suggestion: Add "numpy" to your dependencies

Result: FAILED (exit code 1)

🛠️ Development

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run tests with coverage
pytest --cov

# Linting
ruff check .

# Type checking
mypy typo_shield/

📜 License

Apache License 2.0 - see LICENSE file for details.

🤝 Contributing

Contributions welcome! Please read CONTRIBUTING.md for guidelines.

⚠️ Status

Alpha (v0.1.0) - Under active development. API may change.


Made with ❤️ to protect the Python ecosystem from supply chain attacks.

Metadata

Release files for typo-shield 0.1.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 typo-shield 0.1.1
File Size Uploaded Provenance Actions
typo_shield-0.1.1.tar.gz 61.8 kB Without provenance Details for typo_shield-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for typo-shield 0.1.1
File Interpreter ABI Platform Actions
typo_shield-0.1.1-py3-none-any.whl Python 3 none any Details for typo_shield-0.1.1-py3-none-any.whl

Total release size: 109.3 kB

Release files / typo_shield-0.1.1.tar.gz

Download URL typo_shield-0.1.1.tar.gz
Size 61.8 kB
Tags Source
SHA-256 checksum
How to use checksums
780f65c8d1167b3c12c2c44a085dcd62ece7d28bc8b704ac903be090f0026dde
BLAKE2b-256 checksum
How to use checksums
af314e990ea7dc7edf788b894fdc50e148729755bb677543e9de35bf1847fa3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release files / typo_shield-0.1.1-py3-none-any.whl

Download URL typo_shield-0.1.1-py3-none-any.whl
Size 47.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
041d0588c6e385fe2ea42690ed51f4392235b130f306ed95258bce0b693ad146
BLAKE2b-256 checksum
How to use checksums
47aa24a39ff1b13ae2b416a2213ab52a34a4034a11ec99faa1f718ce22031abc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Security for typo-shield 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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