Overview
ThePart class represents individual pieces of content within a message. It provides factory methods for creating different types of parts.
Part Fields
A Part can contain exactly one of these fields:str
Text content of the part.
Blob
Inline media content (images, audio, video) as raw bytes.
FileData
URI-based media content from Google Cloud Storage.
FunctionCall
A predicted function call from the model.
FunctionResponse
The result of a function call execution.
ExecutableCode
Code generated by the model for execution.
CodeExecutionResult
Result of executing code.
VideoMetadata
Optional metadata for video content (start/end offset, fps).
PartMediaResolution
Optional media resolution configuration.
bool
Whether this part represents the model’s thought process.
Factory Methods
from_text
Create a text part.from_uri
Create a part from a file URI.str
required
The URI of the file (e.g., “gs://bucket/file.jpg”).
str
The MIME type of the file. If not provided, will be automatically determined.
PartMediaResolutionOrDict
Optional media resolution configuration.
from_bytes
Create a part from raw bytes.bytes
required
The raw bytes of the media.
str
required
The MIME type of the data.
PartMediaResolutionOrDict
Optional media resolution configuration.
from_function_call
Create a function call part.str
required
The name of the function to call.
dict[str, Any]
required
The function arguments as a dictionary.
from_function_response
Create a function response part.str
required
The name of the function that was called.
dict[str, Any]
required
The function response. Use “output” key for success, “error” key for errors.
list[FunctionResponsePart]
Optional list of media parts in the response.
from_executable_code
Create an executable code part.str
required
The code to be executed.
Language
required
The programming language (e.g., Language.PYTHON).
from_code_execution_result
Create a code execution result part.Outcome
required
The outcome of the execution (OUTCOME_OK, OUTCOME_FAILED, OUTCOME_DEADLINE_EXCEEDED).
str
required
The output (stdout on success, stderr or error description on failure).
Direct Construction
You can also construct Parts directly:Part Methods
as_image
Convert a part to a PIL Image (if it contains image data).Video Metadata
Add metadata to video parts:Media Resolution Control
Control how media is tokenized:PIL Image Support
Parts can be created directly from PIL Images:File Object Support
Parts can be created from File objects:See Also
- Content Types - Using Parts in Content
- Types Overview - Type system overview
- Client Reference - Using Parts with the client