Skip to main content

Client Reference

The Structurify client provides access to all API resources.

Initialization

from structurify import Structurify

client = Structurify(
api_key="sk_live_your_api_key",
base_url="https://app.structurify.ai/api", # optional
timeout=30, # optional, seconds
)

Parameters

ParameterTypeDefaultDescription
api_keystrRequiredYour Structurify API key
base_urlstrhttps://app.structurify.ai/apiAPI base URL
timeoutint30Request timeout in seconds

Resources

Templates

# List all project templates
templates = client.templates.list()

# Returns list of template dicts with id, name, description, columns

Projects

# List all projects
projects = client.projects.list()

# Create a project
project = client.projects.create(
name="My Project",
template_id="tpl_invoice"
)

# Get a project
project = client.projects.get("proj_xxx")

# Delete a project
client.projects.delete("proj_xxx")

Documents

# Upload a document from file path
doc = client.documents.upload(
project_id="proj_xxx",
file_path="invoice.pdf"
)

# Upload from bytes
with open("invoice.pdf", "rb") as f:
doc = client.documents.upload(
project_id="proj_xxx",
file_content=f.read(),
file_name="invoice.pdf",
mime_type="application/pdf"
)

# Get document
doc = client.documents.get("doc_xxx")

# Get document content
content = client.documents.get_content("doc_xxx")

# Delete document
client.documents.delete("doc_xxx")

Extraction

# Run extraction
job = client.extraction.run(project_id="proj_xxx")

# Get job status
job = client.extraction.get("job_xxx")

# Wait for completion (blocking)
completed = client.extraction.wait_for_completion(
job_id="job_xxx",
poll_interval=2, # seconds
timeout=300 # seconds
)

# Cancel job
client.extraction.cancel("job_xxx")

Exports

# Create export
export = client.exports.create(
project_id="proj_xxx",
format="csv", # or "json"
document_ids=["doc_1", "doc_2"] # optional, default all
)

# Download export
data = client.exports.download("exp_xxx")

Error Handling

from structurify import (
StructurifyError,
AuthenticationError,
NotFoundError,
InsufficientCreditsError,
RateLimitError,
ValidationError,
)

try:
project = client.projects.get("proj_invalid")
except AuthenticationError:
print("Invalid API key")
except NotFoundError:
print("Project not found")
except InsufficientCreditsError:
print("Not enough credits")
except RateLimitError as e:
print(f"Rate limited. Retry after {e.retry_after}s")
except ValidationError as e:
print(f"Validation error: {e.message}")
except StructurifyError as e:
print(f"API error: {e}")

Webhook Verification

from structurify.webhooks import verify_signature

# Verify webhook payload
is_valid = verify_signature(
payload=request.body, # raw bytes
signature=request.headers['X-Structurify-Signature'],
secret='your_webhook_secret'
)

if is_valid:
# Process webhook
data = json.loads(request.body)
print(f"Event: {data['event']}")