
Python has become one of the most popular programming languages, powering everything from data science to web development. At the heart of the Python ecosystem lies pip, the package installer that makes it simple to download and manage libraries from the Python Package Index (PyPI) and other sources.
While pip usually “just works,” developers can sometimes run into issues when installing packages. This is where proxies come in. In this guide, we’ll show you how to use proxies with pip – from simple command-line options to persistent configurations. We’ll also share some best practices for working securely with authenticated proxies.
Why Use Proxies with pip?
In most cases, pip connects directly to the Python Package Index or a private package repository without issues. However, there are situations where using a proxy can be essential:
Overcoming Network Restrictions
Some corporate or university networks restrict direct access to PyPI. By configuring pip to work with a proxy, developers can install the dependencies they need without being blocked by firewalls.
Bypassing Geo-Blocks
Certain packages or repositories may not be accessible from every country. Proxies allow you to route traffic through different regions, ensuring that location doesn’t prevent you from getting the libraries you require.
Preventing IP Bans and Rate Limits
Heavy usage – such as in CI/CD pipelines or automated scripts – can lead to temporary IP bans or throttling. Proxies can distribute requests across multiple IP addresses, reducing the risk of interruptions.

Accessing Private Repositories
If your organization hosts private Python packages, a proxy can help provide secure, controlled access, especially when working with distributed teams.
Step-by-Step: Using Proxies with pip
Now that you know the different ways pip can handle proxies, let’s walk through some practical examples.
Step 1: Using Environment Variables
If you frequently need a proxy, environment variables are the most convenient option.
Linux/macOS (Bash):
export HTTP_PROXY="http://user:password@proxy_host:proxy_port"
export HTTPS_PROXY="http://user:password@proxy_host:proxy_port"
pip install requests
Windows (Command Prompt):
set HTTP_PROXY=http://user:password@proxy_host:proxy_port
set HTTPS_PROXY=http://user:password@proxy_host:proxy_port
pip install requests
This ensures that every pip command runs through your proxy until the session ends.
Step 2: Using the --proxy Flag
For one-off installations, you can set the proxy inline:
pip install flask --proxy="http://user:password@proxy_host:proxy_port"
This is helpful if you only occasionally need to connect through a proxy.
Step 3: Configuring pip Permanently
If you always want pip to use a proxy, you can set it in pip’s configuration file. For Linux/macOS (~/.config/pip/pip.conf
):
[global]
proxy = http://user:password@proxy_host:proxy_port
For Windows (%APPDATA%\pip\pip.ini
):
[global]
proxy = http://user:password@proxy_host:proxy_port
Once set, all pip installs will automatically use the proxy.
Step 4: Testing Your Setup
To confirm that pip is using the proxy, try installing a simple package:
pip install requests
If the package installs successfully without connection errors, your proxy is working correctly.
Authentication and Security
Many proxy servers require authentication to ensure only authorized users can connect. pip supports this by allowing you to include your username and password directly in the proxy URL.
Using Authentication in pip
The basic format looks like this:
pip install requests --proxy="http://username:password@proxy_host:proxy_port"
For environment variables:
export HTTPS_PROXY="http://username:password@proxy_host:proxy_port"
pip install requests
And in pip.conf
or pip.ini
:
[global]
proxy = http://username:password@proxy_host:proxy_port
Security Considerations
While it’s convenient to embed credentials directly in URLs, this can create risks if stored in plain text. Consider these best practices:
- Avoid hardcoding credentials in scripts or version-controlled files.
- Use environment variables or secret managers to store usernames and passwords.
- Prefer HTTPS proxies over HTTP for encrypted connections.
- Rotate credentials periodically to reduce exposure risks.
Example: Using Environment Variables for Credentials
Instead of writing the full proxy URL with a password, you can split credentials into separate environment variables:
export PROXY_USER="myuser"
export PROXY_PASS="mypassword"
export HTTPS_PROXY="http://${PROXY_USER}:${PROXY_PASS}@proxy_host:proxy_port"
This way, sensitive information isn’t directly visible in your pip commands or configuration files.
🔐 Tip: Reliable proxy providers (like Infatica) support encrypted connections and authenticated access, making it easier to integrate proxies into secure development workflows.
Advanced Use Cases
Beyond basic installations, proxies can support more complex pip workflows. Here are some scenarios where they add real value:
Use Case | How Proxies Help | Example Setup |
---|---|---|
Installing from Private Repositories | Restricts access to company packages while allowing remote developers to connect securely. | Configure pip.conf with an authenticated proxy to route requests through a corporate gateway. |
CI/CD Pipelines | Ensures builds can fetch packages reliably, even in restricted environments or behind firewalls. | Set HTTP_PROXY and HTTPS_PROXY as environment variables in the CI/CD configuration. |
Rotating Proxies for Automation | Prevents IP bans and throttling when repeatedly fetching packages at scale. | Use a pool of authenticated proxies and rotate them in scripts that call pip. |
Geo-Restricted Packages | Grants access to region-specific libraries or mirrors that may be blocked in your location. | Set the proxy region in your provider’s dashboard, then export the matching proxy URL. |
Team Collaboration | Standardizes access across distributed teams by routing all package installations through a single proxy endpoint. | Configure a shared pip.conf with proxy credentials distributed securely to the team. |
How Professional Proxy Services Can Help
While it’s possible to configure pip with free or self-hosted proxies, these solutions often come with drawbacks: instability, limited IP pools, or security risks. For developers and teams who depend on reliable access to Python packages, premium proxies can provide significant advantages.
Benefits of Using Infatica, a Professional Proxy Provider
- High reliability: Ensure consistent uptime so that CI/CD pipelines and installations don’t fail unexpectedly.
- Scalability: Access large pools of IP addresses, including residential and datacenter options, suitable for both individual developers and teams.
- Geo-targeting: Choose IPs from different regions to bypass location-based restrictions on certain packages or mirrors.
- Secure authentication: Protect access with encrypted connections and authenticated proxy endpoints.
- Team-friendly setups: Centralize proxy access so distributed teams can work under the same configuration.
By integrating a premium proxy solution into your workflow, you reduce friction and eliminate common installation issues that can slow down development. (Infatica, for example, offers high-performance datacenter proxies and residential proxies designed for developers – making it easy to plug reliable proxy access directly into pip and other Python tools.)