Skip to main content

CruxGen SDK

Python SDK for CruxGen API - Create LLM-ready datasets from documents.

Installation

pip install cruxgen-sdk

Requirements

  • Python 3.13+
  • httpx 0.28.1+
  • orjson 3.11.3+

Quick Start

from cruxgen_sdk import CruxGenSDK

# Initialize SDK
with CruxGenSDK("http://localhost:8000") as sdk:
    # Health check
    health = sdk.health_check()
    print(health)

Initialization

sdk = CruxGenSDK(
    base_url="http://localhost:8000",  # API base URL
    timeout=300.0                      # Request timeout in seconds
)

Document Management

Create Bucket

result = sdk.create_bucket("my-bucket")

Upload File

result = sdk.upload_file("path/to/file.pdf", bucket_name="my-bucket")
file_id = result["response"]  # Extract file ID for further operations

Delete Object

result = sdk.delete_object("my-bucket", "file.pdf")

Delete Bucket

result = sdk.delete_bucket("my-bucket")

List Objects

# List all objects
objects = sdk.list_objects()

# List objects in specific bucket
objects = sdk.list_objects("my-bucket")

# List with prefix filter
objects = sdk.list_objects("my-bucket", prefix="docs/", recursive=True)

List Buckets

buckets = sdk.list_buckets()

Get Object Info

info = sdk.get_object_info("my-bucket", "file.pdf")

Get File ID by Name

file_info = sdk.get_file_id_by_name("file.pdf")
file_id = file_info["response"]

Chunk Management

Create Chunks

result = sdk.create_chunks(file_id, "my-bucket")

Get Chunks

chunks = sdk.get_chunks(file_id)
chunk_texts = chunks["response"]  # List of chunk texts

Delete Chunks

result = sdk.delete_chunks(file_id)

QA Management

Create QA Pairs

# Process all chunks
result = sdk.create_qa_pairs(file_id)

# Process specific chunk
result = sdk.create_qa_pairs(file_id, chunk_id="chunk-123")

Get QA Pairs

# Get as JSON
qa_pairs = sdk.get_qa_pairs(file_id)

# Download as JSONL file
qa_jsonl = sdk.get_qa_pairs(file_id, generate_jsonl=True)
if isinstance(qa_jsonl, bytes):
    with open(f"qa_pairs_{file_id}.jsonl", "wb") as f:
        f.write(qa_jsonl)

Delete QA Pairs

result = sdk.delete_qa_pairs(file_id)

Health Check

health = sdk.health_check()
status = health["status"]  # "ok" or "error"

Complete Workflow Example

from cruxgen_sdk import CruxGenSDK

def process_document(file_path: str):
    with CruxGenSDK("http://localhost:8000") as sdk:
        # 1. Create bucket
        sdk.create_bucket("documents")
        
        # 2. Upload document
        upload_result = sdk.upload_file(file_path, "documents")
        file_id = upload_result["response"]
        
        # 3. Create chunks
        sdk.create_chunks(file_id, "documents")
        
        # 4. Generate QA pairs
        sdk.create_qa_pairs(file_id)
        
        # 5. Export QA dataset
        qa_jsonl = sdk.get_qa_pairs(file_id, generate_jsonl=True)
        with open(f"dataset_{file_id}.jsonl", "wb") as f:
            f.write(qa_jsonl)
        
        return file_id

Context Manager Usage

The SDK supports context manager protocol for automatic resource cleanup:

# Recommended approach
with CruxGenSDK("http://localhost:8000") as sdk:
    result = sdk.health_check()

# Manual cleanup
sdk = CruxGenSDK("http://localhost:8000")
try:
    result = sdk.health_check()
finally:
    sdk.close()

Error Handling

The SDK raises httpx.HTTPStatusError for HTTP errors:

import httpx

try:
    result = sdk.upload_file("nonexistent.pdf")
except httpx.HTTPStatusError as e:
    print(f"HTTP Error: {e.response.status_code}")
except FileNotFoundError:
    print("File not found")

Response Format

All methods return dictionaries with standardized structure:

{
    "success": true,
    "message": "Operation completed successfully",
    "status_code": 200,
    "response": {/* operation-specific data */}
}

Metadata

Release files for cruxgen-sdk 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cruxgen-sdk 0.1.1
File Size Uploaded
cruxgen_sdk-0.1.1.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cruxgen-sdk 0.1.1
File Interpreter ABI Platform
cruxgen_sdk-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.3 kB

Release files / cruxgen_sdk-0.1.1.tar.gz

Download URL cruxgen_sdk-0.1.1.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
705622863f2dac18616327d22a708b8d91bb0a789672d8fba9307ecd5b67d3f1
BLAKE2b-256 checksum
How to use checksums
862788d1f79c47bbe1cca87864ea025fb66145844b373b073c3aa3eda4792e0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.12

Release files / cruxgen_sdk-0.1.1-py3-none-any.whl

Download URL cruxgen_sdk-0.1.1-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b7e12fd7f6a9ae4b5a9bb58f4e48c6efacc14802d999ee32aea9db804faf9c1b
BLAKE2b-256 checksum
How to use checksums
34dc1c49af5047d235e65ef619f78e64ed2cbf63fad8930e98fb9ca053a22fd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.12

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page