inttegro.resources.files

Generated public typing surface. Do not edit by hand.

  1"""Managed file operations and binary download helpers."""
  2
  3from __future__ import annotations
  4
  5from pathlib import Path
  6from inttegro.file.file import File
  7from inttegro.file.page import Page
  8from ..http_client import HttpClient
  9from inttegro.file.page_request import PageRequest
 10
 11
 12class FileDownload:
 13    """Binary file content and the response headers needed to save it safely.
 14
 15    This local helper never performs an API request by itself.
 16    """
 17
 18    data: bytes
 19    """Raw response bytes exactly as returned by the file content endpoint."""
 20    headers: dict[str, str]
 21    """Response headers normalized by the HTTP transport."""
 22
 23    def __init__(self, data: bytes, headers: dict[str, str] | None = None) -> None:
 24        """Create a download value from response ``data`` and optional ``headers``."""
 25        self.data = data
 26        self.headers = headers or {}
 27
 28    def save_to(self, path: str) -> None:
 29        """Write the downloaded bytes to ``path``.
 30
 31        Args:
 32            path (str): Documented path value for this operation.
 33
 34        Returns:
 35            ``None`` after the local operation completes.
 36        """
 37        Path(path).write_bytes(self.data)
 38
 39
 40class Files:
 41    """Create, inspect, download, page, and delete managed file resources.
 42
 43    Access this service as ``InttegroClient.files``. Methods use the client's shared transport and return the typed resource shapes documented below.
 44    """
 45
 46    def __init__(self, http: HttpClient):
 47        """Bind file operations to the client's shared HTTP transport."""
 48        self.http = http
 49
 50    def create(
 51        self,
 52        *,
 53        file: str,
 54        purpose: str,
 55        title: str | None = None,
 56        custom_data: dict[str, str] | None = None,
 57        idempotency_key: str | None = None,
 58    ) -> File:
 59        """Upload ``file`` and create a managed file for the stated ``purpose``.
 60
 61        ``custom_data`` contains merchant-defined string metadata. Reuse
 62        ``idempotency_key`` when retrying the same logical upload.
 63        """
 64        headers = {"Idempotency-Key": idempotency_key} if idempotency_key else {}
 65        return self.http.post_multipart(
 66            "/files/create",
 67            {"purpose": purpose, "title": title, "custom_data": custom_data},
 68            {"file": file},
 69            headers=headers,
 70        )
 71
 72    def lookup(self, file_id: str) -> File:
 73        """Return the file identified by ``file_id``.
 74
 75        API endpoint: ``/files/lookup``.
 76
 77        Args:
 78            file_id (str): Unique identifier of the file.
 79
 80        Returns:
 81            ``File`` decoded from the documented response shape.
 82
 83        Raises:
 84            APIError: The API rejected the request or could not complete it.
 85            NetworkError: The request could not reach the Inttegro API.
 86            TimeoutError: The configured request deadline elapsed.
 87        """
 88        return self.http.post("/files/lookup", {"file_id": file_id})
 89
 90    def page(self, payload: PageRequest | None = None) -> Page:
 91        """Return a page of files visible to the authenticated application.
 92
 93        API endpoint: ``/files/page``.
 94
 95        Args:
 96            payload (PageRequest | None): Typed request object or equivalent request mapping for this operation.
 97
 98        Returns:
 99            ``Page`` decoded from the documented response shape.
100
101        Raises:
102            APIError: The API rejected the request or could not complete it.
103            NetworkError: The request could not reach the Inttegro API.
104            TimeoutError: The configured request deadline elapsed.
105        """
106        return self.http.post("/files/page", payload or {})
107
108    def contents(self, *, file_id: str, disposition: str = "attachment") -> FileDownload:
109        """Download ``file_id`` with the requested content ``disposition``.
110
111        API endpoint: ``/files/contents``.
112
113        Args:
114            file_id (str): Unique identifier of the file.
115            disposition (str): Requested content disposition for the download response.
116
117        Returns:
118            ``FileDownload`` decoded from the documented response shape.
119
120        Raises:
121            APIError: The API rejected the request or could not complete it.
122            NetworkError: The request could not reach the Inttegro API.
123            TimeoutError: The configured request deadline elapsed.
124        """
125        data, headers = self.http.post_binary_json(
126            "/files/contents",
127            {"file_id": file_id, "disposition": disposition},
128        )
129        return FileDownload(data, headers)
130
131    def delete(self, file_id: str) -> File:
132        """Delete ``file_id`` and return its final typed file state.
133
134        API endpoint: ``/files/delete``.
135
136        Args:
137            file_id (str): Unique identifier of the file.
138
139        Returns:
140            ``File`` decoded from the documented response shape.
141
142        Raises:
143            APIError: The API rejected the request or could not complete it.
144            NetworkError: The request could not reach the Inttegro API.
145            TimeoutError: The configured request deadline elapsed.
146        """
147        return self.http.post("/files/delete", {"file_id": file_id})
class FileDownload:
13class FileDownload:
14    """Binary file content and the response headers needed to save it safely.
15
16    This local helper never performs an API request by itself.
17    """
18
19    data: bytes
20    """Raw response bytes exactly as returned by the file content endpoint."""
21    headers: dict[str, str]
22    """Response headers normalized by the HTTP transport."""
23
24    def __init__(self, data: bytes, headers: dict[str, str] | None = None) -> None:
25        """Create a download value from response ``data`` and optional ``headers``."""
26        self.data = data
27        self.headers = headers or {}
28
29    def save_to(self, path: str) -> None:
30        """Write the downloaded bytes to ``path``.
31
32        Args:
33            path (str): Documented path value for this operation.
34
35        Returns:
36            ``None`` after the local operation completes.
37        """
38        Path(path).write_bytes(self.data)

