Skip to content

Python SDK#

client#

AsyncLlamaDeployClient #

Source code in llama_deploy/client/async_client.py
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
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
275
276
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
class AsyncLlamaDeployClient:
    def __init__(
        self, control_plane_config: ControlPlaneConfig, timeout: float = DEFAULT_TIMEOUT
    ):
        self.control_plane_config = control_plane_config
        # TODO: add scheme to config (http, https, ..)
        self.control_plane_url = control_plane_config.url
        self.timeout = timeout

    async def create_session(
        self, poll_interval: float = DEFAULT_POLL_INTERVAL
    ) -> AsyncSessionClient:
        """Create a new session and return a AsyncSessionClient for it.

        Returns:
            AsyncSessionClient: A client for the newly created session.
        """
        async with httpx.AsyncClient(timeout=self.timeout) as client:
            response = await client.post(f"{self.control_plane_url}/sessions/create")
            session_id = response.json()
        return AsyncSessionClient(
            self.control_plane_config,
            session_id,
            timeout=self.timeout,
            poll_interval=poll_interval,
        )

    async def list_sessions(self) -> List[SessionDefinition]:
        """List all sessions registered with the control plane.

        Returns:
            List[SessionDefinition]: A list of session definitions.
        """
        async with httpx.AsyncClient(timeout=self.timeout) as client:
            response = await client.get(f"{self.control_plane_url}/sessions")
            return [
                SessionDefinition(**session) for session in response.json().values()
            ]

    async def get_session_definition(self, session_id: str) -> SessionDefinition:
        """Get the definition of a session by ID.

        Args:
            session_id (str): The ID of the session to get.

        Returns:
            SessionDefinition: The definition of the session.
        """
        async with httpx.AsyncClient(timeout=self.timeout) as client:
            response = await client.get(
                f"{self.control_plane_url}/sessions/{session_id}"
            )
            return SessionDefinition(**response.json())

    async def get_session(
        self, session_id: str, poll_interval: float = DEFAULT_POLL_INTERVAL
    ) -> AsyncSessionClient:
        """Get an existing session by ID.

        Args:
            session_id (str): The ID of the session to get.

        Returns:
            AsyncSessionClient: A client for the specified session.

        Raises:
            ValueError: If the session does not exist.
        """
        async with httpx.AsyncClient(timeout=self.timeout) as client:
            response = await client.get(
                f"{self.control_plane_url}/sessions/{session_id}"
            )
            if response.status_code == 404:
                raise ValueError(f"Session with id {session_id} not found")
            response.raise_for_status()

        return AsyncSessionClient(
            self.control_plane_config,
            session_id,
            timeout=self.timeout,
            poll_interval=poll_interval,
        )

    async def get_or_create_session(
        self, session_id: str, poll_interval: float = DEFAULT_POLL_INTERVAL
    ) -> AsyncSessionClient:
        """Get an existing session by ID, or create a new one if it doesn't exist.

        Args:
            session_id (str): The ID of the session to get.

        Returns:
            AsyncSessionClient: A client for the specified session.
        """
        try:
            return await self.get_session(session_id, poll_interval=poll_interval)
        except ValueError as e:
            if "not found" in str(e):
                return await self.create_session(poll_interval=poll_interval)
            raise e

    async def get_service(self, service_name: str) -> ServiceDefinition:
        """Get the definition of a service by name.

        Args:
            service_name (str): The name of the service to get.

        Returns:
            ServiceDefinition: The definition of the service.
        """
        async with httpx.AsyncClient(timeout=self.timeout) as client:
            response = await client.get(
                f"{self.control_plane_url}/services/{service_name}"
            )
            return ServiceDefinition(**response.json())

    async def delete_session(self, session_id: str) -> None:
        """Delete a session by ID.

        Args:
            session_id (str): The ID of the session to delete.
        """
        async with httpx.AsyncClient(timeout=self.timeout) as client:
            await client.post(f"{self.control_plane_url}/sessions/{session_id}/delete")

    async def list_services(self) -> List[ServiceDefinition]:
        """List all services registered with the control plane.

        Returns:
            List[ServiceDefinition]: A list of service definitions.
        """
        async with httpx.AsyncClient(timeout=self.timeout) as client:
            response = await client.get(f"{self.control_plane_url}/services")
            return [
                ServiceDefinition(**service) for _, service in response.json().items()
            ]

    async def register_service(self, service_def: ServiceDefinition) -> None:
        """Register a service with the control plane.

        Args:
            service_def (ServiceDefinition): The service definition to register.
        """
        async with httpx.AsyncClient(timeout=self.timeout) as client:
            await client.post(
                f"{self.control_plane_url}/services/register",
                json=service_def.model_dump(),
            )

    async def deregister_service(self, service_name: str) -> None:
        """Deregister a service from the control plane.

        Args:
            service_name (str): The name of the service to deregister.
        """
        async with httpx.AsyncClient(timeout=self.timeout) as client:
            await client.post(
                f"{self.control_plane_url}/services/deregister",
                json={"service_name": service_name},
            )

