API Reference

Access files from a remote wheel.

Classes:

RemoteWheelDistribution(name, version, url, …)

Represents a Python distribution in wheel form, accessed over HTTP.

RemoteZipFile(url[, auth, initial_buffer_size])

Subclass of handy_archives.ZipFile for accessing zip files using HTTP Range requests.

Data:

USER_AGENT

The User-Agent header used for requests; not used when the user provides their own session object.

namedtuple RemoteWheelDistribution(name, version, url, wheel_zip)[source]

Represents a Python distribution in wheel form, accessed over HTTP.

Fields
  1.  name (str) – The name of the distribution.

  2.  version (Version) – The version number of the distribution.

  3.  url (str) – The URL of the .whl file. The remote server MUST support HTTP range requests.

  4.  wheel_zip (ZipFile) – The opened zip file.

A RemoteWheelDistribution can be used as a contextmanager, which will close the underlying RemoteZipFile when exiting the with block.

classmethod from_url(url, **kwargs)[source]

Construct a RemoteWheelDistribution from a URL to the .whl file.

Parameters

Note

The remote server MUST support HTTP range requests.

If the server lacks support, you should instead download the wheel with a standard GET request and use the dist_meta.distributions.WheelDistribution class.

Note

If the remote server requires authentication (e.g. a private package repository), construct a RemoteZipFile – passing the authentication information to its constructor – then create a RemoteWheelDistribution manually:

from remote_wheel import RemoteZipFile, RemoteWheelDistribution
url = "https://my.private.repository/wheels/toml-0.10.2-py2.py3-none-any.whl"
wheel_zip = RemoteZipFile(url, initial_buffer_size=100, auth=("user", "password"))
wheel = RemoteWheelDistribution("toml", Version("0.10.2"), url, wheel_zip)
Return type

RemoteWheelDistribution

get_record()[source]

Returns the parsed content of the *.dist-info/RECORD file, or None if the file does not exist.

Return type

List[RecordEntry]

Returns

A dist_meta.record.RecordEntry object for each line in the record (i.e. each file in the distribution). This includes files in the *.dist-info directory.

Raises

FileNotFoundError – if the file does not exist.

get_wheel()[source]

Returns the content of the *.dist-info/WHEEL file.

Raises

FileNotFoundError – if the file does not exist.

Return type

MetadataMapping

has_file(filename)[source]

Returns whether the *.dist-info directory contains a file named filename.

Parameters

filename (str)

Return type

bool

read_file(filename)[source]

Read a file from the *.dist-info directory and return its content.

Parameters

filename (str)

Return type

str

class RemoteZipFile(url, auth=None, initial_buffer_size=500, **kwargs)[source]

Subclass of handy_archives.ZipFile for accessing zip files using HTTP Range requests.

If necessary, login/authentication details for the repository can be specified at initialization by setting the auth parameter to either a (username, password) pair or another authentication object accepted by requests.

A RemoteZipFile instance can be used as a context manager that will automatically close the underlying session on exit.

Parameters

Other keyword arguments taken by zipfile.ZipFile are accepted, except mode.

USER_AGENT

Type:    str

The User-Agent header used for requests; not used when the user provides their own session object.

The structure of the User-Agent is:

' '.join([
        f"pypi-json/{__version__} (https://github.com/repo-helper/pypi-json)",
        f"requests/{requests.__version__}",
        f"{platform.python_implementation()}/{platform.python_version()}",
        #  ^^^ e.g. CPython                   ^^^ e.g. 3.8.10
        ])

This global attribute should not be changed by other code. Instead, pass RemoteZipFile a RequestsURL object with your own requests session and customise its User-Agent header.