wxc_sdk

A simple SDK to work with Webex APIs, special focus on Webex Calling specific API endpoints.


This is how easy it is to use the SDK. The example code list all calling enabled users within the org.

 1#!/usr/bin/env python
 2"""
 3Example script
 4Get all calling users within the org
 5"""
 6
 7from dotenv import load_dotenv
 8
 9from wxc_sdk import WebexSimpleApi
10
11load_dotenv()
12
13api = WebexSimpleApi()
14
15# using wxc_sdk.people.PeopleApi.list to iterate over persons
16# Parameter calling_data needs to be set to true to gat calling specific information
17# calling users have the attribute location_id set
18calling_users = [user for user in api.people.list(calling_data=True)
19                 if user.location_id]
20print(f'{len(calling_users)} users:')
21print('\n'.join(user.display_name for user in calling_users))

Installation

Installing and upgrading wxc_sdk is easy:

Install via PIP

$ pip install wxc-sdk

Upgrade to the latest version

$ pip install wxc-sdk --upgrade

Documentation

Documentation is available at: http://wxc_sdk.readthedocs.io

Examples

Sample scripts are available in the examples folder.

Also the test cases in the tests folder can serve as examples of how to use the SDK.

Datatypes

Datatypes are defined in the respective subpackages and submodules and have to be imported from there explicitly:

from wxc_sdk.people import Person
from wxc_sdk.person_settings.barge import BargeSettings

To allow to abstract from the subpackage and submodule structure any datatype can also be imported from wxc_sdk.all_types directly:

from wxc_sdk.all_types import Person, BargeSettings

All wxc_sdk data types can also be imported at once:

from wxc_sdk.all_types import *

Async version of the SDK (experimental)

With wxc_sdk.as_api.AsWebexSimpleApi the SDK offers an async variant based on asyncio/aiohttp. This variant is automatically generated based off the source of the synchronous API and offers async variants of the endpoints using the same datastructures as the synchronous API.

Here is an example of how to use the async SDK:

 1#!/usr/bin/env python
 2"""
 3Example script
 4Get all calling users within the org using the (experimental) async API
 5"""
 6import asyncio
 7import time
 8
 9from dotenv import load_dotenv
10
11from wxc_sdk.as_api import AsWebexSimpleApi
12
13load_dotenv()
14
15
16async def get_calling_users():
17    """
18    Get details of all calling enabled users by:
19    1) getting all calling users
20    2) collecting all users that have a calling license
21    3) getting details for all users
22    """
23    async with AsWebexSimpleApi(concurrent_requests=40) as api:
24        print('Collecting calling licenses')
25        calling_license_ids = set(lic.license_id for lic in await api.licenses.list()
26                                  if lic.webex_calling)
27
28        # get users with a calling license
29        calling_users = [user async for user in api.people.list_gen()
30                         if any(lic_id in calling_license_ids for lic_id in user.licenses)]
31        print(f'{len(calling_users)} users:')
32        print('\n'.join(user.display_name for user in calling_users))
33
34        # get details for all users
35        start = time.perf_counter()
36        details = await asyncio.gather(*[api.people.details(person_id=user.person_id, calling_data=True)
37                                         for user in calling_users])
38        expired = time.perf_counter() - start
39        print(f'Got details for {len(details)} users in {expired * 1000:.3f} ms')
40
41
42if __name__ == '__main__':
43    asyncio.run(get_calling_users())

Reference


Indices and tables