create_session async #

create_session(poll_interval: float = DEFAULT_POLL_INTERVAL) -> AsyncSessionClient

Create a new session and return a AsyncSessionClient for it.

Returns:

Name Type Description
AsyncSessionClient AsyncSessionClient

A client for the newly created session.

Source code in llama_deploy/client/async_client.py
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
async def create_session(
    self, poll_interval: float = DEFAULT_POLL_INTERVAL
) -> AsyncSessionClient:
    """Create a new session and return a AsyncSessionClient for it.

    Returns:
        AsyncSessionClient: A client for the newly created session.
    """
    async with httpx.AsyncClient(timeout=self.timeout) as client:
        response = await client.post(f"{self.control_plane_url}/sessions/create")
        session_id = response.json()
    return AsyncSessionClient(
        self.control_plane_config,
        session_id,
        timeout=self.timeout,
        poll_interval=poll_interval,
    )

list_sessions async #

list_sessions() -> List[SessionDefinition]

List all sessions registered with the control plane.

Returns:

Type Description
List[SessionDefinition]

List[SessionDefinition]: A list of session definitions.

Source code in llama_deploy/client/async_client.py
205
206
207
208
209
210
211
212
213
214
215
async def list_sessions(self) -> List[SessionDefinition]:
    """List all sessions registered with the control plane.

    Returns:
        List[SessionDefinition]: A list of session definitions.
    """
    async with httpx.AsyncClient(timeout=self.timeout) as client:
        response = await client.get(f"{self.control_plane_url}/sessions")
        return [
            SessionDefinition(**session) for session in response.json().values()
        ]

get_session_definition async #

get_session_definition(session_id: str) -> SessionDefinition

Get the definition of a session by ID.

Parameters:

Name Type Description Default
session_id str

The ID of the session to get.

required

Returns:

Name Type Description
SessionDefinition SessionDefinition

The definition of the session.

Source code in llama_deploy/client/async_client.py
217
218
219
220
221
222
223
224
225
226
227
228
229
230
async def get_session_definition(self, session_id: str) -> SessionDefinition:
    """Get the definition of a session by ID.

    Args:
        session_id (str): The ID of the session to get.

    Returns:
        SessionDefinition: The definition of the session.
    """
    async with httpx.AsyncClient(timeout=self.timeout) as client:
        response = await client.get(
            f"{self.control_plane_url}/sessions/{session_id}"
        )
        return SessionDefinition(**response.json())

get_session async #

get_session(session_id: str, poll_interval: float = DEFAULT_POLL_INTERVAL) -> AsyncSessionClient

Get an existing session by ID.

Parameters:

Name Type Description Default
session_id str

The ID of the session to get.

required

Returns:

Name Type Description
AsyncSessionClient AsyncSessionClient

A client for the specified session.

Raises:

Type Description
ValueError

If the session does not exist.

Source code in llama_deploy/client/async_client.py
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
async def get_session(
    self, session_id: str, poll_interval: float = DEFAULT_POLL_INTERVAL
) -> AsyncSessionClient:
    """Get an existing session by ID.

    Args:
        session_id (str): The ID of the session to get.

    Returns:
        AsyncSessionClient: A client for the specified session.

    Raises:
        ValueError: If the session does not exist.
    """
    async with httpx.AsyncClient(timeout=self.timeout) as client:
        response = await client.get(
            f"{self.control_plane_url}/sessions/{session_id}"
        )
        if response.status_code == 404:
            raise ValueError(f"Session with id {session_id} not found")
        response.raise_for_status()

    return AsyncSessionClient(
        self.control_plane_config,
        session_id,
        timeout=self.timeout,
        poll_interval=poll_interval,
    )

