{"id":1770,"library":"unstructured-client","title":"Unstructured Python Client SDK","description":"The `unstructured-client` library provides a Python SDK to interact with the Unstructured API, enabling users to programmatically partition, clean, and extract structured data from various document types (PDFs, images, HTML, Word, etc.) using Unstructured's cloud services. It is actively maintained with frequent updates, often on a weekly or bi-weekly cadence, reflecting ongoing API developments. The current version is 0.43.2.","status":"active","version":"0.43.2","language":"en","source_language":"en","source_url":"https://github.com/Unstructured-IO/unstructured-client","tags":["unstructured","nlp","document-processing","api-client","etl","llm-preparation"],"install":[{"cmd":"pip install unstructured-client","lang":"bash","label":"Install `unstructured-client`"}],"dependencies":[],"imports":[{"symbol":"UnstructuredClient","correct":"from unstructured_client import UnstructuredClient"},{"note":"Parameters are located in `unstructured_client.models.shared`.","wrong":"from unstructured_client import PartitionParameters","symbol":"PartitionParameters","correct":"from unstructured_client.models.shared import PartitionParameters"},{"note":"File object definitions are located in `unstructured_client.models.shared`.","wrong":"from unstructured_client import File","symbol":"File","correct":"from unstructured_client.models.shared import File"}],"quickstart":{"code":"import os\nfrom unstructured_client import UnstructuredClient\nfrom unstructured_client.models.shared import PartitionParameters, File\n\n# --- IMPORTANT: Set your API key environment variable ---\n# export UNSTRUCTURED_API_KEY=\"YOUR_API_KEY\"\n# Get your key from: https://unstructured.io/api-key\n\ns = UnstructuredClient(\n    api_key_auth=os.environ.get(\"UNSTRUCTURED_API_KEY\", \"\")\n)\n\n# Create a dummy file for demonstration\ntry:\n    with open(\"example.pdf\", \"w\") as f:\n        f.write(\"This is a test document with some text.\")\nexcept Exception:\n    pass # Ignore if it exists or fails for simple dummy file\n\n# Example: Partitioning a local file\ntry:\n    with open(\"example.pdf\", \"rb\") as f:\n        # Prepare the file as a list of File objects for the API\n        files = [\n            File(\n                content=f.read(),\n                file_name=\"example.pdf\",\n                mime_type=\"application/pdf\"\n            )\n        ]\n        \n        # Call the partition endpoint with parameters\n        resp = s.general.partition(\n            partition_parameters=PartitionParameters(\n                files=files,\n                strategy=\"auto\", # 'fast', 'hi_res', 'auto'\n                coordinates=True, # Include bounding box coordinates\n                output_format=\"json\" # 'json' (default), 'text'\n            )\n        )\n        \n        # Print the extracted elements\n        print(\"Successfully partitioned document.\")\n        for element in resp.elements:\n            print(f\"Type: {element.type}, Text: {element.text[:70]}...\")\n\nexcept FileNotFoundError:\n    print(\"Please ensure 'example.pdf' exists in the current directory for this example.\")\nexcept Exception as e:\n    print(f\"An error occurred during partitioning: {e}\")\n    if \"API Key\" in str(e):\n        print(\"HINT: Ensure your UNSTRUCTURED_API_KEY environment variable is set correctly.\")\n    elif \"401\" in str(e) or \"403\" in str(e):\n        print(\"HINT: Check your API key for correctness and permissions.\")\n","lang":"python","description":"This quickstart demonstrates how to initialize the `UnstructuredClient` and partition a local PDF file using the `general.partition` endpoint. It highlights the use of `PartitionParameters` and `File` objects for robust API interaction and emphasizes environment variable-based API key management."},"warnings":[{"fix":"Use `unstructured-client` for API calls and `unstructured` for local, self-hosted processing. Ensure you import from the correct library (e.g., `from unstructured_client import UnstructuredClient`).","message":"The `unstructured-client` library is distinct from the `unstructured` library. `unstructured-client` interacts with the Unstructured Cloud API, while the `unstructured` library performs local document processing. Do not confuse their imports or functionalities.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always refer to the official Unstructured API documentation and the `unstructured-client` changelog for the specific version you are using. Update parameter names and request body formats as per the new specifications. Common changes include how files/URLs are passed or new sub-parameters.","message":"API endpoint parameters and request body structures can change between Unstructured API versions, which the client library wraps. This can lead to breaking changes in your code when upgrading `unstructured-client`.","severity":"breaking","affected_versions":"All minor and patch versions, but especially between minor versions (e.g., 0.x to 0.y)."},{"fix":"Obtain your API Key from the Unstructured website and set it as an environment variable (`export UNSTRUCTURED_API_KEY=\"YOUR_API_KEY\"`) before running your application, or pass it directly during client initialization (though environment variables are recommended for security).","message":"Authentication via API Key is mandatory for most Unstructured API endpoints. Failing to set the `UNSTRUCTURED_API_KEY` environment variable or providing an invalid key will result in `401 Unauthorized` or `403 Forbidden` errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}