Utility to find an available package name in the PyPI repository and register it
Project description
Utility to find an available package name in the PyPI repository and optionally 'register' it.
As a pseudo replacement for pip search, pynamer will quickly ascertain if a project name is 'available' in PyPI.
Contents
- tl;dr
- Introduction
- Quick Start
- Usage
- The oddities
- Limitations
- Documentation
- Planned Future improvements
Introduction
Project Rationale
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 453,769 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:
TLDR
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
Quick Start
Prerequisites
- 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
Installation
Pynamer can be installed into any python environment using pip:
~ $ pip install pynamer
However, optimal installation can be achieved using pipx:
~ $ pipx install pynamer
Basic Usage
A package name that is not available
~ $ pynamer pynball
A package name that is available
~ $ 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 450,000+ 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!
Usage
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
Specifying multiple names
You can specify as many names as you like from the command line e.g.
~ $ pynamer ganymede europa callisto
Using an input file
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
Saving the results to a file
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.
Display GitHub statistics
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
Register the package name with PyPI
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
Verbose output
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
Regenerate the PyPI simple Repository Index
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 Oddities
The reason I wrote this application in the first place...
~ $ pynamer zaphod
Even worse ...
~ $ pynamer zem
Limitations
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.
Using the Docker Image
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
...
Documentation
Planned Future improvements
- Improve performance of the regeneration of the PyPI simple Repository Index, so this can be run in the background automatically.
Meta
Author: Stephen King (sking.github@gmail.com)
Distributed under the MIT license. See for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pynamer-2.1.8.tar.gz
.
File metadata
- Download URL: pynamer-2.1.8.tar.gz
- Upload date:
- Size: 41.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.30.0 requests-toolbelt/1.0.0 urllib3/2.0.2 tqdm/4.65.0 importlib-metadata/6.6.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3d4d2948bd6bd9a3b4a695c22b075ed60de33dfec8d5566094161b135b62ee8 |
|
MD5 | 4794eeabe322473ed25546ccb4d0fd5d |
|
BLAKE2b-256 | 07174f31855510287f517622f9a106bfc358a473ec62738fffdb6f57be46737e |
File details
Details for the file pynamer-2.1.8-py3-none-any.whl
.
File metadata
- Download URL: pynamer-2.1.8-py3-none-any.whl
- Upload date:
- Size: 24.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.30.0 requests-toolbelt/1.0.0 urllib3/2.0.2 tqdm/4.65.0 importlib-metadata/6.6.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9f34776898a9977564f72235f9725e1cff262e7c2c023a9d55abe8b332233ad |
|
MD5 | 607e7a8c4e5e2f16fc434613ecb4582c |
|
BLAKE2b-256 | 748f8f4bd96467e43d90ce77c9c08abe9fc9c93d236c5fdf20dc34c15d81bbcd |