get_or_create_session async #

get_or_create_session(session_id: str, poll_interval: float = DEFAULT_POLL_INTERVAL) -> AsyncSessionClient

Get an existing session by ID, or create a new one if it doesn't exist.

Parameters:

Name Type Description Default
session_id str

The ID of the session to get.

required

Returns:

Name Type Description
AsyncSessionClient AsyncSessionClient

A client for the specified session.

Source code in llama_deploy/client/async_client.py
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
async def get_or_create_session(
    self, session_id: str, poll_interval: float = DEFAULT_POLL_INTERVAL
) -> AsyncSessionClient:
    """Get an existing session by ID, or create a new one if it doesn't exist.

    Args:
        session_id (str): The ID of the session to get.

    Returns:
        AsyncSessionClient: A client for the specified session.
    """
    try:
        return await self.get_session(session_id, poll_interval=poll_interval)
    except ValueError as e:
        if "not found" in str(e):
            return await self.create_session(poll_interval=poll_interval)
        raise e

get_service async #

get_service(service_name: str) -> ServiceDefinition

Get the definition of a service by name.

Parameters:

Name Type Description Default
service_name str

The name of the service to get.

required

Returns:

Name Type Description
ServiceDefinition ServiceDefinition

The definition of the service.

Source code in llama_deploy/client/async_client.py
279
280
281
282
283
284
285
286
287
288
289
290
291
292
async def get_service(self, service_name: str) -> ServiceDefinition:
    """Get the definition of a service by name.

    Args:
        service_name (str): The name of the service to get.

    Returns:
        ServiceDefinition: The definition of the service.
    """
    async with httpx.AsyncClient(timeout=self.timeout) as client:
        response = await client.get(
            f"{self.control_plane_url}/services/{service_name}"
        )
        return ServiceDefinition(**response.json())

delete_session async #

delete_session(session_id: str) -> None

Delete 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/async_client.py
294
295
296
297
298
299
300
301
async def delete_session(self, session_id: str) -> None:
    """Delete a session by ID.

    Args:
        session_id (str): The ID of the session to delete.
    """
    async with httpx.AsyncClient(timeout=self.timeout) as client:
        await client.post(f"{self.control_plane_url}/sessions/{session_id}/delete")

list_services async #

list_services() -> List[ServiceDefinition]

List all services registered with the control plane.

Returns:

Type Description
List[ServiceDefinition]

List[ServiceDefinition]: A list of service definitions.

Source code in llama_deploy/client/async_client.py
303
304
305
306
307
308
309
310
311
312
313
async def list_services(self) -> List[ServiceDefinition]:
    """List all services registered with the control plane.

    Returns:
        List[ServiceDefinition]: A list of service definitions.
    """
    async with httpx.AsyncClient(timeout=self.timeout) as client:
        response = await client.get(f"{self.control_plane_url}/services")
        return [
            ServiceDefinition(**service) for _, service in response.json().items()
        ]

register_service async #

register_service(service_def: ServiceDefinition) -> None

Register a service with the control plane.

Parameters:

Name Type Description Default
service_def ServiceDefinition

The service definition to register.

required
Source code in llama_deploy/client/async_client.py
315
316
317
318
319
320
321
322
323
324
325
async def register_service(self, service_def: ServiceDefinition) -> None:
    """Register a service with the control plane.

    Args:
        service_def (ServiceDefinition): The service definition to register.
    """
    async with httpx.AsyncClient(timeout=self.timeout) as client:
        await client.post(
            f"{self.control_plane_url}/services/register",
            json=service_def.model_dump(),
        )

deregister_service async #

deregister_service(service_name: str) -> None

Deregister 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/async_client.py
327
328
329
330
331
332
333
334
335
336
337
async def deregister_service(self, service_name: str) -> None:
    """Deregister a service from the control plane.

    Args:
        service_name (str): The name of the service to deregister.
    """
    async with httpx.AsyncClient(timeout=self.timeout) as client:
        await client.post(
            f"{self.control_plane_url}/services/deregister",
            json={"service_name": service_name},
        )

LlamaDeployClient #

