Python SDK#
Client#
The LlamaDeploy Python client.
The client is gives access to both the asyncio and non-asyncio APIs. To access the sync
API just use methods of client.sync
.
Example usage:
from llama_deploy.client import Client
# Use the same client instance
c = Client()
async def an_async_function():
status = await client.apiserver.status()
def normal_function():
status = client.sync.apiserver.status()
Source code in llama_deploy/client/client.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
API Server functionalities#
SessionCollection #
Bases: Collection
A model representing a collection of session for a given deployment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
deployment_id
|
str
|
|
required |
Source code in llama_deploy/client/models/apiserver.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
delete
async
#
delete(session_id: str) -> None
Deletes the session with the provided session_id
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session_id
|
str
|
The id of the session that will be removed |
required |
Raises:
Type | Description |
---|---|
HTTPException
|
If the session couldn't be found with the id provided. |
Source code in llama_deploy/client/models/apiserver.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
create
async
#
create() -> SessionDefinition
Source code in llama_deploy/client/models/apiserver.py
44 45 46 47 48 49 50 51 52 53 54 55 |
|
list
async
#
list() -> list[SessionDefinition]
Returns a collection of all the sessions in the given deployment.
Source code in llama_deploy/client/models/apiserver.py
57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
Task #
Bases: Model
A model representing a task belonging to a given session in the given deployment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
deployment_id
|
str
|
|
required |
session_id
|
str
|
|
required |
Source code in llama_deploy/client/models/apiserver.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
results
async
#
results() -> TaskResult
Returns the result of a given task.
Source code in llama_deploy/client/models/apiserver.py
78 79 80 81 82 83 84 85 86 87 88 89 |
|
send_event
async
#
send_event(ev: Event, service_name: str) -> EventDefinition
Sends a human response event.
Source code in llama_deploy/client/models/apiserver.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
events
async
#
events() -> AsyncGenerator[dict[str, Any], None]
Returns a generator object to consume the events streamed from a service.
Source code in llama_deploy/client/models/apiserver.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
TaskCollection #
Bases: Collection
A model representing a collection of tasks for a given deployment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
deployment_id
|
str
|
|
required |
Source code in llama_deploy/client/models/apiserver.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
run
async
#
run(task: TaskDefinition) -> Any
Runs a task and returns the results once it's done.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task
|
TaskDefinition
|
The definition of the task we want to run. |
required |
Source code in llama_deploy/client/models/apiserver.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
create
async
#
create(task: TaskDefinition) -> Task
Runs a task returns it immediately, without waiting for the results.
Source code in llama_deploy/client/models/apiserver.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
list
async
#
Returns the list of tasks from this collection.
Source code in llama_deploy/client/models/apiserver.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
Deployment #
Bases: Model
A model representing a deployment.
Source code in llama_deploy/client/models/apiserver.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
tasks
property
#
tasks: TaskCollection
Returns a collection of tasks from all the sessions in the given deployment.
sessions
property
#
sessions: SessionCollection
Returns a collection of all the sessions in the given deployment.
DeploymentCollection #
Bases: Collection
A model representing a collection of deployments currently active.
Source code in llama_deploy/client/models/apiserver.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
|
create
async
#
create(config: TextIO, reload: bool = False) -> Deployment
Creates a new deployment from a deployment file.
If reload
is true, an existing deployment will be reloaded, otherwise
an error will be raised.
Example
with open("deployment.yml") as f:
await client.apiserver.deployments.create(f)
Source code in llama_deploy/client/models/apiserver.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
|
get
async
#
get(id: str) -> Deployment
Gets a deployment by id.
Source code in llama_deploy/client/models/apiserver.py
256 257 258 259 260 261 262 263 264 265 266 267 |
|
ApiServer #
Bases: Model
A model representing the API Server instance.
Source code in llama_deploy/client/models/apiserver.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
deployments
property
#
deployments: DeploymentCollection
Returns a collection of deployments currently active in the API Server.
status
async
#
status() -> Status
Returns the status of the API Server.
Source code in llama_deploy/client/models/apiserver.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
Control Plane functionalities#
Session #
Bases: Model
Source code in llama_deploy/client/models/core.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
run
async
#
run(service_name: str, **run_kwargs: Any) -> str
Implements the workflow-based run API for a session.
Source code in llama_deploy/client/models/core.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
run_nowait
async
#
run_nowait(service_name: str, **run_kwargs: Any) -> str
Implements the workflow-based run API for a session, but does not wait for the task to complete.
Source code in llama_deploy/client/models/core.py
38 39 40 41 42 43 44 45 |
|
create_task
async
#
create_task(task_def: TaskDefinition) -> str
Create a new task in this session.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_def
|
Union[str, TaskDefinition]
|
The task definition or input string. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The ID of the created task. |
Source code in llama_deploy/client/models/core.py
47 48 49 50 51 52 53 54 55 56 |
|
get_task_result
async
#
get_task_result(task_id: str) -> TaskResult | None
Get the result of a task in this session if it has one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_id
|
str
|
The ID of the task to get the result for. |
required |
Returns:
Type | Description |
---|---|
TaskResult | None
|
Optional[TaskResult]: The result of the task if it has one, otherwise None. |
Source code in llama_deploy/client/models/core.py
65 66 67 68 69 70 71 72 73 74 |
|
get_tasks
async
#
get_tasks() -> list[TaskDefinition]
Get all tasks in this session.
Returns:
Type | Description |
---|---|
list[TaskDefinition]
|
list[TaskDefinition]: A list of task definitions in the session. |
Source code in llama_deploy/client/models/core.py
85 86 87 88 89 90 91 92 93 |
|
send_event
async
#
send_event(service_name: str, task_id: str, ev: Event) -> None
Send event to a Workflow service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event
|
Event
|
The event to be submitted to the workflow. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in llama_deploy/client/models/core.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
send_event_def
async
#
send_event_def(task_id: str, ev_def: EventDefinition) -> None
Send event to a Workflow service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event
|
Event
|
The event to be submitted to the workflow. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in llama_deploy/client/models/core.py
112 113 114 115 116 117 118 119 120 121 122 |
|
get_task_result_stream
async
#
get_task_result_stream(task_id: str) -> AsyncGenerator[dict[str, Any], None]
Get the result of a task in this session if it has one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_id
|
str
|
The ID of the task to get the result for. |
required |
Returns:
Type | Description |
---|---|
AsyncGenerator[dict[str, Any], None]
|
AsyncGenerator[str, None, None]: A generator that yields the result of the task. |
Source code in llama_deploy/client/models/core.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
SessionCollection #
Bases: Collection
Source code in llama_deploy/client/models/core.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
|
list
async
#
Returns a list of all the sessions in the collection.
Source code in llama_deploy/client/models/core.py
161 162 163 164 165 166 167 168 169 |
|
create
async
#
create() -> Session
Creates a new session and returns a Session object.
Returns:
Name | Type | Description |
---|---|---|
Session |
Session
|
A Session object representing the newly created session. |
Source code in llama_deploy/client/models/core.py
171 172 173 174 175 176 177 |
|
get
async
#
get(id: str) -> Session
Gets a session by ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session_id
|
The ID of the session to get. |
required |
Returns:
Name | Type | Description |
---|---|---|
Session |
Session
|
A Session object representing the specified session. |
Raises:
Type | Description |
---|---|
ValueError
|
If the session does not exist. |
Source code in llama_deploy/client/models/core.py
187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
get_or_create
async
#
get_or_create(id: str) -> Session
Gets a session by ID, or creates a new one if it doesn't exist.
Returns:
Name | Type | Description |
---|---|---|
Session |
Session
|
A Session object representing the specified session. |
Source code in llama_deploy/client/models/core.py
209 210 211 212 213 214 215 216 217 218 219 220 |
|
delete
async
#
delete(session_id: str) -> None
Deletes a session by ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session_id
|
str
|
The ID of the session to delete. |
required |
Source code in llama_deploy/client/models/core.py
222 223 224 225 226 227 228 229 |
|
Service #
Bases: Model
Source code in llama_deploy/client/models/core.py
232 233 |
|
ServiceCollection #
Bases: Collection
Source code in llama_deploy/client/models/core.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
list
async
#
Returns a list containing all the services registered with the control plane.
Returns:
Type | Description |
---|---|
list[Service]
|
list[Service]: List of services registered with the control plane. |
Source code in llama_deploy/client/models/core.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
|
register
async
#
register(service: ServiceDefinition) -> Service
Registers a service with the control plane.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service
|
ServiceDefinition
|
Definition of the Service to register. |
required |
Source code in llama_deploy/client/models/core.py
253 254 255 256 257 258 259 260 261 262 263 264 |
|
deregister
async
#
deregister(service_name: str) -> None
Deregisters a service from the control plane.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service_name
|
str
|
The name of the Service to deregister. |
required |
Source code in llama_deploy/client/models/core.py
266 267 268 269 270 271 272 273 274 275 276 277 |
|
Core #
Bases: Model
Source code in llama_deploy/client/models/core.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
services
property
#
services: ServiceCollection
Returns a collection containing all the services registered with the control plane.
Returns:
Name | Type | Description |
---|---|---|
ServiceCollection |
ServiceCollection
|
Collection of services registered with the control plane. |
sessions
property
#
sessions: SessionCollection
Returns a collection to access all the sessions registered with the control plane.
Returns:
Name | Type | Description |
---|---|---|
SessionCollection |
SessionCollection
|
Collection of sessions registered with the control plane. |