What is the best way to check if a PyPI package name is taken?
Asked Answered
T

3

18

What is the best way to check if a PyPI package name is taken?

Several times now I have searched pypi for a package and received no results. Then I have taken the time to create a package with a name seemingly not taken, only to receive an error when I deploy. Is there a better way to check package name availability?

Toback answered 18/11, 2021 at 17:7 Comment(8)
pip install <package> won't do it ? or wget pypi.org/project/you_project_name. The pypi url will return 404 if its empty or 200 if its there, you can do something with the requests module to check it using head.Tobit
pip install python for example should work for youCzarina
As @CristianoAraujo points out the pip install or search will often show nothing even though the package name is not available. The suggestion to get pypi.org/project/you_project_name is a good one and more reliable, it seems.Toback
https://mcmap.net/q/742290/-get-list-of-all-available-pip-packages-and-their-versionsKlockau
Thanks didn't know the /simple . However are you sure it answers the question? I strongly suspect, unless I've tripped on some weird case, that a name can be denied yet not show on this search. Am I simply mistaken?Toback
@PeterCotton AFAIK /simple/ lists all packages.Klockau
pypi.org/project/definetti doesn't show.Toback
Oh I see you're hitting /simple not /simple/definetti. That nice. Probably the solutionToback
S
3

I just made a python package for that same use, it's called pkg_name_validator.

To install it, just run

pip install pkg_name_validator

Using it is as simple as using python -m, like so:

python -m pkg_name_validator <package name to validate>

And if you need any help, just run:

python -m pkg_name_validator -h
Stutz answered 10/8, 2022 at 1:1 Comment(8)
Really good way to check if package name is available. Thanks :)Abridgment
Doesn't address the annoying "The name '...' is too similar to an existing project" issue.Mavis
Still haven't found a workaround for that :(... I am open to suggestions though, preferably on github.Stutz
ERROR: Ignored the following versions that require a different python version: 1.0.0 Requires-Python >=3.10,<4.0 ERROR: Could not find a version that satisfies the requirement pkg_name_validatorApc
@Sekomer you do not have the sufficient python version. You would need to install python 3.10+ to get it to work. Hope that helps!Stutz
This package may not be very useful because it does not take into account PyPI's specification limiting packages with similar names. (e.g. pkgnamevalidator and pkg-name-validator) github.com/Tinkering-Townsperson/pkg_name_validator/issues/1Homs
Nice project thanks. However it checks the response code of https://pypi.org/project/{name}, which will return 404 for existing projects without releases. Try it with the name due, it should say "not available" but it says otherwise. Instead, it should check https://pypi.org/simple/{name} which will only return 404 if the name is available. See my own answer for this question :)Pediatrics
This very interesting... If someone finds a way to rectify this issue, please open a pr!Stutz
S
2

As far as I know it seems that is trial and error situation. Nevertheless you can always try pip install <name_package> to see if the name is already taken.

If you are interesting in deploying your package and don't facing up indexes errors from PyPi, you can always try out to deploy your code to TestPyPi. You will have to replace this first command:

python -m twine upload --repository pypi dist/*

by

python -m twine upload --repository testpypi dist/*

Seawright answered 11/12, 2021 at 15:30 Comment(2)
Good suggestion. It hadn't occurred to me that they must share the same namespace - but I suppose that's true? As a practical matter though, it takes a few steps to change the name of a package (maybe someone should deploy a package for that :)Toback
TestPyPI and PyPI don't share the same namespace. Picking an arbitrary name, compare pypi.org/project/pyromaji and test.pypi.org/project/pyromajiAbreact
P
2

Check the response of HTTP GET https://pypi.org/simple/{name}/. 404 means the name is available, contrary to HTTP GET https://pypi.org/project/{name}/ where 404 means either the name is available or there are no releases for this project.

You can do this from the browser, the response will show "404 Not Found" when the name is available or "Links for {name}" when the name is taken (even if there are no releases).

Pediatrics answered 5/7, 2024 at 13:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.