Quickstart Code Example
Split and classify a bundle from your own storage — in Python
The Prep API works bucket to bucket: you tell it where a document already lives in your cloud storage and where to write the output, and it reads and writes directly. Nothing is uploaded through the API, so this example needs a little more setup than a plain file post — you supply storage credentials alongside your own.
Create a client
The API accepts either of two credentials, and get_auth_session returns the
right kind of session for whichever you pass. Two things hold for both: the API
URL is the first positional argument — it is what the issued token is scoped
to — and credentials is a dictionary.
Each tab below is complete on its own: the storage credentials are the same for both, your own are not.
API key
IAM username and password
An API key is sent in the x-api-key header. Emtelligent issues the key; it
never expires on its own.
Describe the job
InputDocument names the object to process, the buckets to read and write, and
the credentials the service should use for them. operation='split-ocr-ep' runs
the full set of functions — split, classify, OCR and metadata extraction.
The keys in cloud_credential_set are passed straight through to the cloud
client, so they are that provider’s own parameter names — aws_ prefix included.
For S3 they are aws_access_key_id and aws_secret_access_key, plus
aws_session_token if you are using temporary credentials. For Azure, either
connection_string, or account_name with one of account_primary_access_key or
sas_token. Anything else comes back as Invalid cred format for s3.
Output is written to <output_bucket_prefix>/<job_id>/, and get_result looks
under exactly that path. Pass the prefix rather than leaving it out: SDK versions
up to 1.1.3 default it to the literal string unused, so output arrives under a
folder nobody chose — and those versions ignore the prefix when fetching, so
get_result returns nothing whatever you pass. If it comes back empty, check your
version with pip show emtellisplit-sdk-python; the objects are in the bucket
either way.
These credentials are used by the service to read your input bucket and write
your output bucket. Scope them to exactly those two buckets rather than reusing
a broad key, and prefer temporary credentials — pass the aws_session_token
they come with alongside the key and secret.
Submit and wait
process returns a ResultFuture, and it has to be awaited — it polls the
job on an asyncio task, so it only works inside async code. Both spellings below
do the same thing.
Awaiting gives you a CloudResult if the job succeeded and a plain Result if it
failed or was cancelled, so isinstance is the success test.
Prefer to stay synchronous? submit returns a DeferredResult instead, which is
deliberately not awaitable — you poll it yourself. A JobStatus is truthy once the
job reaches a terminal state.
Fetch the output
The split documents are in your output bucket, and get_result reads them back.
These credentials are not sent to the service — this call is your own client
listing and reading your own bucket — so they only need list and read on it.
Check output.docs rather than looping straight over it. get_result returns an
empty collection when it finds nothing in the bucket — it does not raise — so a
bare loop over it prints nothing and looks like a job that produced no documents.
One bundle in gives many documents out — that is the split — each with the category and subcategory the classifier assigned and the pages it came from.
The whole thing
Only the session differs between the two, so pick the tab you set up above.
API key
IAM username and password
If get_result finds nothing, the output is still there — list your bucket under
<output_bucket_prefix>/<job_id>/ and you will see it. That gap between where the
service writes and where the SDK looks is the version difference described above,
not a job that produced nothing.