Binary file content and the response headers needed to save it safely.

This local helper never performs an API request by itself.

FileDownload(data: bytes, headers: dict[str, str] | None = None)
24    def __init__(self, data: bytes, headers: dict[str, str] | None = None) -> None:
25        """Create a download value from response ``data`` and optional ``headers``."""
26        self.data = data
27        self.headers = headers or {}

Create a download value from response data and optional headers.

data: bytes

Raw response bytes exactly as returned by the file content endpoint.

headers: dict[str, str]

Response headers normalized by the HTTP transport.

def save_to(self, path: str) -> None:
29    def save_to(self, path: str) -> None:
30        """Write the downloaded bytes to ``path``.
31
32        Args:
33            path (str): Documented path value for this operation.
34
35        Returns:
36            ``None`` after the local operation completes.
37        """
38        Path(path).write_bytes(self.data)

Write the downloaded bytes to path.

Arguments:
  • path (str): Documented path value for this operation.
Returns:

None after the local operation completes.

class Files:
 41class Files:
 42    """Create, inspect, download, page, and delete managed file resources.
 43
 44    Access this service as ``InttegroClient.files``. Methods use the client's shared transport and return the typed resource shapes documented below.
 45    """
 46
 47    def __init__(self, http: HttpClient):
 48        """Bind file operations to the client's shared HTTP transport."""
 49        self.http = http
 50
 51    def create(
 52        self,
 53        *,
 54        file: str,
 55        purpose: str,
 56        title: str | None = None,
 57        custom_data: dict[str, str] | None = None,
 58        idempotency_key: str | None = None,
 59    ) -> File:
 60        """Upload ``file`` and create a managed file for the stated ``purpose``.
 61
 62        ``custom_data`` contains merchant-defined string metadata. Reuse
 63        ``idempotency_key`` when retrying the same logical upload.
 64        """
 65        headers = {"Idempotency-Key": idempotency_key} if idempotency_key else {}
 66        return self.http.post_multipart(
 67            "/files/create",
 68            {"purpose": purpose, "title": title, "custom_data": custom_data},
 69            {"file": file},
 70            headers=headers,
 71        )
 72
 73    def lookup(self, file_id: str) -> File:
 74        """Return the file identified by ``file_id``.
 75
 76        API endpoint: ``/files/lookup``.
 77
 78        Args:
 79            file_id (str): Unique identifier of the file.
 80
 81        Returns:
 82            ``File`` decoded from the documented response shape.
 83
 84        Raises:
 85            APIError: The API rejected the request or could not complete it.
 86            NetworkError: The request could not reach the Inttegro API.
 87            TimeoutError: The configured request deadline elapsed.
 88        """
 89        return self.http.post("/files/lookup", {"file_id": file_id})
 90
 91    def page(self, payload: PageRequest | None = None) -> Page:
 92        """Return a page of files visible to the authenticated application.
 93
 94        API endpoint: ``/files/page``.
 95
 96        Args:
 97            payload (PageRequest | None): Typed request object or equivalent request mapping for this operation.
 98
 99        Returns:
100            ``Page`` decoded from the documented response shape.
101
102        Raises:
103            APIError: The API rejected the request or could not complete it.
104            NetworkError: The request could not reach the Inttegro API.
105            TimeoutError: The configured request deadline elapsed.
106        """
107        return self.http.post("/files/page", payload or {})
108
109    def contents(self, *, file_id: str, disposition: str = "attachment") -> FileDownload:
110        """Download ``file_id`` with the requested content ``disposition``.
111
112        API endpoint: ``/files/contents``.
113
114        Args:
115            file_id (str): Unique identifier of the file.
116            disposition (str): Requested content disposition for the download response.
117
118        Returns:
119            ``FileDownload`` decoded from the documented response shape.
120
121        Raises:
122            APIError: The API rejected the request or could not complete it.
123            NetworkError: The request could not reach the Inttegro API.
124            TimeoutError: The configured request deadline elapsed.
125        """
126        data, headers = self.http.post_binary_json(
127            "/files/contents",
128            {"file_id": file_id, "disposition": disposition},
129        )
130        return FileDownload(data, headers)
131
132    def delete(self, file_id: str) -> File:
133        """Delete ``file_id`` and return its final typed file state.
134
135        API endpoint: ``/files/delete``.
136
137        Args:
138            file_id (str): Unique identifier of the file.
139
140        Returns:
141            ``File`` decoded from the documented response shape.
142
143        Raises:
144            APIError: The API rejected the request or could not complete it.
145            NetworkError: The request could not reach the Inttegro API.
146            TimeoutError: The configured request deadline elapsed.
147        """
148        return self.http.post("/files/delete", {"file_id": file_id})

