pypiuploader.upload Module

Packages uploading.

class PackageUploader(host, username=None, password=None)[source]

Bases: object

Uploads source distributions to a PyPI server.

Example:

>>> uploader = PackageUploader('http://localhost:8000', 'user', 'pass')
>>> uploader.upload('amqp-1.4.4.tar.gz')
<Response [200]>
>>> uploader.upload('amqp-1.4.4.tar.gz')
Traceback (most recent call last):
  ...
PackageConflictError: Package amqp-1.4.4.tar.gz already uploaded.
Parameters:
  • host – The host of the PyPI server, e.g. 'http://localhost:8000'.
  • username – Optional username for HTTP authentication.
  • password – Optional password for HTTP authentication.
classmethod from_rc_file(repository, username=None, password=None, config_path=None)[source]

Instantiate the uploader using configuration from .pypirc file.

Read the rc file using pypirc.RCParser.

Use the repository‘s authentication config from the rc file, if the file exists and the repository section is defined. The username and password defined in the file can be overriden by the given arguments.

If the rc file or the section for the repository doesn’t exist, use the repository argument as the server host.

Return a new instance of PackageUploader.

Parameters:
  • repository – PyPI server name or URL.
  • username – Optional username for authentication.
  • password – Optional password for authentication.
  • config_path – Optional config path to use instead of ~/.pypirc.
classmethod from_repository_config(repo_config, username=None, password=None)[source]

Instantiate the uploader using repository configuration dictionary.

Examples:

>>> repo_config = {
...     'repository': 'http://localhost:8000',
...     'username': 'foo',
...     'password': 'bar',
... }
>>> uploader = PackageUploader.from_repository_config(repo_config)
>>> uploader.host, uploader.username, uploader.password
'http://localhost:8000', 'foo', 'bar'
>>> uploader = PackageUploader.from_repository_config(
...     repo_config, username='bar')
>>> uploader.host, uploader.username, uploader.password
'http://localhost:8000', 'bar', 'bar'

Return a new instance of PackageUploader.

Parameters:
  • repo_config

    A dictionary with the repository configuration, must contain three keys:

    • repository,
    • username
    • password
  • username – Optional username to override the one from the repo_cofig.
  • password – Optional password to override the one from the repo_cofig.
upload(filepath)[source]

Upload a package under the given path.

Return requests.Response from the PyPI server.

If the package is already uploaded, raise exceptions.PackageConflictError. On other errors raise requests.exceptions.HTTPError.

Parameters:filepath – A path to the package file you want to upload.

Related Topics

This Page