http
openml._api.clients.http
#
HTTPCache
#
Filesystem-based cache for HTTP responses.
This class stores HTTP responses on disk using a structured directory layout
derived from the request URL and parameters. Each cached response consists of
three files: metadata (meta.json), headers (headers.json), and the raw
body (body.bin).
Notes
The cache key is derived from the URL (domain and path components) and query
parameters, excluding the api_key parameter.
get_key
#
Generate a filesystem-safe cache key for a request.
The key is constructed from URL path segments and
URL-encoded query parameters (excluding api_key).
| PARAMETER | DESCRIPTION |
|---|---|
url
|
The full request URL.
TYPE:
|
params
|
Query parameters associated with the request.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
A relative path string representing the cache key. |
Source code in openml/_api/clients/http.py
load
#
Load a cached HTTP response from disk.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
Cache key identifying the stored response.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Response
|
Reconstructed response object with status code, headers, body, and metadata. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the cache entry or required files are missing. |
ValueError
|
If required metadata is missing or malformed. |
Source code in openml/_api/clients/http.py
save
#
Persist an HTTP response to disk.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
Cache key identifying where to store the response.
TYPE:
|
response
|
Response object to cache.
TYPE:
|
Notes
The response body is stored as binary data. Headers and metadata (status code, URL, reason, encoding, elapsed time, request info, and creation timestamp) are stored as JSON.
Source code in openml/_api/clients/http.py
HTTPClient
#
HTTPClient(*, api_version: APIVersion)
HTTP client for interacting with the OpenML API.
This client supports configurable retry policies, optional filesystem caching, API key authentication, and response validation including checksum verification.
| PARAMETER | DESCRIPTION |
|---|---|
api_version
|
Backend API Version.
TYPE:
|
Source code in openml/_api/clients/http.py
__request
#
__request(session: Session, method: str, url: str, params: Mapping[str, Any], data: Mapping[str, Any], headers: Mapping[str, str], files: Mapping[str, Any] | None, **request_kwargs: Any) -> tuple[Response | None, Exception | None]
Execute a single HTTP request attempt.
| PARAMETER | DESCRIPTION |
|---|---|
session
|
Active session used to send the request.
TYPE:
|
method
|
HTTP method (e.g.,
TYPE:
|
url
|
Full request URL.
TYPE:
|
params
|
Query parameters.
TYPE:
|
data
|
Request body data.
TYPE:
|
headers
|
HTTP headers.
TYPE:
|
files
|
Files to upload.
TYPE:
|
**request_kwargs
|
Additional arguments forwarded to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of (requests.Response or None, Exception or None)
|
Response and potential retry exception. |
Source code in openml/_api/clients/http.py
delete
#
Send a DELETE request.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
API path relative to the base URL.
TYPE:
|
**request_kwargs
|
Additional request arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Response
|
HTTP response. |
Source code in openml/_api/clients/http.py
download
#
download(url: str, handler: Callable[[Response, Path, str], None] | None = None, encoding: str = 'utf-8', file_name: str = 'response.txt', md5_checksum: str | None = None) -> Path
Download a resource and store it in the cache directory.
| PARAMETER | DESCRIPTION |
|---|---|
url
|
Absolute URL of the resource to download.
TYPE:
|
handler
|
Custom handler function accepting
TYPE:
|
encoding
|
Text encoding used when writing the response body.
TYPE:
|
file_name
|
Name of the saved file.
TYPE:
|
md5_checksum
|
Expected MD5 checksum for integrity verification.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
Path to the downloaded file. |
| RAISES | DESCRIPTION |
|---|---|
OpenMLHashException
|
If checksum verification fails. |
Source code in openml/_api/clients/http.py
get
#
get(path: str, *, enable_cache: bool = False, refresh_cache: bool = False, use_api_key: bool = False, md5_checksum: str | None = None, **request_kwargs: Any) -> Response
Send a GET request.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
API path relative to the base URL.
TYPE:
|
enable_cache
|
Whether to use the response cache.
TYPE:
|
refresh_cache
|
Whether to ignore existing cached entries.
TYPE:
|
use_api_key
|
Whether to include the API key.
TYPE:
|
md5_checksum
|
Expected MD5 checksum for response validation.
TYPE:
|
**request_kwargs
|
Additional request arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Response
|
HTTP response. |
Source code in openml/_api/clients/http.py
post
#
Send a POST request.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
API path relative to the base URL.
TYPE:
|
use_api_key
|
Whether to include the API key.
TYPE:
|
**request_kwargs
|
Additional request arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Response
|
HTTP response. |