Skip to main content

优选 pip 镜像源,提升下载速度的命令行工具。

Project description

tpip

tpip 是一个帮助你快速选择最优 pip 镜像源的命令行工具,基于cnpip 构建,提升 Python 包的下载速度。
它可以测试各镜像源的实际下载速度,并自动选择下载速度最快的镜像源

快速使用

运行以下命令,快速切换为最快的镜像源:

pip install tpip
tpip set

功能

  • 列出并测试镜像源速度,按连接速度排序
  • 快速切换 pip 镜像源,支持手动选择自动选择最快镜像
  • 美化表格输出,使用 prettytable 库显示更清晰的结果
  • 显示包下载链接,方便查看各镜像源中包的实际下载地址
  • 支持异步测试,提高测试效率

安装

pip install tpip

开发者安装(可编辑模式)

pip install -e .

支持的镜像源

使用方法

1. 列出所有可用的镜像源

tpip list

示例输出:

+----------+-----------+----------------------------------------+
| 镜像名称 | 耗时(ms)  | 地址                                   |
+----------+-----------+----------------------------------------+
| ustc     | 135.71    | https://pypi.mirrors.ustc.edu.cn/simple|
| aliyun   | 300.77    | https://mirrors.aliyun.com/pypi/simple |
| tuna     | 499.51    | https://pypi.tuna.tsinghua.edu.cn/simple|
| default  | 1252.75   | https://pypi.org/simple                |
| tencent  | 1253.07   | https://mirrors.cloud.tencent.com/pypi/simple|
+----------+-----------+----------------------------------------+

2. 测试特定包的下载速度

tpip list --package numpy

这将测试各镜像源下载 numpy 包的速度,并显示包的下载链接。

示例输出:

正在对延迟最低的3个镜像源进行下载速度测试,这可能需要几分钟时间...

ustc 的包链接: @https://pypi.mirrors.ustc.edu.cn/packages/65/6e/09db2a15a75e9cca1c8a5b89b5d5a6d945b3bc551898b4b8d2c4a08e09b9/numpy-1.26.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
tuna 的包链接: @https://pypi.tuna.tsinghua.edu.cn/packages/65/6e/09db2a15a75e9cca1c8a5b89b5d5a6d945b3bc551898b4b8d2c4a08e09b9/numpy-1.26.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
aliyun 的包链接: @https://mirrors.aliyun.com/pypi/packages/65/6e/09db2a15a75e9cca1c8a5b89b5d5a6d945b3bc551898b4b8d2c4a08e09b9/numpy-1.26.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

开始进行下载速度测试...

3. 自动选择最快的镜像源

tpip set

示例输出:

未指定镜像源,自动选择最快的镜像源: ustc
成功设置 pip 镜像源为 'https://pypi.mirrors.ustc.edu.cn/simple'

4. 选择指定的镜像源

tpip set <镜像名称>

示例:

tpip set tuna

输出:

成功设置 pip 镜像源为 'https://pypi.tuna.tsinghua.edu.cn/simple'

5. 取消自定义镜像源设置

tpip unset

输出:

成功取消 pip 镜像源设置,已恢复为默认源。

6. 高级选项

顺序测试模式

默认情况下,tpip 使用并行测试模式。如果需要更详细的输出,可以使用顺序测试模式:

tpip list --sequential

指定测试时间

可以指定下载测试的时间限制:

tpip list --test-time 10

指定测试的镜像源数量

可以指定要测试下载速度的镜像源数量:

tpip list --top-count 5

配置文件

tpip 会修改或创建 pip 的配置文件来设置镜像源:

  • Linux/macOS: ~/.pip/pip.conf
  • Windows: %APPDATA%\pip\pip.ini

在设置镜像源时,tpip 只会修改或添加 index-url 配置,不会覆盖其他配置项。

常见问题

1. 为什么我无法连接到某些镜像源?

某些镜像源(如豆瓣)可能由于网络问题或镜像源本身的原因无法连接。在这种情况下,tpip 会显示"无法连接",并将其排在速度测试结果的最后。

2. 如何恢复为默认的 pip 镜像源?

使用 unset 命令恢复为默认的 pip 镜像源:

tpip unset

3. tpip 会覆盖我的 pip.conf 文件吗?

不会。tpip 只会修改或添加 index-url 配置项,其他配置项会被保留。

致谢

本项目基于 cnpip 项目开发,感谢 cnpip 项目的开发者提供的优秀工具和灵感。tpip 在 cnpip 的基础上进行了功能扩展和优化,为中国用户提供更好的 pip 镜像源管理体验。


tpip (English)

tpip is a command-line tool designed specifically for users in mainland China to help quickly switch pip mirrors and improve Python package download speeds. Based on cnpip, it tests the connection speed of various mirrors and automatically selects the fastest one.

Quick Start

