Metadata-Version: 2.4
Name: tripo
Version: 0.2.0
Summary: Tripo Python Client
Requires-Python: >=3.11
Requires-Dist: httpx>=0.27.2
Requires-Dist: pydantic>=2.9.2
Description-Content-Type: text/markdown

# Tripo Python Client
[![PyPI version](https://badge.fury.io/py/tripo.svg)](https://badge.fury.io/py/tripo)

This is a Python client for the [Tripo API](https://platform.tripo3d.ai/docs/introduction).

## Installation

```bash
pip install tripo
```

```bash
export TRIPO_API_KEY="your_api_key"
```

## Usage

This first example is to get the balance.

```python
from tripo import Client

with Client() as client:
    balance = client.get_balance()
    print(f"Balance: {balance.balance}, Frozen: {balance.frozen}")
```

This example is to generate a model from text.

```python
import time
from tripo import Client

# Initialize the client
with Client() as client:
    # Create a task to generate a model from text
    success_task = client.text_to_model(
        prompt="A 3D model of a futuristic car",
        model_version="v2.0-20240919",
        texture=True,
        pbr=True
    )
    print(f"Created task with ID: {success_task.task_id}")

    # Get 3d model
    print("Waiting for the model to be ready...")
    while True:
        data = client.try_download_model(success_task.task_id)
        if data is not None:
            data.save("model.glb")
            break
        time.sleep(1)
```

This is the 3D model generated by the previous example.

![3D Model](assets/model.png)

The next example is to generate a model from an image.

```python
import time
from tripo import Client

# Initialize the client
with Client() as client:
    # Upload a file
    upload_data = client.upload_file('path/to/your/image.jpg')
    # Or upload a byte array
    # byte_image = open('path/to/your/image.jpg', "rb").read()
    # upload_data = client.upload_file(byte_image)
    print(f"Uploaded file token: {upload_data.image_token}")

    # Create a task to generate a model from an image
    success_task = client.image_to_model(
        file_token=upload_data.image_token,
        model_version='v1.4-20240625',
        texture=True,
        pbr=True
    )
    print(f"Created task with ID: {success_task.task_id}")

    # Get 3d model
    print("Waiting for the model to be ready...")
    while True:
        data = client.try_download_model(success_task.task_id)
        if data is not None:
            data.save("model.glb")
            break
        time.sleep(1)
```