Source code in llama_deploy/client/sync_client.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
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
275
276
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
322
323
324
325
326
327
328
329
330
331
332
333
334
class LlamaDeployClient:
    def __init__(
        self, control_plane_config: ControlPlaneConfig, timeout: float = DEFAULT_TIMEOUT
    ):
        self.control_plane_config = control_plane_config
        # TODO: add scheme to config (http, https, ..)
        self.control_plane_url = control_plane_config.url
        self.timeout = timeout

    def create_session(
        self, poll_interval: float = DEFAULT_POLL_INTERVAL
    ) -> SessionClient:
        """Create a new session and return a SessionClient for it.

        Returns:
            SessionClient: A client for the newly created session.
        """
        with httpx.Client(timeout=self.timeout) as client:
            response = client.post(f"{self.control_plane_url}/sessions/create")
            session_id = response.json()
        return SessionClient(
            self.control_plane_config,
            session_id,
            timeout=self.timeout,
            poll_interval=poll_interval,
        )

    def list_sessions(self) -> List[SessionDefinition]:
        """List all sessions registered with the control plane.

        Returns:
            List[SessionDefinition]: A list of session definitions.
        """
        with httpx.Client(timeout=self.timeout) as client:
            response = client.get(f"{self.control_plane_url}/sessions")
            return [
                SessionDefinition(**session) for session in response.json().values()
            ]

    def get_session_definition(self, session_id: str) -> SessionDefinition:
        """Get the definition of a session by ID.

        Args:
            session_id (str): The ID of the session to get.

        Returns:
            SessionDefinition: The definition of the session.
        """
        with httpx.Client(timeout=self.timeout) as client:
            response = client.get(f"{self.control_plane_url}/sessions/{session_id}")
            return SessionDefinition(**response.json())

    def get_session(
        self, session_id: str, poll_interval: float = DEFAULT_POLL_INTERVAL
    ) -> SessionClient:
        """Get an existing session by ID.

        Args:
            session_id (str): The ID of the session to get.

        Returns:
            SessionClient: A client for the specified session.

        Raises:
            ValueError: If the session does not exist.
        """
        with httpx.Client(timeout=self.timeout) as client:
            response = client.get(f"{self.control_plane_url}/sessions/{session_id}")
            if response.status_code == 404:
                raise ValueError(f"Session with id {session_id} not found")
            response.raise_for_status()

        return SessionClient(
            self.control_plane_config,
            session_id,
            timeout=self.timeout,
            poll_interval=poll_interval,
        )

    def get_or_create_session(
        self, session_id: str, poll_interval: float = DEFAULT_POLL_INTERVAL
    ) -> SessionClient:
        """Get an existing session by ID, or create a new one if it doesn't exist.

        Args:
            session_id (str): The ID of the session to get.

        Returns:
            SessionClient: A client for the specified session.
        """
        try:
            return self.get_session(session_id, poll_interval=poll_interval)
        except ValueError as e:
            if "not found" in str(e):
                return self.create_session(poll_interval=poll_interval)
            raise e

    def get_service(self, service_name: str) -> ServiceDefinition:
        """Get the definition of a service by name.

        Args:
            service_name (str): The name of the service to get.

        Returns:
            ServiceDefinition: The definition of the service.
        """
        with httpx.Client(timeout=self.timeout) as client:
            response = client.get(f"{self.control_plane_url}/services/{service_name}")
            return ServiceDefinition(**response.json())

    def delete_session(self, session_id: str) -> None:
        """Delete a session by ID.

        Args:
            session_id (str): The ID of the session to delete.
        """
        with httpx.Client(timeout=self.timeout) as client:
            client.post(f"{self.control_plane_url}/sessions/{session_id}/delete")

    def list_services(self) -> List[ServiceDefinition]:
        """List all services registered with the control plane.

        Returns:
            List[ServiceDefinition]: A list of service definitions.
        """
        with httpx.Client(timeout=self.timeout) as client:
            response = client.get(f"{self.control_plane_url}/services")
            return [
                ServiceDefinition(**service) for _, service in response.json().items()
            ]

    def register_service(self, service_def: ServiceDefinition) -> None:
        """Register a service with the control plane.

        Args:
            service_def (ServiceDefinition): The service definition to register.
        """
        with httpx.Client(timeout=self.timeout) as client:
            client.post(
                f"{self.control_plane_url}/services/register",
                json=service_def.model_dump(),
            )

    def deregister_service(self, service_name: str) -> None:
        """Deregister a service from the control plane.

        Args:
            service_name (str): The name of the service to deregister.
        """
        with httpx.Client(timeout=self.timeout) as client:
            client.post(
                f"{self.control_plane_url}/services/deregister",
                json={"service_name": service_name},
            )

