DEV Community

Cover image for How to Secure pip install and Protect Your Python Supply Chain (with pipq)
Livrädo Sandoval
Livrädo Sandoval

Posted on • Edited on

How to Secure pip install and Protect Your Python Supply Chain (with pipq)

Installing Python packages with pip is fast — but it’s also a major security risk.

Every pip install executes third-party code directly on your system. Typosquatting, compromised packages, or malicious dependencies can easily turn a simple install into a supply chain attack.

pipq is a security tool that protects your Python supply chain by analyzing packages before they are installed. It acts as a secure proxy for pip, helping you detect malicious or risky packages without changing your workflow.

What Is pipq and How Does It Secure pip install?

pipq acts as an intelligent security guard between you and PyPI. Instead of running pip install, you run pipq install.

pipq intercepts that request and, before installing anything, runs a series of comprehensive security validations. It gives you a clear report and makes a decision based on your configuration: block, warn, or install silently.

It's the same ease of use as pip, but with a security brain built-in.

Why pip install Is a Security Risk

The default pip install process blindly trusts packages from PyPI. This means:

  • Setup scripts can execute arbitrary code
  • Malicious dependencies can be installed silently
  • Typosquatted packages can look legitimate
  • Vulnerabilities are often discovered after installation

This makes Python a frequent target for supply chain attacks — especially in CI/CD environments.

Key Security Features of pipq

pipq isn't just one check. It's a suite of deep analysis tools designed to catch a wide range of threats:

  • Typosquatting Detection: Identifies packages with names dangerously similar to popular ones to catch malicious imitations.
  • Static Code Analysis: This is a crucial one! pipq downloads the package and scans the source code for dangerous patterns (like eval(), exec(), or obfuscated code) without ever executing it.
  • Known Vulnerability Scanning: Integrates with databases like OSV to check if the package or its dependencies have reported CVEs.
  • Malware Scanning (with VirusTotal): If you have an API key (even the free one works!), pipq can submit file hashes to VirusTotal for top-tier malware analysis.
  • Package Age Validation: A critical package was created 3 hours ago? pipq will flag it. Brand-new packages can be a strong indicator of an attack.
  • Maintainer Analysis: Does the package have a single maintainer? Does their profile look suspicious? pipq gives you that context.
  • Integrity & Provenance Validation: Ensures SHA256 hashes match and that the package follows modern standards (like using pyproject.toml).

Get Started in 60 Seconds

Enough talk. Let's put it to work.

1. Installation

The installation uses pip (ironically, for the last time unsafely!). The package is named pypipq:

pip install pypipq
Enter fullscreen mode Exit fullscreen mode

2. Usage (It's this easy!)

Now, just replace pip with pipq for your installations:

# Instead of: pip install requests
pipq install requests
Enter fullscreen mode Exit fullscreen mode

pipq will analyze requests and its dependencies. If everything looks good (as it should for requests), it will proceed with the pip installation.

If something is suspicious, you'll see a clear warning in your terminal, and the default (warn) mode will ask you if you want to proceed.

Advanced Python Dependency Security with pipq

pipq isn't just for installation. It's a Swiss Army knife for your Python environment's security.

Analyze a package without installing

Curious about a package but don't want to install it? Use pipq check:

# Deeply analyze 'numpy'
pipq check numpy --deep

# You can even get the output in JSON or Markdown
pipq check flask --json
Enter fullscreen mode Exit fullscreen mode

Audit your current environment

What vulnerabilities do you have right now in your venv? pipq audit scans all your installed packages.

# Run a full security audit
pipq audit

# Generate a JSON report for your CI/CD pipeline
pipq audit --json > audit_report.json
Enter fullscreen mode Exit fullscreen mode

Get a security profile

Want the full scoop on a package? pipq info gives you a "report card" with a security grade (A-F), license, maintainers, and more.

pipq info django
Enter fullscreen mode Exit fullscreen mode

Other helpful commands:

  • pipq list: Like pip list, but with security status.
  • pipq upgrade: Securely upgrade your packages.
  • pipq search: Search for packages and see their security scores.

Configuration: Make It Your Own

pipq is fully configurable via a TOML file (~/.config/pipq/config.toml).

Here you can change the operating mode:

  • mode = "warn" (Default): Asks you before installing anything risky.
  • mode = "block": Paranoid but safe. Blocks anything that fails a validation.
  • mode = "silent": Just installs, but still logs any issues.

You can also disable specific validators or add your API keys (like VirusTotal) to supercharge the scans.

# Example ~/.config/pipq/config.toml
mode = "block"
timeout = 30
disable_validators = ["age"] # I don't care about package age

[api_keys]
virustotal = "your_free_virustotal_api_key"
Enter fullscreen mode Exit fullscreen mode

A Note on Status

pipq is a project I'm actively working on and should be considered experimental. It's functional, but there may be bugs. Feedback and contributions are more than welcome!

Conclusion: Secure Your Supply Chain

Software supply chain security is no longer just a "big enterprise" problem. It affects every developer, from hobby projects to production systems.

Tools like pipq aim to close the gap, giving you the power of pip with the peace of mind of robust, automatic security analysis. You no longer have to choose between speed and safety.

FAQ: pip Security and Supply Chain Protection

Is pip insecure?

pip itself is not malicious, but it does not perform deep security analysis before executing package code.

Is pipq a replacement for pip?

No. pipq is a security layer on top of pip. It analyzes packages first, then delegates installation to pip.

Can pipq be used in CI/CD?

Yes. pipq supports JSON output and non-interactive modes for automation pipelines.

Does pipq slow down installations?

Slightly — but the tradeoff is significantly improved security and visibility.

Your Turn!

Are you ready to stop installing packages blind?

  1. Try pipq: pip install pypipq
  2. Visit the Repo: github.com/livrasand/pipq

If you care about Python security and supply chain safety, consider starring the project ⭐

Open source security tools grow through visibility and community feedback.

Top comments (0)