Implementation:Groq Groq python FileTypes Handling
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Audio, File_Handling |
| Last Updated | 2026-02-15 16:00 GMT |
Overview
Concrete type system and utilities for handling file inputs in the Groq Python SDK.
Description
FileTypes is a type alias that accepts multiple forms of file input: PathLike (file path), bytes, tuple[str, bytes] (filename + content), or IO[bytes] (file-like object). The extract_files() utility in _files.py normalizes these inputs into multipart form data for HTTP upload.
Usage
Use FileTypes when providing audio files to client.audio.transcriptions.create(file=...). Pass a file path string, opened file object, or raw bytes.
Code Reference
Source Location
- Repository: groq-python
- File: src/groq/_types.py (FileTypes definition: L1-261)
- File: src/groq/_files.py (file extraction utilities: L1-123)
Signature
# Type alias for file inputs
FileTypes = Union[
# PathLike
str, Path,
# bytes content
bytes,
# (filename, content) tuple
Tuple[str, bytes],
# file-like object
IO[bytes],
]
Import
from groq._types import FileTypes
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| file | FileTypes | Yes | Audio file as path, bytes, tuple, or file-like object |
Outputs
| Name | Type | Description |
|---|---|---|
| (value) | FileTypes | Normalized file value ready for multipart upload |
Usage Examples
From File Path
# Pass a file path directly
file = "audio_recording.mp3"
From Open File
with open("audio.wav", "rb") as f:
# Pass file object
response = client.audio.transcriptions.create(
file=f,
model="whisper-large-v3",
)
From Bytes
audio_bytes = download_audio_from_url("https://example.com/audio.mp3")
response = client.audio.transcriptions.create(
file=("audio.mp3", audio_bytes),
model="whisper-large-v3",
)
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment