tools
Module for interacting with the BAV API's tools
.
Read more at https://developer.wppbav.com/docs/2.x/tools.
Each tool will return very different results, depending on each of their requirements. Check the return types of each function and method.
Examples:
>>> from bavapi.tools import ToolsClient
>>> async with ToolsClient("TOKEN") as client: # Replace "TOKEN" with your BAV API key
>>> result = await client.commitment_funnel(brands=1, studies=1)
ToolsClient(auth_token='', *, base_url='', timeout=30.0, verify=True, headers=None, user_agent='', client=None, retries=3)
¶
Asynchronous API to interact with the WPPBAV Fount API tools.
Read more at https://developer.wppbav.com/docs/2.x/tools.
This class uses asyncio
to perform asynchronous requests to the Fount API.
Asynchronous requests allow you to make multiple requests at the same time, extremely helpful for working with a paginated API like the Fount. (returns data in multiple pages or requests instead of one single download)
To use the Client class, you will need to precede calls with await
:
bav = Client("TOKEN") # creating client instance does not use `await`
data = await bav.brands("Swatch") # must use `await`
For more information, see the asyncio
documentation for Python.
Either auth_token
or client
are required to instantiate a Client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
auth_token |
str
|
WPPBAV Fount API authorization token, default |
''
|
timeout |
float
|
Maximum timeout for requests in seconds, default 30.0 |
30.0
|
verify |
bool or str
|
Verify SSL credentials, default True Also accepts a path string to an SSL certificate file. |
True
|
headers |
dict[str, str]
|
Collection of headers to send with each request, default None |
None
|
user_agent |
str
|
The name of the User-Agent to send to the Fount API, default If no user_agent is set, |
''
|
client |
AsyncClient
|
Authenticated async client, default None If |
None
|
retries |
int
|
Number of times to retry a request, default 3 |
3
|
Raises:
Type | Description |
---|---|
ValueError
|
If neither |
Examples:
Use async with
to get data and close the connection.
This way you get the benefits from httpx
speed improvements
and closes the connection when exiting the async with block.
>>> async with ToolsClient("TOKEN") as bav:
... data = await bav.commitment_funnel(brands=1, studies=1)
When not using async with
, close the connection manually by awaiting aclose
.
>>> bav = ToolsClient("TOKEN")
>>> data = await bav.commitment_funnel(brands=1, studies=1)
>>> await bav.aclose()
If you want to perform multiple endpoint requests with the same Client
, it is
recommended to use verbose=False
to avoid jumping progress bars.
>>> async with ToolsClient("TOKEN", verbose=False) as bav:
... resp1 = await bav.commitment_funnel(brands=1, studies=1)
... resp2 = await bav.brand_worth_map(brands=1, studies=1)
Source code in bavapi/tools.py
aclose()
async
¶
archetypes(brands, studies, audiences=None, *, categories=None, collections=None)
async
¶
Retrieve results from the archetypes
endpoint
See https://developer.wppbav.com/docs/2.x/tools/archetypes for more info.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
brands |
ListOrValues[int]
|
Brand ID or list of brand IDs |
required |
studies |
ListOrValues[int]
|
Study ID or list of study IDs |
required |
audiences |
OptionalListOr[int]
|
Audience ID or list of audience IDs, default None |
None
|
categories |
OptionalListOr[int]
|
Category ID or list of category IDs for the target category, default None |
None
|
collections |
OptionalListOr[int]
|
Collection ID or list of collections for the target collection, default None |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
Dataframe containing the results |
Raises:
Type | Description |
---|---|
ValueError
|
If category or collection are not specified, or if they are both specified |
APIError
|
If an error occurs with the query |
Source code in bavapi/tools.py
brand_personality_match(brands, studies, audiences=None)
async
¶
Retrieve results from the brand-personality-match
endpoint
See https://developer.wppbav.com/docs/2.x/tools/brand-personality-match for more info.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
brands |
ListOrValues[int]
|
Brand ID or list of brand IDs |
required |
studies |
ListOrValues[int]
|
Study ID or list of study IDs |
required |
audiences |
OptionalListOr[int]
|
Audience ID or list of audience IDs, default None |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
Dataframe containing the results |
Raises:
Type | Description |
---|---|
APIError
|
If an error occurs with the query |
Source code in bavapi/tools.py
brand_vulnerability_map(brand)
async
¶
Retrieve results from the brand-vulnerability-map
endpoint
See https://developer.wppbav.com/docs/2.x/tools/brand-vulnerability-map for more info.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
brand |
int
|
Brand ID |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
Dataframe containing the results |
Raises:
Type | Description |
---|---|
APIError
|
If an error occurs with the query |
Source code in bavapi/tools.py
brand_worth_map(brands, studies, audiences=None)
async
¶
Retrieve results from the brand-worth-map
endpoint
See https://developer.wppbav.com/docs/2.x/tools/brand-worth-map for more info.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
brands |
ListOrValues[int]
|
Brand ID or list of brand IDs |
required |
studies |
ListOrValues[int]
|
Study ID or list of study IDs |
required |
audiences |
OptionalListOr[int]
|
Audience ID or list of audience IDs, default None |
None
|
Returns:
Type | Description |
---|---|
Tuple[JSONDict, DataFrame]
|
A tuple containing a JSON dictionary of metadata and a Dataframe with the results |
Raises:
Type | Description |
---|---|
APIError
|
If an error occurs with the query |
Source code in bavapi/tools.py
category_worth_map(categories, studies, audiences=None)
async
¶
Retrieve results from the category-worth-map
endpoint
[NOT IMPLEMENTED]
See https://developer.wppbav.com/docs/2.x/tools/category-worth-map for more info.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
categories |
ListOrValues[int]
|
Category ID or list of category IDs |
required |
studies |
ListOrValues[int]
|
Study ID or list of study IDs |
required |
audiences |
OptionalListOr[int]
|
Audience ID or list of audience IDs, default None |
None
|
Returns:
Type | Description |
---|---|
Tuple[JSONDict, DataFrame]
|
A tuple containing a JSON dictionary of metadata and a Dataframe with the results |
Raises:
Type | Description |
---|---|
APIError
|
If an error occurs with the query |
Source code in bavapi/tools.py
commitment_funnel(brands, studies, audiences=None)
async
¶
Retrieve results from the commitment-funnel
endpoint
See https://developer.wppbav.com/docs/2.x/tools/commitment-funnel for more info.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
brands |
ListOrValues[int]
|
Brand ID or list of brand IDs |
required |
studies |
ListOrValues[int]
|
Study ID or list of study IDs |
required |
audiences |
OptionalListOr[int]
|
Audience ID or list of audience IDs, default None |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
Dataframe containing the results |
Raises:
Type | Description |
---|---|
APIError
|
If an error occurs with the query |
Source code in bavapi/tools.py
cost_of_entry(brand, study, audience=None, *, categories=None, collections=None, comparison_name=None)
async
¶
Retrieve results from the cost-of-entry
endpoint
See https://developer.wppbav.com/docs/2.x/tools/cost-of-entry for more info.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
brand |
int
|
Brand ID |
required |
study |
int
|
Study ID |
required |
audience |
int
|
Audience ID, default None |
None
|
categories |
OptionalListOr[int]
|
Category ID or list of category IDs for the target category, default None |
None
|
collections |
OptionalListOr[int]
|
Collection ID or list of collections for the target collection, default None |
None
|
comparison_name |
str
|
Custom name to give the comparison, default None Default behavior is to use the category or collection name. |
None
|
Returns:
Type | Description |
---|---|
Tuple[JSONDict, DataFrame]
|
A tuple containing a JSON dictionary of metadata and a Dataframe with the results |
Raises:
Type | Description |
---|---|
ValueError
|
If category or collection are not specified, or if they are both specified |
APIError
|
If an error occurs with the query |
Source code in bavapi/tools.py
love_plus(brands, studies, audiences=None)
async
¶
Retrieve results from the love-plus
endpoint
See https://developer.wppbav.com/docs/2.x/tools/love-plus for more info.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
brands |
ListOrValues[int]
|
Brand ID or list of brand IDs |
required |
studies |
ListOrValues[int]
|
Study ID or list of study IDs |
required |
audiences |
OptionalListOr[int]
|
Audience ID or list of audience IDs, default None |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
Dataframe containing the results |
Raises:
Type | Description |
---|---|
APIError
|
If an error occurs with the query |
Source code in bavapi/tools.py
partnership_exchange_map(brands, studies, comparison_brands)
async
¶
Retrieve results from the partnership-exchange-map
endpoint
See https://developer.wppbav.com/docs/2.x/tools/partnership-exchange-map for more info.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
brands |
ListOrValues[int]
|
Brand ID or list of brand IDs |
required |
studies |
ListOrValues[int]
|
Study ID or list of study IDs |
required |
comparison_brands |
ListOrValues[int]
|
Brand ID for comparison with the brand specified in `brands |
required |
Returns:
Type | Description |
---|---|
Tuple[JSONDict, DataFrame]
|
A tuple containing a JSON dictionary of metadata and a Dataframe with the results |
Raises:
Type | Description |
---|---|
APIError
|
If an error occurs with the query |
Source code in bavapi/tools.py
swot(brands, studies, audiences=None, *, categories=None, collections=None, comparison_name=None)
async
¶
Retrieve results from the swot
endpoint
[NOT IMPLEMENTED]
See https://developer.wppbav.com/docs/2.x/tools/swot for more info.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
brands |
ListOrValues[int]
|
Brand ID or list of brand IDs |
required |
studies |
ListOrValues[int]
|
Study ID or list of study IDs |
required |
audiences |
OptionalListOr[int]
|
Audience ID or list of audience IDs, default None |
None
|
categories |
OptionalListOr[int]
|
Category ID or list of category IDs for the target category, default None |
None
|
collections |
OptionalListOr[int]
|
Collection ID or list of collections for the target collection, default None |
None
|
comparison_name |
str
|
Custom name to give the comparison, default None Default behavior is to use "Category" or "Collection", depending on whether categories or collections were specified in the method call. |
None
|
Returns:
Type | Description |
---|---|
Tuple[JSONDict, DataFrame]
|
A tuple containing a JSON dictionary of metadata and a Dataframe with the results |
Raises:
Type | Description |
---|---|
ValueError
|
If category or collection are not specified, or if they are both specified |
APIError
|
If an error occurs with the query |
Source code in bavapi/tools.py
toplist_market(brands, studies, audiences=None, *, metrics=None, metric_keys=None)
async
¶
Retrieve results from the toplist-market
endpoint
[NOT IMPLEMENTED]
See https://developer.wppbav.com/docs/2.x/tools/toplist-market for more info.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
brands |
ListOrValues[int]
|
Brand ID or list of brand IDs |
required |
studies |
ListOrValues[int]
|
Study ID or list of study IDs |
required |
audiences |
OptionalListOr[int]
|
Audience ID or list of audience IDs, default None |
None
|
metrics |
OptionalListOr[int]
|
Metric ID or list of metric IDs, default None |
None
|
metric_keys |
OptionalListOr[str]
|
Metric key or list of metric keys, default None |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
Dataframe containing the results |
Raises:
Type | Description |
---|---|
ValueError
|
If metrics or metric_keys are not specified, or if they are both specified |
APIError
|
If an error occurs with the query |