13

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?

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
Peter Cotton
  • 1,671
  • 14
  • 17
  • 1
    pip install won't do it ? or wget https://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. – Cristiano Araujo Nov 18 '21 at 17:10
  • `pip install python` for example should work for you – rv.kvetch Nov 18 '21 at 17:12
  • 1
    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. – Peter Cotton Nov 18 '21 at 17:14
  • 2
    https://stackoverflow.com/a/44572503/7976758 – phd Nov 18 '21 at 17:49
  • 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? – Peter Cotton Nov 18 '21 at 18:00
  • 2
    @PeterCotton AFAIK `/simple/` lists all packages. – phd Nov 18 '21 at 18:12
  • https://pypi.org/project/definetti doesn't show. – Peter Cotton Nov 23 '21 at 17:59
  • Oh I see you're hitting /simple not /simple/definetti. That nice. Probably the solution – Peter Cotton Nov 23 '21 at 19:43

2 Answers2

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/*

Álvaro H.G
  • 397
  • 1
  • 10
  • 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 :) – Peter Cotton Dec 12 '21 at 16:28
  • 2
    TestPyPI and PyPI don't share the same namespace. Picking an arbitrary name, compare https://pypi.org/project/pyromaji/ and https://test.pypi.org/project/pyromaji/ – Hugo Mar 02 '22 at 15:29
2

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
  • Really good way to check if package name is available. Thanks :) – MNA Nov 16 '22 at 07:31
  • 2
    Doesn't address the annoying "The name '...' is too similar to an existing project" issue. – user66081 Dec 24 '22 at 11:15
  • Still haven't found a workaround for that :(... I am open to suggestions though, preferably on github. – AfterNoon PM Dec 29 '22 at 21:33
  • 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_validator – Sekomer Mar 01 '23 at 07:02
  • @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! – AfterNoon PM Mar 02 '23 at 16:19
  • 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`) https://github.com/Tinkering-Townsperson/pkg_name_validator/issues/1 – mikm Jun 27 '23 at 07:15