Official Python SDK for DocumentStack PDF generation API
Project description
documentstack
Official Python SDK for the DocumentStack PDF generation API.
Installation
pip install documentstack
Quick Start
from documentstack import DocumentStack
# Initialize the client
client = DocumentStack(api_key="your-api-key")
# Generate a PDF
result = client.generate(
template_id="template-id",
data={
"name": "John Doe",
"amount": 1500,
},
filename="invoice",
)
# Save to file
with open(result.filename, "wb") as f:
f.write(result.pdf)
print(f"PDF generated in {result.generation_time_ms}ms")
Configuration
client = DocumentStack(
# Required: Your API key
api_key="your-api-key",
# Optional: Custom base URL (default: https://api.documentstack.dev)
base_url="https://api.documentstack.dev",
# Optional: Request timeout in seconds (default: 30.0)
timeout=30.0,
# Optional: Custom headers for all requests
headers={
"X-Custom-Header": "value",
},
# Optional: Enable debug logging (default: False)
debug=False,
)
API Reference
client.generate(template_id, *, data=None, filename=None)
Generate a PDF from a template.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
template_id |
str |
Yes | The ID of the template to use |
data |
dict[str, Any] |
No | Template data for variable substitution |
filename |
str |
No | Custom filename (without .pdf extension) |
Returns: GenerateResponse
@dataclass
class GenerateResponse:
pdf: bytes # PDF binary data
filename: str # Filename from response
generation_time_ms: int # Generation time in ms
content_length: int # File size in bytes
Error Handling
The SDK provides typed exceptions for different failure scenarios:
from documentstack import (
DocumentStack,
ValidationError,
AuthenticationError,
ForbiddenError,
NotFoundError,
RateLimitError,
ServerError,
TimeoutError,
NetworkError,
)
try:
result = client.generate("template-id", data={})
except ValidationError as e:
# 400: Invalid request
print(f"Validation failed: {e.message}")
except AuthenticationError as e:
# 401: Invalid API key
print(f"Authentication failed: {e.message}")
except ForbiddenError as e:
# 403: No access to template
print(f"Access forbidden: {e.message}")
except NotFoundError as e:
# 404: Template not found
print(f"Template not found: {e.message}")
except RateLimitError as e:
# 429: Rate limit exceeded
print(f"Rate limited. Retry after {e.retry_after} seconds")
except ServerError as e:
# 500: Server error
print(f"Server error: {e.message}")
except TimeoutError as e:
# Request timed out
print("Request timed out")
except NetworkError as e:
# Network failure
print(f"Network error: {e}")
Type Hints
This SDK is fully typed with Python type hints and supports static type checking with mypy.
from documentstack import (
DocumentStackConfig,
GenerateRequest,
GenerateResponse,
GenerateOptions,
)
Requirements
- Python 3.10 or higher
- httpx >= 0.24.0
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file documentstack-1.0.0.tar.gz.
File metadata
- Download URL: documentstack-1.0.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfc0b6b68f4113befed81317b1637596e62588ae3199f835f6a7dacec5395fbb
|
|
| MD5 |
caae69422b5a4cb0d67077a2932bdf2e
|
|
| BLAKE2b-256 |
61b4860aa784dfc05c49b43502c731db45e4799a868c22d23c6ba727b3b5bd06
|
File details
Details for the file documentstack-1.0.0-py3-none-any.whl.
File metadata
- Download URL: documentstack-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c708645c896dcc6cca86e424df80e424e3b47edf47d8f03b55f0b0e5c4f831df
|
|
| MD5 |
27a3fce6e2ed960a2cc7e340a3627a41
|
|
| BLAKE2b-256 |
f033e8c23754145341fc07e309ef1a8e74ccf8ec00332941a211b38a0063969d
|