API Reference¶
Access files from a remote wheel.
Classes:
|
Represents a Python distribution in wheel form, accessed over HTTP. |
|
Subclass of |
Data:
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
name (
str) – The name of the distribution.version (
Version) – The version number of the distribution.url (
str) – The URL of the.whlfile. The remote server MUST support HTTP range requests.wheel_zip (
ZipFile) – The opened zip file.
A
RemoteWheelDistributioncan be used as a contextmanager, which will close the underlyingRemoteZipFilewhen exiting thewithblock.-
classmethod
from_url(url, **kwargs)[source]¶ Construct a
RemoteWheelDistributionfrom a URL to the.whlfile.- Parameters
**kwargs – Additional keyword arguments passed to
RemoteZipFile.
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.WheelDistributionclass.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 aRemoteWheelDistributionmanually: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
-
get_record()[source]¶ Returns the parsed content of the
*.dist-info/RECORDfile, orNoneif the file does not exist.- Return type
- Returns
A
dist_meta.record.RecordEntryobject for each line in the record (i.e. each file in the distribution). This includes files in the*.dist-infodirectory.- Raises
FileNotFoundError – if the file does not exist.
-
get_wheel()[source]¶ Returns the content of the
*.dist-info/WHEELfile.- Raises
FileNotFoundError – if the file does not exist.
- Return type
-
class
RemoteZipFile(url, auth=None, initial_buffer_size=500, **kwargs)[source]¶ Subclass of
handy_archives.ZipFilefor accessing zip files using HTTP Range requests.If necessary, login/authentication details for the repository can be specified at initialization by setting the
authparameter to either a(username, password)pair or another authentication object accepted by requests.A
RemoteZipFileinstance can be used as a context manager that will automatically close the underlying session on exit.- Parameters
auth (
Optional[Any]) – Optional login/authentication details for the repository; either a(username, password)pair or another authentication object accepted by requests. DefaultNone.initial_buffer_size (
int) – The buffer size to use for the first request. Default500.
Other keyword arguments taken by
zipfile.ZipFileare accepted, exceptmode.
-
USER_AGENT¶ Type:
strThe 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
RemoteZipFileaRequestsURLobject with your own requests session and customise itsUser-Agentheader.