create_session #

create_session(poll_interval: float = DEFAULT_POLL_INTERVAL) -> SessionClient

Create a new session and return a SessionClient for it.

Returns:

Name Type Description
SessionClient SessionClient

A client for the newly created session.

Source code in llama_deploy/client/sync_client.py
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
def create_session(
    self, poll_interval: float = DEFAULT_POLL_INTERVAL
) -> SessionClient:
    """Create a new session and return a SessionClient for it.

    Returns:
        SessionClient: A client for the newly created session.
    """
    with httpx.Client(timeout=self.timeout) as client:
        response = client.post(f"{self.control_plane_url}/sessions/create")
        session_id = response.json()
    return SessionClient(
        self.control_plane_config,
        session_id,
        timeout=self.timeout,
        poll_interval=poll_interval,
    )

list_sessions #

list_sessions() -> List[SessionDefinition]

List all sessions registered with the control plane.

Returns:

Type Description
List[SessionDefinition]

List[SessionDefinition]: A list of session definitions.

Source code in llama_deploy/client/sync_client.py
208
209
210
211
212
213
214
215
216
217
218
def list_sessions(self) -> List[SessionDefinition]:
    """List all sessions registered with the control plane.

    Returns:
        List[SessionDefinition]: A list of session definitions.
    """
    with httpx.Client(timeout=self.timeout) as client:
        response = client.get(f"{self.control_plane_url}/sessions")
        return [
            SessionDefinition(**session) for session in response.json().values()
        ]

get_session_definition #

get_session_definition(session_id: str) -> SessionDefinition

Get the definition of a session by ID.

Parameters:

Name Type Description Default
session_id str

The ID of the session to get.

required

Returns:

Name Type Description
SessionDefinition SessionDefinition

The definition of the session.

Source code in llama_deploy/client/sync_client.py
220
221
222
223
224
225
226
227
228
229
230
231
def get_session_definition(self, session_id: str) -> SessionDefinition:
    """Get the definition of a session by ID.

    Args:
        session_id (str): The ID of the session to get.

    Returns:
        SessionDefinition: The definition of the session.
    """
    with httpx.Client(timeout=self.timeout) as client:
        response = client.get(f"{self.control_plane_url}/sessions/{session_id}")
        return SessionDefinition(**response.json())

get_session #

get_session(session_id: str, poll_interval: float = DEFAULT_POLL_INTERVAL) -> SessionClient

Get an existing session by ID.

Parameters:

Name Type Description Default
session_id str

The ID of the session to get.

required

Returns:

Name Type Description
SessionClient SessionClient

A client for the specified session.

Raises:

Type Description
ValueError

If the session does not exist.

Source code in llama_deploy/client/sync_client.py
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
def get_session(
    self, session_id: str, poll_interval: float = DEFAULT_POLL_INTERVAL
) -> SessionClient:
    """Get an existing session by ID.

    Args:
        session_id (str): The ID of the session to get.

    Returns:
        SessionClient: A client for the specified session.

    Raises:
        ValueError: If the session does not exist.
    """
    with httpx.Client(timeout=self.timeout) as client:
        response = client.get(f"{self.control_plane_url}/sessions/{session_id}")
        if response.status_code == 404:
            raise ValueError(f"Session with id {session_id} not found")
        response.raise_for_status()

    return SessionClient(
        self.control_plane_config,
        session_id,
        timeout=self.timeout,
        poll_interval=poll_interval,
    )

get_or_create_session #

get_or_create_session(session_id: str, poll_interval: float = DEFAULT_POLL_INTERVAL) -> SessionClient

Get an existing session by ID, or create a new one if it doesn't exist.

Parameters:

Name Type Description Default
session_id str

The ID of the session to get.

required

Returns:

Name Type Description
SessionClient SessionClient

A client for the specified session.

