fftools.web

fftools.web.dig(fqdn: str, record_type: str) list[str][source]

resolve dns record.

Parameters:
  • fqdn (str) – fqdn of record to resolve

  • record_type (str) – type of record, e.g. A or AAA

Raises:
  • ValueError – if no answer was found.

  • exc – on resolving errors.

Returns:

a list of resolved addresses

Return type:

list[str]

fftools.web.download_file(url: str, download_path: Path, timeout: int = 30, follow_redirects: bool = True, chunk_size: int | None = 65536, username: str | None = None, password: str | None = None, **kwargs) None[source]

download a file with httpx.stream.

Parameters:
  • url (str) – url of the file.

  • download_path (Path) – ath to save the file to.

  • timeout (int) – timeout of the request in seconds. Defaults to 30.

  • follow_redirects (bool) – follow HTTP 3XX redirects. None sets it to the server response default. Defaults to True.

  • chunk_size (int | None) – size of the chunks which are downloaded. Defaults to 64*1024.

  • username (str | None) – username for basic auth. if unset no authentication is used. Defaults to None.

  • password (str | None) – password for basic auth. if unset no authentication is used. Defaults to None.

  • kwargs – other kwargs directly supplied to httpx.request

Raises:
  • ValueError – if requested file size is 0 bytes.

  • exc – on download errors.

Return type:

None

fftools.web.req(method: Literal['GET', 'POST', 'HEAD', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'], url: str, timeout: float = 5, default_headers: bool = True, follow_redirects: bool = True, payload: dict[str, Any] | str | bytes | None = None, username: str | None = None, password: str | None = None, **kwargs) Response[source]

make a http(s) request.

Parameters:
  • method (Literal['GET', 'POST', 'HEAD', 'PUT', 'DELETE', 'PATCH', 'OPTIONS']) – HTTP method, e.g. GET.

  • url (str) – url for the request.

  • timeout (float) – timeout of the request in seconds. Defaults to 5.

  • default_headers (bool) – send default headers for content-type and accept. Defaults to True.

  • follow_redirects (bool) – follow HTTP 3XX redirects. Defaults to True.

  • payload (dict[str, Any] | str | bytes | None) – data to send. either dict, str or bytes. Defaults to None.

  • username (str | None) – username for basic auth. if unset no authentication is used. Defaults to None.

  • password (str | None) – password for basic auth. if unset no authentication is used. Defaults to None.

  • kwargs – other kwargs directly supplied to httpx.request

Raises:

exc – on request errors.

Returns:

httpx.Response object

Return type:

Response

fftools.web.upload_file(method: Literal['POST', 'PUT', 'PATCH'], url: str, file_path: Path, timeout: int = 30, username: str | None = None, password: str | None = None, **kwargs) Response[source]

upload a file with httpx.

Parameters:
  • method (Literal['POST', 'PUT', 'PATCH']) – http method to use for the upload.

  • url (str) – upload url.

  • file_path (Path) – path of file to upload.

  • timeout (int) – timeout of the request in seconds. Defaults to 30.

  • username (str | None) – username for basic auth. if unset no authentication is used. Defaults to None.

  • password (str | None) – password for basic auth. if unset no authentication is used. Defaults to None.

  • kwargs – other kwargs directly supplied to httpx.request

Raises:

exc – on upload errors.

Returns:

httpx.Response object

Return type:

Response