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:
You should avoid using XML-RPC method calls when:
When dealing with indexes, keep in mind that the index queries will always return you packaging.pypi.dist.ReleaseInfo and packaging.pypi.dist.ReleasesList objects.
Some methods here share common APIs with the one you can find on packaging.pypi.simple, internally, packaging.pypi.client is inherited by Client
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 packaging.pypi.client.Client
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:
XML-RPC is a preferred 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 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>
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>]
Indexes have information about projects, releases and distributions. If you’re not familiar with those, please refer to the documentation of 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.