ClientFileMixin#

class httpx_gracedb.file.ClientFileMixin(*, auth=None, params=None, headers=None, cookies=None, timeout=Timeout(timeout=5.0), follow_redirects=False, max_redirects=20, event_hooks=None, base_url='', trust_env=True, default_encoding='utf-8')[source]#

Bases: BaseClient

A mixin for httpx.Client to add features for file uploads.

The httpx.Client.request() method takes a files argument which is a dictionary of {fieldname: fileobject}, where fileobject may be a file-like object or a tuple of 2-4 elements consisting of the filename, file content, MIME type, and any custom headers.

This mixin adds the following features:

  • The MIME type is automatically guessed from the filename.

  • If the file content is None, then the filename is treated as a path, and the file is opened and read. If the filename is -, then the file content is read from stdin.

Methods Summary

build_request(method, url, *[, content, ...])

Build and return a request instance.

Methods Documentation

Parameters:
  • auth (AuthTypes | None)

  • params (QueryParamTypes | None)

  • headers (HeaderTypes | None)

  • cookies (CookieTypes | None)

  • timeout (TimeoutTypes)

  • follow_redirects (bool)

  • max_redirects (int)

  • event_hooks (None | Mapping[str, list[EventHook]])

  • base_url (URL | str)

  • trust_env (bool)

  • default_encoding (str | Callable[[bytes], str])

build_request(method, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, timeout=Ellipsis, extensions=None)[source]#

Build and return a request instance.

  • The params, headers and cookies arguments

are merged with any values set on the client. * The url argument is merged with any base_url set on the client.

See also: [Request instances][0]

[0]: /advanced/clients/#request-instances