Pulse-Version: 2 header on every request, and return typed results.
Install pulse-ai from PyPI for Python, or @pulse-software/sdk from npm for TypeScript:
Create a client
This code creates a client with the API key in thePULSE_API_KEY environment variable:
asyncio, Python also has AsyncPulse. It takes the same arguments and has the same calls, which you await.
Call an endpoint
Each endpoint is a group on the client, and every group has the same four calls. For Parse:classify, extract, split, tables, charts, pipeline and parse.batch work the same way. Saved configs sit in client.<endpoint>.configs, such as client.extract.configs. Webhooks sit in client.webhook, usage in client.usage.get(), and organization settings in client.settings.org.
Names and types
- Python uses the API’s field names, with a trailing underscore where a name clashes with Python:
async_,from_onusage.get, andjson_on a table’scontent. - TypeScript uses camelCase, such as
fileUrl, and sends the API’s names for you. - A
fileis an open file or bytes in Python, and a stream,BufferorBlobin TypeScript. - To read a response’s headers, such as the
Linkheader on a page of a batch’s manifest, use the raw response. In Python,client.parse.batch.with_raw_response.get_result(...)returns.dataand.headers. In TypeScript,.withRawResponse()on a call returns{ data, rawResponse }.
Errors
A failed request raises an error that carries the response’s status, headers and body. In Python it’sApiError, from pulse.core.api_error, with status_code, headers and body. In TypeScript it’s PulseError, with statusCode, rawResponse.headers and body. The body is the error’s problem details: branch on its code, and quote its request_id to support. Errors and retries explains each status and what to do about it.
Retries
The SDKs never retry a request on their own, and themax_retries (Python) and maxRetries (TypeScript) options have no effect. Add retries in your own code.
Reads are safe to retry: reading a job’s status or result never starts a job or costs credits. In an organization that deletes each result the first time it’s read, a retried result read gets 410 if the first read reached Pulse. This helper retries a read after a network error, a 429 or a 5xx, and honors Retry-After:
client is the client from above, and the parse id is one a run returned.
A job’s run is different. When a run fails with a 5xx or times out, Pulse may already have started the job:
Send long work with
async: true. The run then returns the job’s id within seconds, so a timeout is unlikely.
Timeouts
Calls have no timeout by default, so a call withoutasync waits until its job ends or the connection closes. To set one, pass timeout (Python) or timeoutInSeconds (TypeScript), in seconds, when you create the client.