Client#
AddHeadersMiddleware #
Middleware that adds headers to requests based on a callback function.
The callback receives the host and path of the request URL and should return a dictionary of headers to add, or None to add no headers.
Examples#
>>> from rattler.networking import Client, AddHeadersMiddleware
>>> def my_callback(host: str, path: str) -> dict[str, str] | None:
... if host == "private.example.com":
... return {"Authorization": "Bearer my-token"}
... return None
>>> middleware = AddHeadersMiddleware(my_callback)
>>> middleware
AddHeadersMiddleware()
>>> Client([middleware])
Client()
>>>
__init__ #
Create a new AddHeadersMiddleware instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[[str, str], dict[str, str] | None]
|
A callable that takes (host, path) and returns a dictionary of headers to add to the request, or None to add no headers. The host is the hostname of the request URL (e.g., "conda.anaconda.org"). The path is the path component of the URL (e.g., "/conda-forge/linux-64/repodata.json"). |
required |
AuthenticationMiddleware #
Client #
FetchRepoDataOptions
dataclass
#
bz2_enabled
class-attribute
instance-attribute
#
Whether the BZ2 compression is enabled or not.
cache_action
class-attribute
instance-attribute
#
How to interact with the cache.
'cache-or-fetch'(default): Use the cache if its up to date or fetch from the URL if there is no valid cached value.'use-cache-only': Only use the cache, but error out if the cache is not up to date'force-cache-only': Only use the cache, ignore whether or not it is up to date.'no-cache': Do not use the cache even if there is an up to date entry
jlap_enabled
class-attribute
instance-attribute
#
Whether the JLAP compression is enabled or not.
variant
class-attribute
instance-attribute
#
Which type of repodata to download
'after-patches'(default): Fetch therepodata.jsonfile. Thisrepodata.jsonhas repodata patches applied.'from-packages'Fetch therepodata_from_packages.jsonfile'current': Fetchcurrent_repodata.jsonfile. This file contains only the latest version of each package.
zstd_enabled
class-attribute
instance-attribute
#
Whether the ZSTD compression is enabled or not.
GCSMiddleware #
Middleware to work with gcs:// URLs
Examples#
>>> from rattler.networking import Client
>>> middleware = GCSMiddleware()
>>> middleware
GCSMiddleware()
>>> Client([middleware])
Client()
>>>
FetchRepoDataOptions
dataclass
#
bz2_enabled
class-attribute
instance-attribute
#
Whether the BZ2 compression is enabled or not.
cache_action
class-attribute
instance-attribute
#
How to interact with the cache.
'cache-or-fetch'(default): Use the cache if its up to date or fetch from the URL if there is no valid cached value.'use-cache-only': Only use the cache, but error out if the cache is not up to date'force-cache-only': Only use the cache, ignore whether or not it is up to date.'no-cache': Do not use the cache even if there is an up to date entry
jlap_enabled
class-attribute
instance-attribute
#
Whether the JLAP compression is enabled or not.
variant
class-attribute
instance-attribute
#
Which type of repodata to download
'after-patches'(default): Fetch therepodata.jsonfile. Thisrepodata.jsonhas repodata patches applied.'from-packages'Fetch therepodata_from_packages.jsonfile'current': Fetchcurrent_repodata.jsonfile. This file contains only the latest version of each package.
zstd_enabled
class-attribute
instance-attribute
#
Whether the ZSTD compression is enabled or not.
fetch_repo_data
async
#
Returns a list of RepoData for given channels and platform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channels
|
List[Channel]
|
A list of |
required |
platforms
|
List[Platform]
|
A list of |
required |
cache_path
|
Union[str, PathLike[str]]
|
A |
required |
callback
|
Optional[Callable[[int, int], None]]
|
A |
required |
client
|
Optional[Client]
|
A |
None
|
Returns:
| Type | Description |
|---|---|
List[SparseRepoData]
|
A list of |