files
Files module.
files module
Files module.
FileContent
Represents contents of a file.
alias of IO[bytes] | bytes | PathLike[str]
FileResource
Resource a file is related to.
alias of Literal[‘prediction’]
class FileUrls
Bases: TypedDict
Generated file urls.
upload_url : str
The url to use to upload the file. The file should be uploaded using a PUT request to this URL. The Content-Length and Content-type headers are required and should match the size and MIME type of the file being uploaded.
download_url : str
The url to download the file.
class CreateFileUrlsParams
Bases: TypedDict
Parameters for creating file urls.
name : str
The name of the file to upload.
size : int
The size of the file to upload in bytes. This should be the exact size of the file. Any mismatch will result in the url being invalid or a corrupt file being uploaded.
resource : Literal['prediction']
The resource the file will be related to.
mime_type : str
The MIME type of the file.
class Files(api, http_client, async_http_client)
Bases: Resource
Initializes the Resource with an API instance.
- Parameters:
- api (API) – An instance of the API class.
- http_client (Client) – An instance of a synchronous HTTP client.
- async_http_client (AsyncClient) – An instance of an asynchronous HTTP client.
create_urls(params)
Generate urls to upload and download a file for a resource.
This is a low-level method. Most callers should use
upload() instead, which handles reading, streaming,
and uploading the file contents.
- Parameters: params (CreateFileUrlsParams) – Parameters for url generation.
- Returns: The generated urls.
- Return type: FileUrls
async async_create_urls(params)
Generate urls to upload and download a file for a resource.
This is a low-level method. Most callers should use
async_upload() instead, which handles reading, streaming,
and uploading the file contents.
- Parameters: params (CreateFileUrlsParams) – Parameters for url generation.
- Returns: The generated urls.
- Return type: FileUrls
upload(file, resource, name=None)
Upload a file.
File contents are streamed without being fully buffered into memory unless the stream is not seekable, in which case it is read in full to determine size.
- Parameters:
- file (IO *[*bytes ] | bytes | PathLike *[*str ]) – Contents of the file to upload.
- resource (Literal [ 'prediction' ]) – The resource this file relates to.
- name (str | None) – Display name including extension (e.g. “report.pdf”). Inferred from the path or file object’s name attribute when omitted. Required when file is raw bytes or an IO[bytes] without a name attribute.
- Returns: The download URL for the uploaded file.
- Raises: TypeError – If name cannot be determined i.e. file is raw bytes without name, or an IO[bytes] whose name attribute is missing and name was not provided.
- Return type: str
async async_upload(file, resource, name=None)
Upload a file.
File contents are streamed without being fully buffered into memory unless the stream is not seekable, in which case it is read in full to determine size.
- Parameters:
- file (IO *[*bytes ] | bytes | PathLike *[*str ]) – Contents of the file to upload.
- resource (Literal [ 'prediction' ]) – The resource this file relates to.
- name (str | None) – Display name including extension (e.g. “report.pdf”). Inferred from the path or file object’s name attribute when omitted. Required when file is raw bytes or an IO[bytes] without a name attribute.
- Returns: The download URL for the uploaded file.
- Raises: TypeError – If name cannot be determined i.e. file is raw bytes without name, or an IO[bytes] whose name attribute is missing and name was not provided.
- Return type: str