Reference Classes
The SDK can generate some convenience reference classes which map Fount resource IDs with a more readable name, both for ease of use and for autocompletion in IDEs.
These classes are automatically generated by a console command that becomes available once bavapi
is installed.
A Fount API token is required to generate reference files. See
the Authentication section for more information and
instructions for using .env
files within your Python project.
As of v1.1
the following reference classes will be generated in a folder named bavapi_refs
:
Audiences
: encodes audience IDsCountries
: encodes country IDs
A sample reference class would look like this:
class Audiences(Enum):
ALL_ADULTS = 27 # Random ID
...
And could be used to have better visibility when filtering API responses:
- Using Reference class
- Not using Reference class
bavapi.brandscape_data(country_code="US", year=2022, audiences=Audiences.ALL_ADULTS)
bavapi.brandscape_data(country_code="US", year=2022, audiences=27)
Please take care not to commit reference classes to public repositories. Add bavapi_refs/
to your .gitignore
file.
To generate these reference classes, there are two options for authenticating your requests:
- Specify the Fount API token via the
-t
/--token
argument - Use a
.env
file to store your Fount API token and installpython-dotenv
to read the file into your environment. See the Authentication section for more info.
Run the following command:
- With a `.env` file
- Using the `-t`/`--token` argument
bavapi-gen-refs --all
bavapi-gen-refs -t "TOKEN" --all
Alternatively, you can specify the name of the reference class to generate:
bavapi-gen-refs --name audiences
To update existing reference classes with the latest data, re-run bavapi-gen-refs --all
on your terminal.
The audiences and markets change over time. It is recommended to update your reference classes regularly. Typically audiences and markets are never deleted, however we can't guarantee that it will never happen.