I've updated distlib[1] with a new, high-level API for accessing PyPI. While the existing "locators" API deals with locating distributions already uploaded to PyPI, the "index" API allows the following: * Registering a project on PyPI * Uploading source and binary distributions to PyPI (incl. support for signing) * Uploading documentation to PyPI * Getting a list of mirror hosts Basic usage:
from distlib.index import Index index = Index() # uses PyPI by default, or you can pass the URL of the index
If you have a .pypirc, your username and password are read from there. If not, or if you want to override those values, you can just do
index.username = 'my_pypi_username' index.password = 'my_pypi_password'
To register a project, a version is required (just as from PyPI's Web UI):
from distlib.metadata import Metadata metadata = Metadata() metadata['Name'] = 'my_project' metadata['Version'] = '0.1' response = index.register(metadata)
An urllib HTTP response is returned, or HTTPError is raised on error. To upload a distribution:
response = index.upload_file(metadata, dist_file_name, ... signer='My GPG Key Name', ... sign_password='my GPG passphrase', ... filetype='sdist', pyversion='source')
The signer, sign_password, filetype and pyversion are optional. The latter two default to the values shown. Again, an HTTP response is returned, or HTTPError is raised on error. To upload documentation:
response = index.upload_documentation(metadata, doc_dir)
The doc_dir should contain the index.html file. The entire directory tree is zipped up and uploaded to the index. an HTTP response is returned, or HTTPError is raised on error. The list of mirrors is available through the index.mirrors property. The Index class takes the place of three command classes in distutils/distutils2: register, upload and upload_doc. I've updated the distlib documentation[2]. Feedback welcome. Regards, Vinay Sajip [1] https://bitbucket.org/vinay.sajip/distlib/ [2] http://distlib.readthedocs.org/
On Sun, Feb 3, 2013 at 6:37 PM, Vinay Sajip
I've updated distlib[1] with a new, high-level API for accessing PyPI. While the existing "locators" API deals with locating distributions already uploaded to PyPI, the "index" API allows the following:
* Registering a project on PyPI * Uploading source and binary distributions to PyPI (incl. support for signing) * Uploading documentation to PyPI * Getting a list of mirror hosts
Basic usage:
from distlib.index import Index index = Index() # uses PyPI by default, or you can pass the URL of the index
Very cool, but would it be possible to expand the class name to something like "PackageIndex"? "Index" is an overloaded word, and that leading "I" is also a bit of a problem from a readability point of view. Regards. Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
Nick Coghlan
Very cool, but would it be possible to expand the class name to something like "PackageIndex"? "Index" is an overloaded word,
Good suggestion - done. I also added a method to verify signatures; though this is not strictly related to index operations, since the GnuPG interface code is there to support signing, it was simple enough to add verification code:
index.verify_signature('my_project-0.1.zip.asc', 'my_project-0.1.zip') True index.verify_signature('my_project-0.1.zip.asc', 'my_project-0.1c1.zip') False
Regards, Vinay Sajip
participants (2)
-
Nick Coghlan
-
Vinay Sajip