Documentation for the Document AI Python SDK
[!NOTE] Python version upgrade policy Once a Python version reaches its official end of life date, a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.The SDK can be installed with either pip or poetry package managers.
pyproject.toml
file to handle project metadata and dependencies.
uv
uvx
command that comes with it like so:
uv run script.py
where
script.py
can be replaced with the actual file name.
Name | Type | Scheme | Environment Variable |
---|---|---|---|
api_key_auth | http | HTTP Bearer | DOCUMENTAI_API_KEY_AUTH |
api_key_auth
parameter must be set when initializing the SDK client instance. For example:
Next
method that can be called to pull down the next group of results. If the
return value of Next
is None
, then there are no more pages to be fetched.
Here’s an example of one such pagination call:
RetryConfig
object to the call:
retry_config
optional parameter when initializing the SDK:
Property | Type | Description |
---|---|---|
.status_code | int | The HTTP status code |
.message | str | The error message |
.raw_response | httpx.Response | The raw HTTP response |
.body | str | The response content |
list_async
method may raise the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
models.BadRequestError | 400 | application/json |
models.UnauthorizedError | 401 | application/json |
models.TooManyRequestsError | 429 | application/json |
models.InternalServerError | 500 | application/json |
models.APIError | 4XX, 5XX | */* |
server_url: str
optional parameter when initializing the SDK client instance. For example:
HttpClient
or AsyncHttpClient
respectively, which are Protocol’s ensuring that the client has the necessary methods to make API calls.
This allows you to wrap the client with your own custom logic, such as adding custom headers, logging, or error handling, or you can just pass an instance of httpx.Client
or httpx.AsyncClient
directly.
For example, you could specify a header for every request that this sdk makes as follows:
DocumentAi
class implements the context manager protocol and registers a finalizer function to close the underlying sync and async HTTPX clients it uses under the hood. This will close HTTP connections, release memory and free up other resources held by the SDK. In short-lived Python programs and notebooks that make a few SDK method calls, resource management may not be a concern. However, in longer-lived programs, it is beneficial to create a single SDK instance via a context manager and reuse it across the application.
DOCUMENTAI_DEBUG
to true.