### Python SDK Quick Start Source: https://documentation.datalab.to/docs/recipes/create-document/create-document-api-overview Import the DatalabClient to begin using the SDK. Ensure you have the SDK installed. ```python from datalab_sdk import DatalabClient ``` -------------------------------- ### Python SDK Setup and Basic Usage Source: https://documentation.datalab.to/docs/recipes/conversion/conversion-api-overview Install the Datalab Python SDK and initialize the client. Ensure your DATALAB_API_KEY environment variable is set. This snippet demonstrates the basic import and client instantiation. ```python from datalab_sdk import DatalabClient, ConvertOptions client = DatalabClient() ``` -------------------------------- ### Python SDK Quick Start Source: https://documentation.datalab.to/docs/recipes/create-document/create-document-api-overview Initialize the DatalabClient and prepare markdown content for conversion. This snippet demonstrates the basic setup for using the Python SDK to convert markdown to a document. ```python from datalab_sdk import DatalabClient client = DatalabClient() markdown = "# Contract" ``` -------------------------------- ### Add Template Examples Source: https://documentation.datalab.to/docs/common/supportedfiletypes Upload example files for a template. ```APIDOC ## POST /api/v1/pipeline_templates/{slug}/examples ### Description Upload example files for a template. ### Method POST ### Endpoint /api/v1/pipeline_templates/{slug}/examples ### Parameters #### Path Parameters - **slug** (string) - Required - The slug of the pipeline template. ``` -------------------------------- ### Add Template Examples Source: https://documentation.datalab.to/docs/on-prem/api Upload example files for a template. ```APIDOC ## POST /api/v1/pipeline_templates/{slug}/examples ### Description Uploads example files for a specific pipeline template. ### Method POST ### Endpoint /api/v1/pipeline_templates/{slug}/examples ### Parameters #### Path Parameters - **slug** (string) - Required - The unique slug of the pipeline template. ### Request Body - **files** (array) - Required - An array of files to upload as examples. ``` -------------------------------- ### Add Template Examples Source: https://documentation.datalab.to/docs/recipes/pipelines/pipeline-versioning Upload example files for a template. ```APIDOC ## POST /api/v1/pipeline_templates/{slug}/examples ### Description Uploads example files for a specific pipeline template. ### Method POST ### Endpoint /api/v1/pipeline_templates/{slug}/examples ### Parameters #### Path Parameters - **slug** (string) - Required - The unique slug identifier of the template. #### Request Body - **files** (array) - Required - An array of files to upload as examples. ``` -------------------------------- ### Add Template Examples Source: https://documentation.datalab.to/docs/on-prem/overview Upload example files for a template. ```APIDOC ## POST /api/v1/pipeline_templates/{slug}/examples ### Description Upload example files for a template. ### Method POST ### Endpoint /api/v1/pipeline_templates/{slug}/examples ### Parameters #### Path Parameters - **slug** (string) - Required - The slug of the pipeline template. ### Request Body - **files** (array) - Required - An array of example files to upload. ``` -------------------------------- ### Add Template Examples Source: https://documentation.datalab.to/docs/recipes/create-document/create-document-api-overview Upload example files for a template. ```APIDOC ## POST /api/v1/pipeline_templates/{slug}/examples ### Description Upload example files for a template. ### Method POST ### Endpoint /api/v1/pipeline_templates/{slug}/examples ``` -------------------------------- ### Add Template Examples Source: https://documentation.datalab.to/docs/common/supportedfiletypes Upload example files for a template. ```APIDOC ## POST /api/v1/processor_templates/{slug}/examples ### Description Upload example files for a template. ### Method POST ### Endpoint /api/v1/processor_templates/{slug}/examples ### Parameters #### Path Parameters - **slug** (string) - Required - The slug of the template. ### Request Body - **files** (array) - Required - An array of example files to upload. ``` -------------------------------- ### Add Template Examples Source: https://documentation.datalab.to/docs/recipes/pipelines/pipeline-overview Uploads example files for a template. ```APIDOC ## POST /api/v1/processor_templates/{slug}/examples ### Description Upload example files for a template. ### Method POST ### Endpoint /api/v1/processor_templates/{slug}/examples ### Parameters #### Path Parameters - **slug** (string) - Required - The unique slug of the template. #### Request Body - **files** (array) - Required - An array of example files to upload. ``` -------------------------------- ### Add Template Examples Source: https://documentation.datalab.to/docs/recipes/pipelines/pipeline-overview Uploads example files for a template. ```APIDOC ## POST /api/v1/pipeline_templates/{slug}/examples ### Description Uploads example files for a template. ### Method POST ### Endpoint /api/v1/pipeline_templates/{slug}/examples ``` -------------------------------- ### Add Template Examples Source: https://documentation.datalab.to/docs/recipes/conversion/batch-documents Uploads example files for a template. ```APIDOC ## POST /api/v1/processor_templates/{slug}/examples ### Description Uploads example files for a template. ### Method POST ### Endpoint /api/v1/processor_templates/{slug}/examples ### Parameters #### Path Parameters - **slug** (string) - Required - The unique identifier (slug) of the template. ### Request Body - **files** (array of files) - Required - The example files to upload. ``` -------------------------------- ### Add Template Examples Source: https://documentation.datalab.to/docs/recipes/extract-redlines-and-comments/track-changes-from-word-documents Upload example files for a template. ```APIDOC ## POST /api/v1/processor_templates/{slug}/examples ### Description Upload example files for a template. ### Method POST ### Endpoint /api/v1/processor_templates/{slug}/examples ### Parameters #### Path Parameters - **slug** (string) - Required - The slug of the template to add examples to. ### Request Body - **files** (file) - Required - The example files to upload. ``` -------------------------------- ### Add Template Examples Source: https://documentation.datalab.to/docs/on-prem/usage-analytics Uploads example files for a template. ```APIDOC ## POST /api/v1/processor_templates/{slug}/examples ### Description Uploads example files for a template. ### Method POST ### Endpoint /api/v1/processor_templates/{slug}/examples ### Parameters #### Path Parameters - **slug** (string) - Required - The unique slug of the template. #### Request Body - **files** (file) - Required - The example files to upload. ``` -------------------------------- ### Add Template Examples Source: https://documentation.datalab.to/docs/recipes/document-segmentation/auto-segmentation Uploads example files for a template. ```APIDOC ## POST /api/v1/processor_templates/{slug}/examples ### Description Upload example files for a template. ### Method POST ### Endpoint /api/v1/processor_templates/{slug}/examples ### Parameters #### Path Parameters - **slug** (string) - Required - The unique slug of the template. ### Request Body - **files** (file) - Required - The example files to upload. ``` -------------------------------- ### Download Template Example Source: https://documentation.datalab.to/docs/welcome/sdk/conversion Downloads an example of a processor template. ```APIDOC ## GET /api-reference/processor-templates/download-template-example ### Description Downloads an example of a processor template. ### Method GET ### Endpoint /api-reference/processor-templates/download-template-example ### Query Parameters - **template_id** (string) - Required - The ID of the processor template. ``` -------------------------------- ### Datalab CLI Command-Specific Help Examples Source: https://documentation.datalab.to/docs/welcome/sdk/cli Examples of how to get help for specific Datalab CLI commands like convert, extract, segment, track-changes, and custom-pipeline. ```shellscript # Command-specific help datalab convert --help ``` ```shellscript datalab extract --help ``` ```shellscript datalab segment --help ``` ```shellscript datalab track-changes --help ``` ```shellscript datalab custom-pipeline --help ``` -------------------------------- ### Download Template Example Source: https://documentation.datalab.to/docs/recipes/conversion/batch-documents Fetches an example file from R2 storage and returns its content directly. ```APIDOC ## GET /api/v1/processor_templates/{slug}/examples/{filename} ### Description Fetches an example file from R2 storage and returns its content directly. ### Method GET ### Endpoint /api/v1/processor_templates/{slug}/examples/{filename} ### Parameters #### Path Parameters - **slug** (string) - Required - The unique identifier (slug) of the template. - **filename** (string) - Required - The name of the example file to download. ``` -------------------------------- ### Download Template Example Source: https://documentation.datalab.to/docs/recipes/pipelines/pipeline-versioning Fetch example file from R2 and return content directly. ```APIDOC ## GET /api/v1/pipeline_templates/{slug}/examples/{filename} ### Description Fetches an example file from R2 and returns its content directly. ### Method GET ### Endpoint /api/v1/pipeline_templates/{slug}/examples/{filename} ### Parameters #### Path Parameters - **slug** (string) - Required - The unique slug identifier of the template. - **filename** (string) - Required - The name of the example file to download. ``` -------------------------------- ### Download Template Example Source: https://documentation.datalab.to/docs/common/supportedfiletypes Fetch example file from R2 and return content directly. ```APIDOC ## GET /api/v1/pipeline_templates/{slug}/examples/{filename} ### Description Fetch example file from R2 and return content directly. ### Method GET ### Endpoint /api/v1/pipeline_templates/{slug}/examples/{filename} ### Parameters #### Path Parameters - **slug** (string) - Required - The slug of the pipeline template. - **filename** (string) - Required - The name of the example file. ``` -------------------------------- ### File Upload API - Python Example Source: https://documentation.datalab.to/docs/recipes/file-management/file-upload-api This example demonstrates how to upload a file using the Datalab API with Python. It includes setting up the API key, headers, and making a POST request to get an upload URL, followed by sending the file data. ```APIDOC ## POST /api/v1/files/upload ### Description Requests a pre-signed URL for uploading a file. ### Method POST ### Endpoint https://www.datalab.to/api/v1/files/upload ### Request Body - **filename** (string) - Required - The name of the file to be uploaded. - **content_type** (string) - Required - The MIME type of the file. ### Request Example ```json { "filename": "example.txt", "content_type": "text/plain" } ``` ### Response #### Success Response (200) - **upload_url** (string) - The URL to which the file should be uploaded. - **file_id** (string) - The unique identifier for the uploaded file. #### Response Example ```json { "upload_url": "https://datalab-uploads.s3.amazonaws.com/your-unique-upload-id?AWSAccessKeyId=...", "file_id": "your-file-id" } ``` ## PUT [upload_url] ### Description Uploads the file content to the provided upload URL. ### Method PUT ### Endpoint [upload_url from previous response] ### Request Body [File content] ### Response #### Success Response (200) Indicates successful upload. ### Complete Python Example ```python import requests API_KEY = "YOUR_API_KEY" headers = { "X-API-Key": API_KEY } # Step 1: Request upload URL response = requests.post( "https://www.datalab.to/api/v1/files/upload", json={ "filename": "example.txt", "content_type": "text/plain" }, headers=headers ) if response.status_code == 200: data = response.json() upload_url = data["upload_url"] file_id = data["file_id"] # Step 2: Upload the file content with open("example.txt", "rb") as f: file_content = f.read() upload_response = requests.put(upload_url, data=file_content, headers={ "Content-Type": "text/plain" }) if upload_response.status_code == 200: print(f"File uploaded successfully! File ID: {file_id}") else: print(f"File upload failed: {upload_response.text}") else: print(f"Failed to get upload URL: {response.text}") ``` ``` -------------------------------- ### Retrieve Processor Results in Python Source: https://documentation.datalab.to/docs/recipes/pipelines/run-pipeline Fetch the output of a specific processor within a pipeline. This example shows how to get the result for a step at a given index. ```python # Get result for step at index 1 (e.g., extract step) result = pipeline.steps[1].result ``` -------------------------------- ### Download Template Example Source: https://documentation.datalab.to/docs/on-prem/overview Fetch example file from R2 and return content directly. ```APIDOC ## GET /api/v1/processor_templates/{slug}/examples/{filename} ### Description Fetch example file from R2 and return content directly. ### Method GET ### Endpoint /api/v1/processor_templates/{slug}/examples/{filename} ``` -------------------------------- ### Pipeline Templates (Deprecated) Source: https://documentation.datalab.to/docs/welcome/sdk Deprecated endpoints for managing pipeline templates, including listing, promoting, getting, updating, removing, and downloading templates and examples. ```APIDOC ## Pipeline Templates API (Deprecated) ### Description Deprecated endpoints for managing pipeline templates, including listing, promoting, getting, updating, removing, and downloading templates and examples. ### Endpoints #### `GET /api-reference/pipeline-templates-deprecated/list-templates` List all pipeline templates. #### `POST /api-reference/pipeline-templates-deprecated/promote-to-template` Promote a pipeline to a template. #### `GET /api-reference/pipeline-templates-deprecated/get-template` Retrieve details of a specific pipeline template. #### `PUT /api-reference/pipeline-templates-deprecated/update-template` Update an existing pipeline template. #### `DELETE /api-reference/pipeline-templates-deprecated/remove-template` Remove a pipeline template. #### `GET /api-reference/pipeline-templates-deprecated/download-template-example` Download an example for a pipeline template. #### `DELETE /api-reference/pipeline-templates-deprecated/remove-template-example` Remove an example from a pipeline template. #### `GET /api-reference/pipeline-templates-deprecated/download-template-example-thumbnail` Download a thumbnail for a template example. #### `POST /api-reference/pipeline-templates-deprecated/clone-template` Clone a pipeline template. #### `POST /api-reference/pipeline-templates-deprecated/add-template-examples` Add examples to a pipeline template. ``` -------------------------------- ### Download Template Example Source: https://documentation.datalab.to/docs/common/supportedfiletypes Fetch example file from R2 and return content directly. ```APIDOC ## GET /api/v1/processor_templates/{slug}/examples/{filename} ### Description Fetch example file from R2 and return content directly. ### Method GET ### Endpoint /api/v1/processor_templates/{slug}/examples/{filename} ### Parameters #### Path Parameters - **slug** (string) - Required - The slug of the template. - **filename** (string) - Required - The name of the example file. ``` -------------------------------- ### Get Batch Conversion Job Status Source: https://documentation.datalab.to/docs/recipes/conversion/batch-documents This example shows how to retrieve the status of a previously submitted batch conversion job using its job ID. ```APIDOC ## GET /v1/conversion/batch/{job_id}/status ### Description Retrieves the status of a batch document conversion job. ### Method GET ### Endpoint /v1/conversion/batch/{job_id}/status ### Parameters #### Path Parameters - **job_id** (string) - Required - The ID of the conversion job. ### Response #### Success Response (200 OK) - **job_id** (string) - The unique identifier for the conversion job. - **status** (string) - The current status of the job (e.g., 'pending', 'processing', 'completed', 'failed'). - **results_url** (string, optional) - URL to download converted documents if the job is completed. - **error_message** (string, optional) - Description of the error if the job failed. #### Response Example ```json { "job_id": "conv_job_12345abcde", "status": "completed", "results_url": "https://example.com/results/conv_job_12345abcde.zip" } ``` ``` -------------------------------- ### Download Template Example Source: https://documentation.datalab.to/docs/on-prem/api Fetch example file from R2 and return content directly. ```APIDOC ## GET /api/v1/pipeline_templates/{slug}/examples/{filename} ### Description Fetches an example file from R2 storage and returns its content directly. ### Method GET ### Endpoint /api/v1/pipeline_templates/{slug}/examples/{filename} ### Parameters #### Path Parameters - **slug** (string) - Required - The unique slug of the pipeline template. - **filename** (string) - Required - The name of the example file to download. ``` -------------------------------- ### Download Template Example Source: https://documentation.datalab.to/docs/recipes/pipelines/custom-processors Fetch example file from R2 and return content directly. ```APIDOC ## GET /api/v1/pipeline_templates/{slug}/examples/{filename} ### Description Fetch example file from R2 and return content directly. ### Method GET ### Endpoint /api/v1/pipeline_templates/{slug}/examples/{filename} ``` -------------------------------- ### Python Structured Extraction Example Source: https://documentation.datalab.to/docs/recipes/structured-extraction/balanced-mode Use this Python code to programmatically extract structured data. Ensure you have the necessary libraries installed and your API key configured. ```python _jsx(_components.span, { style: { color: "#1F2328", --shiki-dark: "#D4D4D4" }, children: ")" }) }) }), "\n", _jsxs(_components.span, { className: "line", children: [_jsx(_components.span, { style: { color: "#0550AE", --shiki-dark: "#DCDCAA" }, children: "print" }), _jsx(_components.span, { style: { color: "#1F2328", --shiki-dark: "#D4D4D4" }, children: "(" }), _jsx(_components.span, { style: { color: "#CF222E", --shiki-dark: "#569CD6" }, children: "f" }), _jsx(_components.span, { style: { color: "#0A3069", --shiki-dark: "#CE9178" }, children: "\"Verified: " }), _jsx(_components.span, { style: { color: "#CF222E", --shiki-dark: "#569CD6" }, children: "{" }), _jsx(_components.span, { style: { color: "#1F2328", --shiki-dark: "#D4D4D4" }, children: "extracted[\" }), _jsx(_components.span, { style: { color: "#0A3069", --shiki-dark: "#CE9178" }, children: "'company_name_meta'" }), _jsx(_components.span, { style: { color: "#1F2328", --shiki-dark: "#D4D4D4" }, children: "][" }), _jsx(_components.span, { style: { color: "#0A3069", --shiki-dark: "#CE9178" }, children: "'verification'" }), _jsx(_components.span, { style: { color: "#1F2328", --shiki-dark: "#D4D4D4" }, children: "][" }), _jsx(_components.span, { style: { color: "#0A3069", --shiki-dark: "#CE9178" }, children: "'status'" }), _jsx(_components.span, { style: { color: "#1F2328", --shiki-dark: "#D4D4D4" }, children: "]" }), _jsx(_components.span, { style: { color: "#CF222E", --shiki-dark: "#569CD6" }, children: "}" }), _jsx(_components.span, { style: { color: "#0A3069", --shiki-dark: "#CE9178" }, children: "\"" }), _jsx(_components.span, { style: { color: "#1F2328", --shiki-dark: "#D4D4D4" }, children: ")" })] }), "\n"] }) }) }) ``` -------------------------------- ### Python SDK Quick Example Source: https://documentation.datalab.to/docs/welcome/sdk Demonstrates how to initialize the Datalab client, convert a PDF document to Markdown, and save the output. Ensure you have your API key configured. ```python from datalab_sdk import DatalabClient client = DatalabClient() # Convert a document to markdown result = client.convert("document.pdf") print(result.markdown) # Save output with images result.save_output("output/") ``` -------------------------------- ### Python Conversion Example Source: https://documentation.datalab.to/docs/recipes/conversion/conversion-api-overview Use this Python snippet to convert a document using the Conversion API. Ensure you have the Datalab client library installed and your API key configured. ```python from datalab import DatalabClient client = DatalabClient(api_key=os.environ.get("DATALAB_API_KEY")) options = { "output_format": "pdf", "output_filename": "document.pdf" } result = client.convert("document.pdf", options) print(result) ``` -------------------------------- ### Download Template Example Source: https://documentation.datalab.to/docs/welcome/api Fetches an example file from R2 storage and returns its content. ```APIDOC ## GET /api/v1/pipeline_templates/{slug}/examples/{filename} ### Description Retrieves the content of a specific example file associated with a pipeline template. ### Method GET ### Endpoint /api/v1/pipeline_templates/{slug}/examples/{filename} ### Parameters #### Path Parameters - **slug** (string) - Required - The slug of the pipeline template. - **filename** (string) - Required - The name of the example file to download. ``` -------------------------------- ### Manage Files with Datalab SDK Source: https://documentation.datalab.to/llms-full.txt Provides examples for managing files using the Datalab SDK, including listing, retrieving metadata, getting download URLs, and deleting files. ```python # List files result = client.list_files(limit=50) for file in result['files']: print(f"{file.original_filename}: {file.file_size} bytes") # Get metadata file = client.get_file_metadata(123) # Get download URL download = client.get_file_download_url(file_id=123, expires_in=3600) print(download['download_url']) # Delete file client.delete_file(123) ``` -------------------------------- ### Quick Start with Python SDK Source: https://documentation.datalab.to/docs/recipes/form-filling/form-filling-api-overview Initialize the Datalab client and set up form filling options. Make sure your DATALAB_API_KEY environment variable is set. ```python from datalab_sdk import DatalabClient, FormFillingOptions client = DatalabClient() ``` -------------------------------- ### Python SDK Pipeline Creation Example Source: https://documentation.datalab.to/docs/recipes/pipelines/pipeline-overview Create a pipeline that converts a document and extracts invoice data using the Datalab Python SDK. Ensure you have the SDK installed and a client initialized. ```python from datalab_sdk import DatalabClient, PipelineProcessor client = DatalabClient() # Define steps steps = ``` -------------------------------- ### Download Template Example Source: https://documentation.datalab.to/docs/recipes/form-filling/form-filling-api-overview Fetches an example file from R2 and returns its content directly. ```APIDOC ## GET /api/v1/pipeline_templates/{slug}/examples/{filename} ### Description Fetches an example file from R2 and returns its content directly. ### Method GET ### Endpoint /api/v1/pipeline_templates/{slug}/examples/{filename} ### Parameters #### Path Parameters - **slug** (string) - Required - The unique identifier of the pipeline template. - **filename** (string) - Required - The name of the example file to download. ``` -------------------------------- ### Example Schema Definition Source: https://documentation.datalab.to/docs/recipes/structured-extraction/api-overview This snippet shows a JSON schema definition for structured extraction. It includes fields like 'type', 'properties', 'nested_field', and 'required' fields to guide the extraction process. ```json { "type": "object", "properties": { "nested_field": { "type": "string" } }, "required": [ "field_name" ] } ``` -------------------------------- ### Download Template Example Source: https://documentation.datalab.to/docs/recipes/pipelines/pipeline-overview Fetches an example file from R2 and returns its content directly. ```APIDOC ## GET /api/v1/pipeline_templates/{slug}/examples/{filename} ### Description Fetches an example file from R2 and returns content directly. ### Method GET ### Endpoint /api/v1/pipeline_templates/{slug}/examples/{filename} ``` -------------------------------- ### Get LLM Usage Statistics (Custom Time Range) Source: https://documentation.datalab.to/llms-full.txt Retrieves usage statistics for a custom date range. Specify start and end dates in ISO format. Requires an API key. ```python import requests from datetime import datetime, timedelta, timezone # Query last 7 days end_date = datetime.now(timezone.utc) start_date = end_date - timedelta(days=7) response = requests.get( "http://localhost:8000/api/v1/usage", params={ "start_date": start_date.isoformat(), "end_date": end_date.isoformat() }, headers={"X-API-Key": "any-value"} ) data = response.json() ``` ```bash # Query specific date range curl -X GET "http://localhost:8000/api/v1/usage?start_date=2024-06-01T00:00:00Z&end_date=2024-06-07T23:59:59Z" \ -H "X-API-Key: any-value" ``` ```python import requests from datetime import datetime, timedelta, timezone # Query last 3 days end_date = datetime.now(timezone.utc) start_date = end_date - timedelta(days=3) response = requests.get( "http://localhost:8000/api/v1/usage", params={ "start_date": start_date.isoformat(), "end_date": end_date.isoformat() }, headers={"X-API-Key": "any-value"} ) data = response.json() print(f"Period: {data['period']['start_date']} to {data['period']['end_date']}") ``` -------------------------------- ### Download Template Example Source: https://documentation.datalab.to/docs/on-prem/usage-analytics Fetches an example file from R2 and returns its content directly. ```APIDOC ## GET /api/v1/processor_templates/{slug}/examples/{filename} ### Description Fetches an example file from R2 and returns its content directly. ### Method GET ### Endpoint /api/v1/processor_templates/{slug}/examples/{filename} ### Parameters #### Path Parameters - **slug** (string) - Required - The unique slug of the template. - **filename** (string) - Required - The name of the example file. ``` -------------------------------- ### Download Template Example Source: https://documentation.datalab.to/docs/common/limits Fetches an example file from R2 and returns its content directly. ```APIDOC ## GET /api/v1/processor_templates/{slug}/examples/{filename} ### Description Fetch example file from R2 and return content directly. ### Method GET ### Endpoint /api/v1/processor_templates/{slug}/examples/{filename} ### Parameters #### Path Parameters - **slug** (string) - Required - The unique slug identifier of the template. - **filename** (string) - Required - The name of the example file to download. ``` -------------------------------- ### Python API Request Example Source: https://documentation.datalab.to/docs/welcome/api This Python code snippet demonstrates how to make a GET request to an API endpoint and process the JSON response. It includes error handling and checks for specific status codes. ```python import requests import time check_url = "https://api.datalab.to/v1/check" headers = { "Authorization": "Bearer YOUR_API_KEY" } response = requests.get(check_url, headers=headers) result = response.json() if result["status"] == "complete": break time.sleep(2) print(result["markdown"]) ``` -------------------------------- ### Get Pipeline Step Result Source: https://documentation.datalab.to/docs/recipes/pipelines/run-pipeline This section provides examples for retrieving the result of a specific step within a pipeline execution. You can use cURL or Python's requests library to make the API call. ```APIDOC ## GET /pipelines/executions/EXECUTION_ID/steps/1/result ### Description Retrieves the result of a specific step in a pipeline execution. ### Method GET ### Endpoint /pipelines/executions/EXECUTION_ID/steps/1/result ### Parameters #### Query Parameters - **X-API-Key** (string) - Required - Your DataLab API key. ### Request Example #### cURL ```shell curl https://www.datalab.to/api/v1/pipelines/executions/EXECUTION_ID/steps/1/result \ -H "X-API-Key: $DATALAB_API_KEY" ``` #### Python (requests) ```python import requests execution_id = "YOUR_EXECUTION_ID" base_url = "https://www.datalab.to" response = requests.get( f"{base_url}/pipelines/executions/{execution_id}/steps/1/result", headers={ "X-API-Key": "YOUR_DATALAB_API_KEY" } ) print(response.json()) ``` ### Response #### Success Response (200) - **result** (any) - The result of the pipeline step. ``` -------------------------------- ### Fetch Usage Analytics Data Source: https://documentation.datalab.to/docs/on-prem/usage-analytics Use this snippet to make a GET request to the usage analytics API. Ensure you set the correct start and end dates for the desired period and include the 'X-API-Key' header for authentication. ```javascript const start = new Date(); const end = new Date(); const url = "http://localhost:8000/api/v1/usage" const params = {"start_date": start.isoformat(), "end_date": end.isoformat()} const headers = {"X-API-Key": "any-value"} data = response.json() avg_daily_requests = data["summary"]["total_requests"] / 7 avg_daily_pages = ``` -------------------------------- ### Download Template Example Source: https://documentation.datalab.to/docs/recipes/document-segmentation/auto-segmentation Fetches an example file from R2 and returns its content directly. ```APIDOC ## GET /api/v1/processor_templates/{slug}/examples/{filename} ### Description Fetch example file from R2 and return content directly. ### Method GET ### Endpoint /api/v1/processor_templates/{slug}/examples/{filename} ### Parameters #### Path Parameters - **slug** (string) - Required - The unique slug of the template. - **filename** (string) - Required - The name of the example file. ``` -------------------------------- ### Fetch Usage Data for Last 3 Days Source: https://documentation.datalab.to/docs/on-prem/usage-analytics This Python snippet demonstrates how to fetch usage analytics data for the past three days. It sets up the start and end dates and makes a GET request to the Datalab API. ```python import requests from datetime import datetime, timedelta, timezone # Query last 3 days end_date = datetime.now(timezone.utc) start_date = end_date - timedelta(days=3) response = requests.get( "http://localhost:8000/api/v1/usage", params={ "start_date": start_date.isoformat(), "end_date": end_date.isoformat() } ) print(response.json()) ``` -------------------------------- ### Download Template Example Source: https://documentation.datalab.to/docs/recipes/forge-evals/overview Fetches an example file from R2 and returns its content directly. ```APIDOC ## GET /api/v1/processor_templates/{slug}/examples/{filename} ### Description Fetch example file from R2 and return content directly. ### Method GET ### Endpoint /api/v1/processor_templates/{slug}/examples/{filename} ### Parameters #### Path Parameters - **slug** (string) - Required - The slug of the template. - **filename** (string) - Required - The name of the example file. ### Response (No specific response details provided in the source) ``` -------------------------------- ### Datalab CLI Help Examples Source: https://documentation.datalab.to/docs/welcome/sdk/cli Examples demonstrating how to access help for various Datalab CLI commands. Use these to understand the options available for each command. ```bash datalab convert --help ``` ```bash datalab extract --help ``` ```bash datalab segment --help ``` ```bash datalab track-changes --help ``` ```bash datalab custom-pipeline --help ``` ```bash datalab create-document --help ``` -------------------------------- ### Quick Start: Fill PDF Form with Python SDK Source: https://documentation.datalab.to/docs/recipes/form-filling/form-filling-api-overview Demonstrates how to use the Datalab SDK to fill a PDF form with provided field data. Ensure you have set up your Datalab account, API key, and installed the SDK. ```python from datalab_sdk import DatalabClient, FormFillingOptions client = DatalabClient() options = FormFillingOptions( field_data={ "name": {"value": "John Doe", "description": "Full name"}, "email": {"value": "john@example.com", "description": "Email address"}, "date": {"value": "12/15/2024", "description": "Today's date"}, } ) result = client.fill("form.pdf", options=options) result.save_output("filled_form.pdf") print(f"Fields filled: {result.fields_filled}") print(f"Fields not found: {result.fields_not_found}") ``` -------------------------------- ### Extract Data with Confidence Scoring (Python) Source: https://documentation.datalab.to/docs/recipes/structured-extraction/confidence-scoring Use the 'fast' extraction mode to get numeric confidence scores for each extracted field. This example shows how to send a PDF, poll for completion, and then retrieve and process the scored extraction results. ```python import requests, json, time, os headers = {"X-API-Key": os.getenv("DATALAB_API_KEY")} schema = { "type": "object", "properties": { "invoice_number": {"type": "string", "description": "Invoice ID or number"}, "total_amount": {"type": "number", "description": "Total amount due"}, "vendor_name": {"type": "string", "description": "Vendor or company name"} }, "required": ["invoice_number", "total_amount"] } with open("invoice.pdf", "rb") as f: resp = requests.post( "https://www.datalab.to/api/v1/extract", files={"file": ("invoice.pdf", f, "application/pdf")}, data={ "page_schema": json.dumps(schema), "extraction_mode": "fast" # scoring runs in fast mode only }, headers=headers ) check_url = resp.json()["request_check_url"] # Poll until extraction is complete while True: result = requests.get(check_url, headers=headers).json() if result["status"] == "complete": extracted = json.loads(result["extraction_schema_json"]) print("Extraction:", extracted) break time.sleep(2) # Scores are enriched asynchronously after completion. Keep polling the same # URL until extraction_score_average appears (bounded so we don't loop forever). for _ in range(30): if "extraction_score_average" in result: break time.sleep(2) result = requests.get(check_url, headers=headers).json() scored = json.loads(result["extraction_schema_json"]) for key, value in scored.items(): if key.endswith("_score"): field = key.replace("_score", "") print(f"{field}: score={value['score']}, reasoning={value['reasoning']}") ``` -------------------------------- ### Download Template Example Source: https://documentation.datalab.to/llms-full.txt Fetches an example file from R2 storage for a given processor template slug and filename. ```APIDOC ## GET /api/v1/processor_templates/{slug}/examples/{filename} ### Description Fetch example file from R2 and return content directly. ### Method GET ### Endpoint /api/v1/processor_templates/{slug}/examples/{filename} ### Parameters #### Path Parameters - **slug** (string) - Required - The unique identifier for the processor template. - **filename** (string) - Required - The name of the example file to download. ``` -------------------------------- ### Python Script for Usage Analytics Source: https://documentation.datalab.to/docs/on-prem/usage-analytics This Python script collects usage data for the last 7 days by making a GET request to a local API endpoint. It defines start and end dates for the query and includes parameters for the request. ```python import requests from datetime import datetime, timedelta, timezone # Query last 7 days end_date = datetime.now(timezone.utc) start_date = end_date - timedelta(days=7) response = requests.get( "http://localhost:8000/api/v1/usage", params={ ``` -------------------------------- ### Quick Start: Initialize Datalab Client Source: https://documentation.datalab.to/docs/recipes/document-segmentation/auto-segmentation Initialize the Datalab client in Python. Ensure your DATALAB_API_KEY environment variable is set. ```python import json from datalab_sdk import DatalabClient, SegmentOptions client = DatalabClient() ``` -------------------------------- ### Query Usage Analytics Data (Python) Source: https://documentation.datalab.to/docs/on-prem/usage-analytics This snippet demonstrates how to fetch usage analytics data for the last three days using the requests library in Python. It sets up start and end dates and makes a GET request to the specified API endpoint. ```python import requests from datetime import datetime, timedelta, timezone # Query last 3 days end_date = datetime.now(timezone.utc) start_date = end_date - timedelta(days=3) response = requests.get( "http://localhost:8000/api/v1/usage", params= { ``` -------------------------------- ### Install Datalab Python SDK Source: https://documentation.datalab.to/docs/recipes/form-filling/form-filling-api-overview Install the Datalab SDK using pip. Ensure you have Python 3.10+ installed. ```bash pip install datalab-python-sdk ``` -------------------------------- ### Get Pipeline Source: https://documentation.datalab.to/docs/recipes/pipelines/pipeline-overview Get pipeline by pipeline_id. ```APIDOC ## GET /api/v1/pipelines/{pipeline_id} ### Description Get pipeline by pipeline_id. ### Method GET ### Endpoint /api/v1/pipelines/{pipeline_id} #### Path Parameters - **pipeline_id** (string) - Required - The ID of the pipeline to retrieve. ``` -------------------------------- ### Get Pipeline Source: https://documentation.datalab.to/docs/common/supportedfiletypes Get pipeline by pipeline_id. ```APIDOC ## Get Pipeline ### Description Get pipeline by pipeline_id. ### Method GET ### Endpoint /api/v1/pipelines/{pipeline_id} ``` -------------------------------- ### Get Pipeline Source: https://documentation.datalab.to/docs/on-prem/overview Get pipeline by pipeline_id. ```APIDOC ## GET /api/v1/pipelines/{pipeline_id} ### Description Retrieves a pipeline by its unique identifier. ### Method GET ### Endpoint /api/v1/pipelines/{pipeline_id} ### Parameters #### Path Parameters - **pipeline_id** (string) - Required - The ID of the pipeline. ``` -------------------------------- ### Get Pipeline Source: https://documentation.datalab.to/docs/recipes/extract-redlines-and-comments/track-changes-from-word-documents Get pipeline by pipeline_id. ```APIDOC ## GET /api/v1/pipelines/{pipeline_id} ### Description Retrieves details of a specific pipeline using its unique identifier. ### Method GET ### Endpoint /api/v1/pipelines/{pipeline_id} ### Parameters #### Path Parameters - **pipeline_id** (string) - Required - The unique identifier of the pipeline. ``` -------------------------------- ### Get Workflow Source: https://documentation.datalab.to/docs/recipes/pipelines/pipeline-overview Get workflow definition with all steps. ```APIDOC ## GET /api/v1/workflows/workflows/{workflow_id} ### Description Retrieves a specific workflow definition along with all its associated steps. ### Method GET ### Endpoint /api/v1/workflows/workflows/{workflow_id} ### Parameters #### Path Parameters - **workflow_id** (string) - Required - The ID of the workflow to retrieve. ``` -------------------------------- ### Get Collection Source: https://documentation.datalab.to/docs/recipes/form-filling/form-filling-api-overview Get collection with file list. ```APIDOC ## GET /api/v1/collections/{collection_id} ### Description Get collection with file list. ### Method GET ### Endpoint /api/v1/collections/{collection_id} ### Parameters #### Path Parameters - **collection_id** (string) - Required - The ID of the collection to retrieve. ``` -------------------------------- ### Get Workflow Source: https://documentation.datalab.to/docs/recipes/conversion/batch-documents Get workflow definition with all steps. ```APIDOC ## GET /api/v1/workflows/workflows/{workflow_id} ### Description Get workflow definition with all steps. ### Method GET ### Endpoint /api/v1/workflows/workflows/{workflow_id} #### Path Parameters - **workflow_id** (string) - Required - The ID of the workflow to retrieve. ``` -------------------------------- ### Example of SDK Usage (Python) Source: https://documentation.datalab.to/docs/recipes/conversion/conversion-api-overview Illustrates how to use the SDK for document conversion, including setting the output format and processing mode. The SDK handles polling automatically. ```python from datalab.conversion import Conversion conversion = Conversion() # Convert a local file to markdown result = conversion.convert( file="/path/to/your/document.pdf", output_format="markdown", mode="fast" ) # Convert a document from a URL result = conversion.convert_from_url( file_url="https://example.com/document.docx", output_format="html", mode="fast" ) # Get the result print(result.text) ``` -------------------------------- ### Initialize DatalabClient and ConvertOptions Source: https://documentation.datalab.to/docs/recipes/conversion/conversion-api-overview Demonstrates how to initialize the DatalabClient and set up ConvertOptions for document conversion. Specify 'accurate' mode and 'markdown' output format. ```javascript import { DatalabClient, ConvertOptions } from "@datalab/datalab"; const client = DatalabClient() const options = ConvertOptions( mode: "accurate", output_format: "markdown" ) ``` -------------------------------- ### Get Workflow Source: https://documentation.datalab.to/docs/recipes/document-segmentation/auto-segmentation Get a workflow definition with all its steps. ```APIDOC ## GET /api/v1/workflows/workflows/{workflow_id} ### Description Get workflow definition with all steps. ### Method GET ### Endpoint /api/v1/workflows/workflows/{workflow_id} ### Parameters #### Path Parameters - **workflow_id** (string) - Required - The ID of the workflow to retrieve. ### Request Example None ### Response #### Success Response (200) - **workflow** (object) - The workflow definition. ```