Adwords¶
AdwordsUtility¶
-
class
easyadwords.
AdwordsUtility
(credential_path, client_customer_id=None, service_version=None, max_retries=3)[source]¶ Initialize new utility object for interacting with Adwords.
Configuration/authorization is determined from googleads.yaml (credential_path).
Parameters: - credential_path – Path to googleads.yaml
- client_customer_id – Default customer_id, would override that stated in credential_path.
- service_version – If set, get specific version. Else, get the latest available version. NOTE Check change logs for APIs and googleads client before upgrading or switching report versions.
-
get_report_fields
(*args, **kwargs)[source]¶ Get details about report fields.
Parameters: - report_type – Reference: https://developers.google.com/adwords/api/docs/appendix/reports#report-types
- serialize – Convert to dictionary.
Returns: list of dictionaries or SOAP responses depending on serialize option.
-
get_service
(*args, **kwargs)[source]¶ General purpose function for getting any service listed here: https://developers.google.com/adwords/api/docs/reference/
Parameters: - service_name – Name of service
- selector –
- iterate_pages –
- serialize –
Returns:
-
list_account_labels
()[source]¶ Convenience function for AccountLabelService with predefined options.
Returns: list of dictionaries
-
list_accounts
(fields=None, predicates=None, include_hidden=False, include_mcc=False, serialize=True)[source]¶ Convenience function for ManagedCustomerService with predefined options.
Parameters: - predicates (list of dictionaries representing Predicate objects) – Predicate objects for filtering data.
- include_hidden – Include hidden accounts in results.
- include_mcc – Include MCC in results.
- serialize – Convert to dictionary.
Returns: list of dictionaries or SOAP responses depending on serialize option.
-
get_report
(*args, **kwargs)[source]¶ Downloads and cleans report.
Field Examples:
Renaming field:
{‘name’: ‘Ctr’, ‘alias’: ‘ctr’}Custom Cleaning:
NOTE - simplest implementation would be using a lambda function as shown below.
{‘name’: ‘Ctr’, ‘alias’: ‘ctr’, ‘cleaning’: lambda x: float(str(x).replace(‘%’, ‘’).strip())}
Additional Field Examples:
Prepending field “updated_at”:
{‘name’: ‘updated_at’, ‘value’: datetime.now(), ‘prepend’=True}Parameters: - start_date (datetime) – Reporting start date.
- end_date (datetime) – Reporting end date.
- report_type – Reference: https://developers.google.com/adwords/api/docs/appendix/reports#report-types
- fields (list of dictionaries) – Fields within report.
- additional_fields (list of dictionaries) – New fields to add. Only supports static values, not functions or references to other columns.
- predicates (list of dictionaries representing Predicate objects) – Predicate objects for filtering data.
- client_customer_id – Overwrite set client_customer_id when downloading report.
- include_zero_impressions – Check compatibility with report type
Returns: Generator object for cleaned report
-
get_all_account_info
(start_date, end_date)[source]¶ Convenience function wrapping ACCOUNT_PERFORMANCE_REPORT to get and parse accounts info. Can be used to subsequently filter out accounts without any activity for specific days.
Parameters: - start_date (datetime object) – Start date
- end_date – End date
Returns: Dictionary structured by account id > date > metrics
Misc Classes/Functions¶
-
easyadwords.utils.
serialize_soap_resp
(resp)[source]¶ Convert Adwords SOAP response to serializable dict
Parameters: resp – SOAP response Returns: Dictionary representation of response
-
easyadwords.utils.
date_range
(start, end, ascending=True, date_format='%Y-%m-%d')[source]¶ Simple datetime generator for dates between start and end (inclusive).
Parameters: - start (datetime object or string representation of datetime.) – Date to start at.
- end (datetime object or string representation of datetime.) – Date to stop at.
- ascending (boolean) – Toggle sorting of output.
- date_format – If input is string, denotes string datetime format to convert from.
Returns: generator object for naive datetime objects