Create, inspect, download, page, and delete managed file resources.

Access this service as InttegroClient.files. Methods use the client's shared transport and return the typed resource shapes documented below.

Files(http: inttegro.http_client.HttpClient)
47    def __init__(self, http: HttpClient):
48        """Bind file operations to the client's shared HTTP transport."""
49        self.http = http

Bind file operations to the client's shared HTTP transport.

http
def create( self, *, file: str, purpose: str, title: str | None = None, custom_data: dict[str, str] | None = None, idempotency_key: str | None = None) -> inttegro.file.File:
51    def create(
52        self,
53        *,
54        file: str,
55        purpose: str,
56        title: str | None = None,
57        custom_data: dict[str, str] | None = None,
58        idempotency_key: str | None = None,
59    ) -> File:
60        """Upload ``file`` and create a managed file for the stated ``purpose``.
61
62        ``custom_data`` contains merchant-defined string metadata. Reuse
63        ``idempotency_key`` when retrying the same logical upload.
64        """
65        headers = {"Idempotency-Key": idempotency_key} if idempotency_key else {}
66        return self.http.post_multipart(
67            "/files/create",
68            {"purpose": purpose, "title": title, "custom_data": custom_data},
69            {"file": file},
70            headers=headers,
71        )

Upload file and create a managed file for the stated purpose.

custom_data contains merchant-defined string metadata. Reuse idempotency_key when retrying the same logical upload.