Source code in llama_deploy/client/sync_client.py
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
def get_or_create_session(
    self, session_id: str, poll_interval: float = DEFAULT_POLL_INTERVAL
) -> SessionClient:
    """Get an existing session by ID, or create a new one if it doesn't exist.

    Args:
        session_id (str): The ID of the session to get.

    Returns:
        SessionClient: A client for the specified session.
    """
    try:
        return self.get_session(session_id, poll_interval=poll_interval)
    except ValueError as e:
        if "not found" in str(e):
            return self.create_session(poll_interval=poll_interval)
        raise e

get_service #

get_service(service_name: str) -> ServiceDefinition

Get the definition of a service by name.

Parameters:

Name Type Description Default
service_name str

The name of the service to get.

required

Returns:

Name Type Description
ServiceDefinition ServiceDefinition

The definition of the service.

Source code in llama_deploy/client/sync_client.py
278
279
280
281
282
283
284
285
286
287
288
289
def get_service(self, service_name: str) -> ServiceDefinition:
    """Get the definition of a service by name.

    Args:
        service_name (str): The name of the service to get.

    Returns:
        ServiceDefinition: The definition of the service.
    """
    with httpx.Client(timeout=self.timeout) as client:
        response = client.get(f"{self.control_plane_url}/services/{service_name}")
        return ServiceDefinition(**response.json())

delete_session #

delete_session(session_id: str) -> None

Delete 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/sync_client.py
291
292
293
294
295
296
297
298
def delete_session(self, session_id: str) -> None:
    """Delete a session by ID.

    Args:
        session_id (str): The ID of the session to delete.
    """
    with httpx.Client(timeout=self.timeout) as client:
        client.post(f"{self.control_plane_url}/sessions/{session_id}/delete")

list_services #

list_services() -> List[ServiceDefinition]

List all services registered with the control plane.

Returns:

Type Description
List[ServiceDefinition]

List[ServiceDefinition]: A list of service definitions.

Source code in llama_deploy/client/sync_client.py
300
301
302
303
304
305
306
307
308
309
310
def list_services(self) -> List[ServiceDefinition]:
    """List all services registered with the control plane.

    Returns:
        List[ServiceDefinition]: A list of service definitions.
    """
    with httpx.Client(timeout=self.timeout) as client:
        response = client.get(f"{self.control_plane_url}/services")
        return [
            ServiceDefinition(**service) for _, service in response.json().items()
        ]

register_service #

register_service(service_def: ServiceDefinition) -> None

Register a service with the control plane.

Parameters:

Name Type Description Default
service_def ServiceDefinition

The service definition to register.

required
Source code in llama_deploy/client/sync_client.py
312
313
314
315
316
317
318
319
320
321
322
def register_service(self, service_def: ServiceDefinition) -> None:
    """Register a service with the control plane.

    Args:
        service_def (ServiceDefinition): The service definition to register.
    """
    with httpx.Client(timeout=self.timeout) as client:
        client.post(
            f"{self.control_plane_url}/services/register",
            json=service_def.model_dump(),
        )

deregister_service #

deregister_service(service_name: str) -> None

Deregister 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/sync_client.py
324
325
326
327
328
329
330
331
332
333
334
def deregister_service(self, service_name: str) -> None:
    """Deregister a service from the control plane.

    Args:
        service_name (str): The name of the service to deregister.
    """
    with httpx.Client(timeout=self.timeout) as client:
        client.post(
            f"{self.control_plane_url}/services/deregister",
            json={"service_name": service_name},
        )

Client #

Bases: _BaseClient

The Llama Deploy 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
class Client(_BaseClient):
    """The Llama Deploy 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:
    ```py
    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()
    ```
    """

    @property
    def sync(self) -> "_SyncClient":
        """Returns the sync version of the client API."""
        try:
            asyncio.get_running_loop()
        except RuntimeError:
            return _SyncClient(**self.model_dump())

        msg = "You cannot use the sync client within an async event loop - just await the async methods directly."
        raise RuntimeError(msg)

    @property
    def apiserver(self) -> ApiServer:
        """Returns the ApiServer model."""
        return ApiServer(client=self, id="apiserver")

    @property
    def core(self) -> Core:
        """Returns the Core model."""
        return Core(client=self, id="core")

sync property #

sync: _SyncClient

Returns the sync version of the client API.

apiserver property #

apiserver: ApiServer

Returns the ApiServer model.

core property #

core: Core

Returns the Core model.