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 |
|