def lookup(self, file_id: str) -> inttegro.file.File:
73    def lookup(self, file_id: str) -> File:
74        """Return the file identified by ``file_id``.
75
76        API endpoint: ``/files/lookup``.
77
78        Args:
79            file_id (str): Unique identifier of the file.
80
81        Returns:
82            ``File`` decoded from the documented response shape.
83
84        Raises:
85            APIError: The API rejected the request or could not complete it.
86            NetworkError: The request could not reach the Inttegro API.
87            TimeoutError: The configured request deadline elapsed.
88        """
89        return self.http.post("/files/lookup", {"file_id": file_id})

Return the file identified by file_id.

API endpoint: /files/lookup.

Arguments:
  • file_id (str): Unique identifier of the file.
Returns:

File decoded from the documented response shape.

Raises:
  • APIError: The API rejected the request or could not complete it.
  • NetworkError: The request could not reach the Inttegro API.
  • TimeoutError: The configured request deadline elapsed.
def page( self, payload: inttegro.file.PageRequest | None = None) -> inttegro.file.Page:
 91    def page(self, payload: PageRequest | None = None) -> Page:
 92        """Return a page of files visible to the authenticated application.
 93
 94        API endpoint: ``/files/page``.
 95
 96        Args:
 97            payload (PageRequest | None): Typed request object or equivalent request mapping for this operation.
 98
 99        Returns:
100            ``Page`` decoded from the documented response shape.
101
102        Raises:
103            APIError: The API rejected the request or could not complete it.
104            NetworkError: The request could not reach the Inttegro API.
105            TimeoutError: The configured request deadline elapsed.
106        """
107        return self.http.post("/files/page", payload or {})

Return a page of files visible to the authenticated application.

API endpoint: /files/page.

Arguments:
  • payload (PageRequest | None): Typed request object or equivalent request mapping for this operation.
Returns:

Page decoded from the documented response shape.

Raises:
  • APIError: The API rejected the request or could not complete it.
  • NetworkError: The request could not reach the Inttegro API.
  • TimeoutError: The configured request deadline elapsed.
def contents( self, *, file_id: str, disposition: str = 'attachment') -> FileDownload:
109    def contents(self, *, file_id: str, disposition: str = "attachment") -> FileDownload:
110        """Download ``file_id`` with the requested content ``disposition``.
111
112        API endpoint: ``/files/contents``.
113
114        Args:
115            file_id (str): Unique identifier of the file.
116            disposition (str): Requested content disposition for the download response.
117
118        Returns:
119            ``FileDownload`` decoded from the documented response shape.
120
121        Raises:
122            APIError: The API rejected the request or could not complete it.
123            NetworkError: The request could not reach the Inttegro API.
124            TimeoutError: The configured request deadline elapsed.
125        """
126        data, headers = self.http.post_binary_json(
127            "/files/contents",
128            {"file_id": file_id, "disposition": disposition},
129        )
130        return FileDownload(data, headers)

Download file_id with the requested content disposition.

API endpoint: /files/contents.

Arguments:
  • file_id (str): Unique identifier of the file.
  • disposition (str): Requested content disposition for the download response.
Returns:

FileDownload decoded from the documented response shape.

Raises:
  • APIError: The API rejected the request or could not complete it.
  • NetworkError: The request could not reach the Inttegro API.
  • TimeoutError: The configured request deadline elapsed.
def delete(self, file_id: str) -> inttegro.file.File:
132    def delete(self, file_id: str) -> File:
133        """Delete ``file_id`` and return its final typed file state.
134
135        API endpoint: ``/files/delete``.
136
137        Args:
138            file_id (str): Unique identifier of the file.
139
140        Returns:
141            ``File`` decoded from the documented response shape.
142
143        Raises:
144            APIError: The API rejected the request or could not complete it.
145            NetworkError: The request could not reach the Inttegro API.
146            TimeoutError: The configured request deadline elapsed.
147        """
148        return self.http.post("/files/delete", {"file_id": file_id})

Delete file_id and return its final typed file state.

API endpoint: /files/delete.

Arguments:
  • file_id (str): Unique identifier of the file.
Returns:

File decoded from the documented response shape.

Raises:
  • APIError: The API rejected the request or could not complete it.
  • NetworkError: The request could not reach the Inttegro API.
  • TimeoutError: The configured request deadline elapsed.