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.whl
file. The remote server MUST support HTTP range requests.wheel_zip (
ZipFile
) – The opened zip file.
A
RemoteWheelDistribution
can be used as a contextmanager, which will close the underlyingRemoteZipFile
when exiting thewith
block.-
classmethod
from_url
(url, **kwargs)[source]¶ Construct a
RemoteWheelDistribution
from a URL to the.whl
file.- 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.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 aRemoteWheelDistribution
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
-
get_record
()[source]¶ Returns the parsed content of the
*.dist-info/RECORD
file, orNone
if the file does not exist.- Return type
- 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
-
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
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.ZipFile
are accepted, exceptmode
.
-
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
aRequestsURL
object with your own requests session and customise itsUser-Agent
header.