Get the list of packages for the specified user from the packages registered on PyPI

Suddenly I wanted to get a list of packages I registered on PyPI. When you log in to PyPI, your package list will appear in the menu.

But if you have to log in, you can't get the list of packages of other users. If you enter a user name in a PyPI search, it will hit the search to some extent, but it will also narrow down packages that happen to include the user name.

According to https://wiki.python.org/moin/PyPIXmlRpc, it seems that you can use xmlrpc.

>>> import xmlrpc.client as xmlrpclib
>>> client = xmlrpclib.ServerProxy('https://pypi.python.org/pypi')
>>> client.user_packages('t2y')
[['Owner', 'ikazuchi'],
 ['Owner', 'ikazuchi.plugins.pofile'],
 ['Owner', 'ikazuchi.plugins.speech'],
 ['Owner', 'ikazuchi.plugins.blockdiag'],
 ['Owner', 'pyrtm'],
 ['Owner', 'TracTicketReferencePlugin'],
 ['Owner', 'LittleHTTPServer'],
 ['Owner', 'pytest-quickcheck'],
 ['Owner', 'kotti_mapreduce'],
 ['Maintainer', 'TracCronPlugin'],
 ['Owner', 'TracCronPlugin'],
 ['Owner', 'TracMultiSelectBoxPlugin'],
 ['Owner', 'TracChangeFileBiffPlugin'],
 ['Owner', 'unotools'],
 ['Owner', 'TracAutocompleteUsersPlugin'],
 ['Owner', 'TracMovieMacro']]

I see, it's done.

But it's a hassle to launch an interactive shell to get a list of packages, isn't it? It would be a little easier if you hit xmlrpc directly from the command line. Let's try using curl.

$ user="t2y"; curl -s -X POST -H "Content-Type: text/xml" https://pypi.python.org/pypi -d "<?xml version='1.0'?><methodCall><methodName>user_packages</methodName><params><name>$user</name></params></methodCall>" | python -c "import sys; import xml.dom.minidom; print(xml.dom.minidom.parseString(sys.stdin.read()).toprettyxml(indent='  '))"
<?xml version="1.0" ?>
<methodResponse>
  

  <params>
    

    <param>
      

      <value>
        <array>
          <data>
            

            <value>
              <array>
                <data>
                  

                  <value>
                    <string>Owner</string>
                  </value>
                  

                  <value>
                    <string>ikazuchi</string>
                  </value>
                  

                </data>
              </array>
            </value>
            ...

I see, it's done.

However, displaying the xmlrpc response as it is is redundant, and the line feed code is included here and there, so it is not easy to see at all.

I wonder if there is no choice but to parse and display the response of xmlrpc. Let's try using ElementTree.

$ user="t2y"; curl -s -X POST -H "Content-Type: text/xml" https://pypi.python.org/pypi -d "<?xml version='1.0'?><methodCall><methodName>user_packages</methodName><params><name>$user</name></params></methodCall>" | python -c "import sys; from xml.etree import ElementTree; print('\n'.join(j for j in sorted(['{} ({})'.format(i[1][0].text, i[0][0].text) for i in ElementTree.parse(sys.stdin).iter('data') if i[1][0].text])))"
LittleHTTPServer (Owner)
TracAutocompleteUsersPlugin (Owner)
TracChangeFileBiffPlugin (Owner)
TracCronPlugin (Maintainer)
TracCronPlugin (Owner)
TracMovieMacro (Owner)
TracMultiSelectBoxPlugin (Owner)
TracTicketReferencePlugin (Owner)
ikazuchi (Owner)
ikazuchi.plugins.blockdiag (Owner)
ikazuchi.plugins.pofile (Owner)
ikazuchi.plugins.speech (Owner)
kotti_mapreduce (Owner)
pyrtm (Owner)
pytest-quickcheck (Owner)
unotools (Owner)

I see, it's done.

・ ・ ・

I honestly don't know what to do: sweat:

Recommended Posts

Get the list of packages for the specified user from the packages registered on PyPI
Get the number of occurrences for each element in the list
Get the column list & data list of CASTable
Get the last day of the specified month
Semi-automatically generate a description of the package to be registered on PyPI
Get the average salary of a job with specified conditions from indeed.com
Get only the source code of the PyPI package with pip from the command line
Python script to get a list of input examples for the AtCoder contest
Get the value of a specific key in a list from the dictionary type in the list with Python
Let's get notified of the weather in your favorite area from yahoo weather on LINE!
[Python] Get the text of the law from the e-GOV Law API
[python] Get the list of classes defined in the module
Get the return code of the Python script from bat
[Python] Get the list of ExifTags names of Pillow library
Python: Get a list of methods for an object
Study from the beginning of Python Hour8: Using packages
Get the value of a specific key up to the specified index in the dictionary list in Python
Let's get notified of the weather in your favorite area from yahoo weather on LINE! ~ PART2 ~
Try to get the function list of Python> os package
Analyzing user dissatisfaction very easily from the contents of inquiries
Search for large files on Linux from the command line
Get the package version to register with PyPI from Git
Get the number of specific elements in a python list
Summary of yum packages required for pip install on EC2
How to get a list of links from a page from wikipedia
Get the host name of the host PC with Docker on Linux
python memo: enumerate () -get index and element of list at the same time and turn for statement
Get images of great find / 47 sites using Python (Part 2/2: I published the target list on github)
Get the number of digits
I tried to get the index of the list using the enumerate function
Check the increase / decrease of Bitcoin for each address from the blockchain
Studying web scraping for the purpose of extracting data from Filmarks # 2
[Python of Hikari-] Chapter 05-03 Control syntax (for statement-extracting elements from list-)
[Python] Get the update date of a news article from HTML
[python] Get the rank of the values in List in ascending / descending order
python note: map -do the same for each element of the list
I'll get rid of every single imperial system from the world!
List of disaster dispatches from the Sapporo City Fire Department [Python]
Get the number of readers of a treatise on Mendeley in Python
(For lawyers) Extract the behavior of Office software from .evtx files