This documentation covers the usage of the Python SDK for interacting with the Unstructured API.
The Python SDK allows for easy interaction with the Unstructured API using Python.
Whether you’re using the free Unstructured API, the SaaS Unstructured API, Unstructured API on Azure/AWS or your local
deployment of Unstructured API, you can access the API using the Python SDK.
Let’s start with a simple example in which you send a pdf document to partition via Unstructured API using the Python SDK:
Copy
Ask AI
from unstructured_client import UnstructuredClientfrom unstructured_client.models import sharedfrom unstructured_client.models.errors import SDKErrorclient = UnstructuredClient( api_key_auth="YOUR_API_KEY", # you may need to provide your unique API URL # server_url="YOUR_API_URL",)filename = "sample-docs/layout-parser-paper.pdf"file = open(filename, "rb")req = shared.PartitionParameters( # Note that this currently only supports a single file files=shared.Files( content=file.read(), file_name=filename, ), # Other parameters strategy="fast",)try: res = client.general.partition(req) print(res.elements[0])except SDKError as e: print(e)
In the example above we’re sending the request to the free Unstructured API, in which case the API URL is the same for all
users, and you don’t need to provide it. Note, however, that you still need to authenticate yourself with
your individual API Key.If you want to use the SaaS Unstructured API, you need to replace the URL in this example with the unique API URL that you have
received in the same email as your API key. For Unstructured API on Azure/AWS, use the API URL that you
configured through those services.