As a replacement for pip search, pynamer will quickly ascertain if a project name is 'available' in PyPI and optionally 'register' it.
- TL;DR
- Demo
- Project Rationale
- Quick Start
- Usage
- The oddities
- Limitations
- Using the Docker Image
- Documentation
- Planned Future improvements
- Package Statistics
- License
- Meta Information
Some of you may have reached the point where you want to publish a package in the PyPI python repository. The first step of which is to choose a unique name. Here lies the problem.
A recent look at the PyPI repository revealed there were over 586,727 projects, so many names have already been taken.
pip leaps to the rescue with its search utility... or does it?
pip search zaphod
ERROR: XMLRPC request failed [code: -32500]
RuntimeError: PyPI no longer supports 'pip search' (or XML-RPC search).
Please use https://pypi.org/search (via a browser) instead.
See https://warehouse.pypa.io/api-reference/xml-rpc.html#deprecated-methods for more information.
A quick search will show the internet replete with articles explaining the situation:
- The Register: Why Python's pip search isn't working
- Python.org discussion: Pip search is still broken
OK so I go to the PyPI website and do a search for 'zaphod' as suggested by pip and 7 results are displayed none of which have the package name 'zaphod'
Fantastic! I now think unbelievably that I have a unique name for a project that I can use. So, I go ahead and code my new project, along with all the test files, documentation and meta data. I diligently debug and commit and push to git and github so I have a history.
Finally the project is good enough to release and publish as an installable package on PyPI.
Here goes....
~ $ python -m twine upload --config-file .pypirc dist/*
Uploading distributions to https://upload.pypi.org/legacy/
Uploading zaphod-0.0.0-py3-none-any.whl
100% ---------------------------------------- 3.8/3.8 kB β’ 00:00 β’ ?
WARNING Error during upload. Retry with the --verbose option for more details.
ERROR HTTPError: 403 Forbidden from https://upload.pypi.org/legacy/
The user 'stephenking' isn't allowed to upload to project 'zaphod'. See https://pypi.org/help/#project-name for more information.
AARGH!
What just happened?
Yes unbelievably the project already exists and yes unbelievably PyPI's own search did not find the project.
Enter Pynamer. Pynamer does not rely on a single method of finding a PyPI package:
Pynamer uses the following methods to ascertain whether a package already exists on PyPI:
- A simple request to the project url on PyPI.
- Uses the PyPI "simple" repository - a text-based listing of all the packages available on PyPI.
- Uses PyPI's own search 'API' and scrapes the results.
Pynamer provides a way to optionally 'register' a name on PyPI by building a minimalistic package and uploading
- Python >= 3.9.
The following are optional but required for 'registering' a project name on PyPI
-
An account on PyPI (and generate a PyPI API token).
-
A .pypirc file containing your PyPI API token.
or
-
Configure Twine environment variables.
Your .pypirc file should contain the following and be on your PATH:
[distutils]
index-servers =
pypi
[pypi]
repository = https://upload.pypi.org/legacy/
username = __token__
password = your_API_token_here
Pynamer can be installed into any python environment using pip:
~ $ pip install pynamer
However, optimal installation can be achieved using pipx:
~ $ pipx install pynamer
~ $ pynamer pynball
~ $ pynamer allitnil
Holy smoke batman! You've managed to identify a unique name.
Yes, even though the odds were against you (given there are over 586,727 registered projects), you did it!
Even though the name has nothing in common with your project, or may not even be a real word... you did it!
Congratulations!
Display the help menu with the -h
argument
~ $ pynamer -h
usage: pynamer [-h] [-r] [-v] [-g] [-m] [-s] [-w] [-f FILENAME] [-o FILENAME] [--version] [projects ...]
Determine if project name is available on pypi with the option to 'register' it for future use if available
positional arguments:
projects Optional - one or more project names
optional arguments:
-h, --help show this help message and exit
-r, --register register the name on PyPi if the name is available
-v, --verbose display information about similar projects
-g, --generate generate a new PyPI index file
-m, --meta input new meta data when registering (Author and email address)
-s, --stats display GitHub stats if available
-w, --webbrowser open the project on PyPI in a webbrowser
-f FILENAME file containing a list of project names to analyze
-o FILENAME file to save the test results
--version display version number
You can specify as many names as you like from the command line e.g.
~ $ pynamer ganymede europa callisto
You can use the -f
argument to specify a file containing the a names of projects to analyze.
You specify a space separated sequence of as many names as you like on as many lines as you like. e.g.
'projects' file
ganymede europa
IO callisto
Then specify the -f
argument
~ $ pynamer -f projects
You can use the input file with names from the command line. The names will be aggregated. e.g.
~ $ pynamer ersa pandia leda metis -f projects
You can specify a file to write the result to by using the -o
argument. e.g.
~ $ pynamer ersa pandia leda -o results
This will write a file e.g.
results
Result from pynamer PyPI utility 2023-05-02
-------------------------------------------
test 1 - Basic url lookup on PyPI
test 2 - Search of PyPIs simple index
test 3 - Search using an request to PyPIs search 'API'.
Project name Test1 Test2 Test 3 Conclusion
-------------------------------------------------------------------
ersa Found Found Found Not Available
pandia Not Found Not Found Found Not Available
leda Not Found Not Found Not Found Available
Again you can use a combination of names from the command line and input file.
You can optionally display some of the most pertinent GitHub statistics if available by using the -s
argument.
The statistics will be displayed in the the details section of test 1. e.g.
~ $ pynamer black -s
You can optionally 'register' the name on PyPI by using the -r
argument.
If the project name is found to be available and you have a valid 'pypirc' file is found, a minimalistic project will be built and uploaded
to PyPI.
The first time you use the 'registration' procedure you will be prompted to enter your name and email address. These are required. You can also optionally choose to change the version and description.
This information will be retained and you will not be prompted to enter this information again. However, you can regenerate
this meta data by using the -m
argument along with the -r
argument. You can just enter on the options you dont want to change.
~ $ pynamer agrajag -r
With the -v
argument you can display the first page of all other project matched by PyPIs search API - ordered by relevance.
The algorithm that PyPI uses to select these in unknown but seems to be a mixture of names and other
projects written by the same author.
~ $ pynamer pynamer -v
As one of its tests Pynamer makes use of a list of package names scraped from its simple index site.
The PyPI Simple Index is a plain text file that lists the names of all the packages available on PyPI.
It is a simplified version of the PyPI index that makes it easier for users to browse and download packages.
The PyPI Simple Index is used by a variety of tools and libraries to download and install packages from PyPI. For example, the pip package manager, which is used to install and manage Python packages, uses the PyPI Simple Index to find packages. The Index is updated every few hours.
Using the -g
argument can be used to regenerate the local file contents.
~ $ pynamer -g
See planned future improvements
The reason I wrote this application in the first place...
~ $ pynamer zaphod
Even worse ...
~ $ pynamer zem
You may ask .. Why not just use the PyPI simple search index, that seems to be a pretty good indicator? Well that is because it isn't...
~ $ pynamer gitmon
There will be occasions where all the tests pass, the name appears to be available but the upload to PyPI still fails. This can be several reasons for this:
- You are trying to use an internally "reserved" keyword for PyPI.
- The name you are using is too similar to an existing project name and you get the following error message:
...
Error during upload. Retry with the --verbose option for more details.
HTTPError: 400 Bad Request from https://test.pypi.org/legacy/
The name 'yourpackage' is too similar to an existing project. See https://test.pypi.org/help/#project-name for more information-
Using a name similar to to an existing package name is a security issue.
Malicious players will try to create project names that are frequently mistyped for large popular projects, thereby facilitating installation of a malicious project. e.g. replacing "L" / "l" with the number 1 or "o" / "O" with 0. The Software utilized by PyPI can be found on GitHub: warehouse.
Pull the latest image from the Hub.
~ $ docker pull sraking/pynamer
Run the image.
~ $ docker run -it sraking/pynamer /bin/bash
Use the command line as normal in the container.
root@4d315992ca28:/app# pynamer
usage: pynamer [-h] [-r] [-v] [-g] [-m] [-s] [-w] [-f FILENAME] [-o FILENAME] [--version] [projects ...]
Determine if project name is available on pypi with the option to 'register' it for future use if available
...
- Improve performance of the regeneration of the PyPI simple Repository Index, so this can be run in the background automatically.
Distributed under the MIT license. See for more information.
Author: Stephen King (sking.github@gmail.com)