Run the following commands to quickly switch to the fastest mirror:

pip install tpip
tpip set

Features

  • List and test mirror speeds, sorted by connection time
  • Quickly switch pip mirrors, supporting manual selection or automatic selection of the fastest mirror
  • Beautiful table output using the prettytable library
  • Display package download links for each mirror
  • Support for asynchronous testing to improve efficiency

Installation

pip install tpip

Developer Installation (Editable Mode)

pip install -e .

Supported Mirrors

Usage

1. List All Available Mirrors

tpip list

Example output:

+-------------+-----------+----------------------------------------+
| Mirror Name | Time(ms)  | URL                                    |
+-------------+-----------+----------------------------------------+
| ustc        | 135.71    | https://pypi.mirrors.ustc.edu.cn/simple|
| aliyun      | 300.77    | https://mirrors.aliyun.com/pypi/simple |
| tuna        | 499.51    | https://pypi.tuna.tsinghua.edu.cn/simple|
| default     | 1252.75   | https://pypi.org/simple                |
| tencent     | 1253.07   | https://mirrors.cloud.tencent.com/pypi/simple|
+-------------+-----------+----------------------------------------+

2. Test Download Speed for a Specific Package

tpip list --package numpy

This will test the download speed of the numpy package from different mirrors and display the download links.

Example output:

Testing download speed for the 3 mirrors with lowest latency, this may take a few minutes...

Package link for ustc: @https://pypi.mirrors.ustc.edu.cn/packages/65/6e/09db2a15a75e9cca1c8a5b89b5d5a6d945b3bc551898b4b8d2c4a08e09b9/numpy-1.26.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Package link for tuna: @https://pypi.tuna.tsinghua.edu.cn/packages/65/6e/09db2a15a75e9cca1c8a5b89b5d5a6d945b3bc551898b4b8d2c4a08e09b9/numpy-1.26.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Package link for aliyun: @https://mirrors.aliyun.com/pypi/packages/65/6e/09db2a15a75e9cca1c8a5b89b5d5a6d945b3bc551898b4b8d2c4a08e09b9/numpy-1.26.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Starting download speed test...

3. Automatically Select the Fastest Mirror

tpip set

Example output:

No mirror specified, automatically selecting the fastest mirror: ustc
Successfully set pip mirror to 'https://pypi.mirrors.ustc.edu.cn/simple'

4. Select a Specific Mirror

tpip set <mirror-name>

Example:

tpip set tuna

Output:

Successfully set pip mirror to 'https://pypi.tuna.tsinghua.edu.cn/simple'

5. Reset to Default Mirror

tpip unset

Output:

Successfully reset pip mirror settings to default.

6. Advanced Options

Sequential Testing Mode

By default, tpip uses parallel testing mode. For more detailed output, you can use sequential testing mode:

tpip list --sequential

Specify Test Duration

You can specify the time limit for download testing:

tpip list --test-time 10

Specify Number of Mirrors to Test

You can specify the number of mirrors to test for download speed:

tpip list --top-count 5

Configuration File

tpip modifies or creates the pip configuration file to set the mirror:

  • Linux/macOS: ~/.pip/pip.conf
  • Windows: %APPDATA%\pip\pip.ini

When setting a mirror, tpip only modifies or adds the index-url configuration without overwriting other settings.

FAQ

1. Why Can't I Connect to Some Mirrors?

Some mirrors (like Douban) might be inaccessible due to network issues or problems with the mirror itself. In such cases, tpip will show "Unable to connect" and rank them last in the speed test results.

2. How to Reset to the Default pip Mirror?

Use the unset command to restore the default pip mirror:

tpip unset

3. Will tpip Overwrite My pip.conf File?

No. tpip only modifies or adds the index-url configuration while preserving other settings.

Acknowledgments

This project is based on the cnpip project. We thank the developers of cnpip for providing an excellent tool and inspiration. tpip extends and optimizes the functionality of cnpip to provide a better pip mirror management experience for users in China.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tpip-0.2.0.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tpip-0.2.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file tpip-0.2.0.tar.gz.

File metadata

  • Download URL: tpip-0.2.0.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for tpip-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2e1a1bba25935fcbdd611e2a072f9649455e48bc9369aaf69d4236d18b5cebc1
MD5 ed6167a2e5bc28379ddb287c4fd92a7e
BLAKE2b-256 c0e800647f789848c63cf85f3cb2ccd35536f4b75707e60e89a54dc91c7ea3e8

See more details on using hashes here.

File details

Details for the file tpip-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: tpip-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for tpip-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7adbffa22213cd3e53b08384d7a486916b8ce65d7b7404f0746a5fe3728a60c3
MD5 28154f5ad3d6be1a5134dd9715a0f87e
BLAKE2b-256 30d9d3c919156acba24caa4bb1f211b5211fd7f62f97b0107f478d332369c8d9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page