7

Does PyPI support simple download urls? The reason I want to do this, is that I have a PC with curl installed, but not pip. So I would be able to install the package with:

pip install ppci

But since pip is not available, what I want to do is download this package with curl and untar it.

Now I can do this:

curl https://pypi.python.org/packages/4c/e8/fd7241885330ace50d2f7598a2652d4e80c1d922faece7bba88529cf6cfe/ppci-0.5.4.tar.gz
tar xfz ppci-0.5.4.tar.gz

But what I want is a cleaner url, like this:

curl https://pypi.python.org/packages/ppci/0.5.4/ppci-0.5.4.tar.gz

So, that in future I can easily upgrade the version to this:

curl https://pypi.python.org/packages/ppci/0.5.5/ppci-0.5.5.tar.gz

Does this url, or something alike exist, such that I can easily increase the version number and get the newer version without the long hashcode in it?

Windel
  • 499
  • 4
  • 11

3 Answers3

11

The right url is:

https://pypi.io/packages/source/p/ppci/ppci-0.5.4.tar.gz

Note that this url will redirect, but curl can handle it with the -L option.

The url format is, as explained below in the comments:

https://pypi.io/packages/source/{ package_name_first_letter }/{ package_name }/{ package_name }-{ package_version }.tar.gz
Windel
  • 499
  • 4
  • 11
  • Would you have an idea why this package doesn't work with the URL scheme you used above: https://pypi.io/packages/source/p/hashids/hashids-1.2.0.tar.gz. Thanks – Ricky Boyce Mar 01 '19 at 13:47
  • 3
    Just answering my own question, the package URL pattern is this: `https://pypi.io/packages/source/{ first letter }/{ package name }/{ package name }-{ version }.tar.gz` – Ricky Boyce Mar 01 '19 at 23:50
  • URL scheme failing now: eg `curl -iLs https://pypi.io/packages/source/m/mkdocs-1.0.4.tar.gz` – SJT Aug 22 '19 at 11:42
  • Does pypi.io host wheels too? Or just source tarballs? – Ahmed Fasih Apr 13 '21 at 22:37
  • @AhmedFasih yes, they host wheels. Look in the "files" section of the PyPI project page for any major package. – shadowtalker Aug 11 '23 at 13:33
  • Note that the first letter is case-sensitive. This can be very annoying if you don't realize it, because `pip install` is largely _not_ case-sensitive. – shadowtalker Aug 11 '23 at 13:33
5

These all appear to work as of 2019-10-30, and redirect one to the next:

https://pypi.io/packages/source/p/pip/pip-19.3.1.tar.gz
https://pypi.org/packages/source/p/pip/pip-19.3.1.tar.gz
https://files.pythonhosted.org/packages/source/p/pip/pip-19.3.1.tar.gz
https://files.pythonhosted.org/packages/ce/ea/9b445176a65ae4ba22dce1d93e4b5fe182f953df71a145f557cffaffc1bf/pip-19.3.1.tar.gz

This answer describes a way to fetch wheels using a similar index built by Debian: https://stackoverflow.com/a/53176862/881629

PyPI documentation actively discourages using the conveyor service as above, as it's mostly for legacy support, and we "should generally query the index for package URLs rather than guessing". https://warehouse.readthedocs.io/api-reference/integration-guide.html#querying-pypi-for-package-urls

(Thanks to Wolfgang Kuehn for the pointer to Warehouse documentation, but note that to get a correct wheel we need to select the appropriate entry for the target platform from the urls field in the API response. We can't grab a static element from the list, as order appears to vary between packages.)

Jack Foy
  • 493
  • 5
  • 8
1

The url for wheels is, by example invoke

https://files.pythonhosted.org/packages/py3/i/invoke/invoke-1.6.0-py3-none-any.whl

or in general

file_name := {distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl
first_letter := first letter of distribution

https://files.pythonhosted.org/packages/{python tag}/{first_letter}/{distribution}/{file_name}

I don't know if this is an official contract of PyPI Warehouse. You can always query, in a RestFull manner, its JSON API like so

https://pypi.org/pypi/invoke/1.6.0/json

The download url is then at document path /urls[1]/url

Wolfgang Kuehn
  • 12,206
  • 2
  • 33
  • 46