summaryrefslogtreecommitdiffstats
path: root/Doc/library/packaging.pypi.xmlrpc.rst
blob: 0253d68089eed5d3a9802d4270b101a9bcb1ee89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
:mod:`packaging.pypi.xmlrpc` --- Crawler using the PyPI XML-RPC interface
=========================================================================

.. module:: packaging.pypi.xmlrpc
   :synopsis: Client using XML-RPC requests to fetch info and distributions.


Indexes can be queried using XML-RPC calls, and Packaging provides a simple
way to interface with XML-RPC.

You should **use** XML-RPC when:

* Searching the index for projects **on other fields than project
  names**. For instance, you can search for projects based on the
  author_email field.
* Searching all the versions that have existed for a project.
* you want to retrieve METADATAs information from releases or
  distributions.


You should **avoid using** XML-RPC method calls when:

* Retrieving the last version of a project
* Getting the projects with a specific name and version.
* The simple index can match your needs


When dealing with indexes, keep in mind that the index queries will always
return you :class:`packaging.pypi.dist.ReleaseInfo` and
:class:`packaging.pypi.dist.ReleasesList` objects.

Some methods here share common APIs with the one you can find on
:class:`packaging.pypi.simple`, internally, :class:`packaging.pypi.client`
is inherited by :class:`Client`


API
---

.. class:: Client


Usage examples
--------------

Use case described here are use case that are not common to the other clients.
If you want to see all the methods, please refer to API or to usage examples
described in :class:`packaging.pypi.client.Client`


Finding releases
^^^^^^^^^^^^^^^^

It's a common use case to search for "things" within the index. We can
basically search for projects by their name, which is the most used way for
users (eg. "give me the last version of the FooBar project").

This can be accomplished using the following syntax::

   >>> client = xmlrpc.Client()
   >>> client.get_release("Foobar (<= 1.3))
   <FooBar 1.2.1>
   >>> client.get_releases("FooBar (<= 1.3)")
   [FooBar 1.1, FooBar 1.1.1, FooBar 1.2, FooBar 1.2.1]


And we also can find for specific fields::

   >>> client.search_projects(field=value)


You could specify the operator to use, default is "or"::

   >>> client.search_projects(field=value, operator="and")


The specific fields you can search are:

* name
* version
* author
* author_email
* maintainer
* maintainer_email
* home_page
* license
* summary
* description
* keywords
* platform
* download_url


Getting metadata information
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

XML-RPC is a prefered way to retrieve metadata information from indexes.
It's really simple to do so::

   >>> client = xmlrpc.Client()
   >>> client.get_metadata("FooBar", "1.1")
   <ReleaseInfo FooBar 1.1>


Assuming we already have a :class:`packaging.pypi.ReleaseInfo` object defined,
it's possible to pass it to the xmlrpc client to retrieve and complete its
metadata::

   >>> foobar11 = ReleaseInfo("FooBar", "1.1")
   >>> client = xmlrpc.Client()
   >>> returned_release = client.get_metadata(release=foobar11)
   >>> returned_release
   <ReleaseInfo FooBar 1.1>


Get all the releases of a project
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To retrieve all the releases for a project, you can build them using
`get_releases`::

   >>> client = xmlrpc.Client()
   >>> client.get_releases("FooBar")
   [<ReleaseInfo FooBar 0.9>, <ReleaseInfo FooBar 1.0>, <ReleaseInfo 1.1>]


Get information about distributions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Indexes have information about projects, releases **and** distributions.
If you're not familiar with those, please refer to the documentation of
:mod:`packaging.pypi.dist`.

It's possible to retrieve information about distributions, e.g "what are the
existing distributions for this release ? How to retrieve them ?"::

   >>> client = xmlrpc.Client()
   >>> release = client.get_distributions("FooBar", "1.1")
   >>> release.dists
   {'sdist': <FooBar 1.1 sdist>, 'bdist': <FooBar 1.1 bdist>}

As you see, this does not return a list of distributions, but a release,
because a release can be used like a list of distributions.