Trellis Python SDK
The Trellis data flow can be broken down into four steps:
- Upload your assets
- Extract your assets
- Define and run your transformations.
- Get your results
We'll go over the main functionality for each step with our Python SDK. For full SDK code, check out https://github.com/Trellis-insights/trellis-python.
To begin, first run
pip install trellis-python
Upload, get, and delete assets
from trellis.client import TrellisApi
client = TrellisApi(api_key="YOUR_API_KEY")
# Upload files with filepath
client.assets.upload_assets(
proj_name="proj_name",
files="path/to/file.pdf"
)
# OR Upload files with URLs
client.assets.upload_assets(
proj_name="proj_name",
urls=["http://example.com/file1.pdf", "http://example.com/file2.pdf"]
)
# Get assets
client.assets.get_assets()
# Delete assets based on ID
client.assets.delete_assets(asset_id="asset_id")
Run Extraction
from trellis.client import TrellisApi
client = TrellisApi(api_key="YOUR_API_KEY")
# Extract files based on asset_ids
client.assets_extract.extract_files(
asset_ids=["id1", "id2"]
)
# Extract files based on project
client.assets_extract.extract_files(
proj_name="your_project_name"
)
Run Transformation
from trellis import TransformationOperation, TransformParams
from trellis.client import TrellisApi
# Initialize the Trellis API client with your API key
client = TrellisApi(api_key="YOUR_API_KEY")
# Define the transformation operation
transformation_operation = TransformationOperation(
column_name="column_name", # Enter column name here as snake case
column_type="text", # Enter valid Postgres type. Most common type is `text`
transform_type="transform_type", # Enter `classification`, `extraction`, or `generation`
task_description="task_description" # Enter the task you want to do
)
# Define the transformation parameters
transform_params = TransformParams(
model="trellis-premium",
operations=[transformation_operation]
)
# Run the transform operation
client.transforms.create_transform(
proj_name="your_project_name",
transform_params=transform_params
)
Get Results
from trellis.client import TrellisApi
client = TrellisApi(api_key="YOUR_API_KEY")
client.transforms.get_transform_results(transform_id="transform_id")