If you’re used to working the Unstructured Open Source library but would like to leverage the advanced capabilities of the Unstructured API services, you can do so without leaving the comfort and familiarity of the open source library. Whether you’re using the free Unstructured API, the Unstructured Serverless API, Unstructured API on Azure/AWS or your local deployment of Unstructured API, you can access it from the open source library through partition_via_api. You’ll also need:

These environment variables:

  • UNSTRUCTURED_API_KEY - Your Unstructured API key value.
  • UNSTRUCTURED_API_URL - Your Unstructured API URL.

Get your API key and API URL.

Installation

Make sure you have the Unstructured Open Source library installed. Refer to the Unstructured Open Source library Quickstart guide for instructions.

Basics

Here’s a basic example in which you send an email file to partition via Unstructured API using partition_via_api available in the Unstructured Open Source library:

import os

from unstructured.partition.api import partition_via_api

elements = partition_via_api(
    filename="example-docs/eml/fake-email.eml",
    api_key=os.getenv("UNSTRUCTURED_API_KEY"),
    api_url=os.getenv("UNSTRUCTURED_API_URL"),
    content_type="message/rfc822"
    )

When sending a request to the free Unstructured API, you only need to provide your individual API key. When sending requests to the Unstructured Serverless API, you need to supply your unique API URL in addition to your API key. For Unstructured API on Azure/AWS, use the API URL that you configured through those services.

The partition_via_api function in the open source library processes single files only. To process multiple files at a time, use the Unstructured CLI or the open source library with their provided source connectors and destination connectors.

Parameters & examples

The API parameters are the same across all methods of accessing the Unstructured API.

  • Refer to the API parameters page for the full list of available parameters.
  • Refer to the Examples page for some inspiration on using the parameters.