from mixtrain.types import File, Image, Video, Audio, Model3D, Text, Markdown, JSON, EmbeddingMedia Types
Media types can be used as both inputs and outputs. All inherit from File and support downloading from https://, gs://, and s3:// URLs.
File
Base class for file references.
from mixtrain.types import File
file = File(
url="gs://bucket/data.bin",
content_type="application/octet-stream",
filename="data.bin"
)
# Download to local file
local_path = file.to_file()
# Or specify path
file.to_file("/tmp/myfile.bin")| Property | Type | Description |
|---|---|---|
url | str | URL to the file (https://, gs://, s3://) |
content_type | str | None | MIME type |
filename | str | None | Original filename |
Methods:
| Method | Returns | Description |
|---|---|---|
to_file(path=None) | str | Download to local file. Returns path. |
Image
Extends File with image-specific helpers.
from mixtrain.types import Image
image = Image(
url="https://...",
width=1024,
height=768
)
# As input in model
def run(self, image: Image):
pil = image.to_pil() # PIL.Image
arr = image.to_numpy() # numpy (H, W, C)| Property | Type | Description |
|---|---|---|
url | str | URL to the image |
width | int | None | Image width in pixels |
height | int | None | Image height in pixels |
format | str | None | Format (png, jpg, webp) |
Methods:
| Method | Returns | Description |
|---|---|---|
to_file(path=None) | str | Download to local file |
to_pil() | PIL.Image.Image | Open as PIL Image |
to_numpy() | np.ndarray | Convert to numpy array (H, W, C) |
Video
Extends File with video-specific helpers.
from mixtrain.types import Video
video = Video(
url="https://...",
width=1920,
height=1080,
duration_seconds=10.5
)
# As input in model
def run(self, video: Video):
cap = video.to_cv2()
for frame in video.to_frames():
process(frame)| Property | Type | Description |
|---|---|---|
url | str | URL to the video |
width | int | None | Video width in pixels |
height | int | None | Video height in pixels |
duration_seconds | float | None | Duration in seconds |
format | str | None | Format (mp4, webm) |
Methods:
| Method | Returns | Description |
|---|---|---|
to_file(path=None) | str | Download to local file |
to_cv2() | cv2.VideoCapture | Open as OpenCV VideoCapture |
to_frames() | Iterator[np.ndarray] | Yield frames as numpy arrays (H, W, C) |
Audio
Extends File with audio-specific helpers.
from mixtrain.types import Audio
audio = Audio(
url="https://...",
duration_seconds=30.0
)
# As input in model
def run(self, audio: Audio):
samples, sr = audio.to_numpy()| Property | Type | Description |
|---|---|---|
url | str | URL to the audio file |
duration_seconds | float | None | Duration in seconds |
format | str | None | Format (mp3, wav) |
Methods:
| Method | Returns | Description |
|---|---|---|
to_file(path=None) | str | Download to local file |
to_numpy() | tuple[np.ndarray, int] | Returns (samples, sample_rate) |
Model3D
from mixtrain.types import Model3D
model3d = Model3D(
url="https://...",
format="glb"
)| Property | Type | Description |
|---|---|---|
url | str | URL to the 3D model file |
format | str | File format (e.g., "glb", "obj") |
Embedding
from mixtrain.types import Embedding
embedding = Embedding(
vector=[0.1, 0.2, 0.3, ...],
dimensions=1536
)| Property | Type | Description |
|---|---|---|
vector | list[float] | Embedding vector |
dimensions | int | Vector dimensions |
Text Types
Text
Plain text output.
from mixtrain.types import Text
text = Text(content="Hello, world!")| Property | Type | Description |
|---|---|---|
content | str | Text content |
Markdown
Markdown-formatted text.
from mixtrain.types import Markdown
md = Markdown(content="# Hello\n\nThis is **bold**.")| Property | Type | Description |
|---|---|---|
content | str | Markdown content |
JSON
Structured JSON data.
from mixtrain.types import JSON
data = JSON(data={"key": "value", "count": 42})| Property | Type | Description |
|---|---|---|
data | dict | JSON data |
Using Types in Your Models
Return typed outputs from your MixModel:
from mixtrain import MixModel
from mixtrain.types import Image, Video
class ImageGenerator(MixModel):
def run(self, inputs=None):
# Generate image
image_url = self._generate(inputs["prompt"])
return {
"image": Image(
url=image_url,
width=1024,
height=1024
)
}
class VideoGenerator(MixModel):
def run(self, inputs=None):
video_url = self._generate(inputs["prompt"])
return {
"video": Video(
url=video_url,
width=1920,
height=1080,
duration_seconds=5.0
)
}Accessing Types from ModelResult
When you run a model, typed accessors are available on the result:
from mixtrain import Model
model = Model("flux-pro")
result = model.run({"prompt": "A sunset"})
# Typed accessor returns Image or None
if result.image:
print(result.image.url)
print(f"{result.image.width}x{result.image.height}")
# For video models
model = Model("hunyuan-video")
result = model.run({"prompt": "A cat playing"})
if result.video:
print(result.video.url)
print(f"Duration: {result.video.duration_seconds}s")