hip_data_tools.google package

Submodules

hip_data_tools.google.adwords module

This Module handles the connection and operations on Google AdWords accounts using adwords API

class hip_data_tools.google.adwords.AdWordsAdGroupAdUtil(conn: hip_data_tools.google.adwords.GoogleAdWordsConnectionManager)

Bases: hip_data_tools.google.adwords.AdWordsDataReader

Handles the querying of Adwords AdGroupAd service :param conn: Connection manager to handle the creation of :type conn: GoogleAdWordsConnectionManager :param adwords client:

set_query_to_fetch_all(start_index: int = 0, page_size: int = 500)

Get all Ad groups Ads in the account :param page_size: :param start_index:

Returns: None

class hip_data_tools.google.adwords.AdWordsAdGroupUtil(conn: hip_data_tools.google.adwords.GoogleAdWordsConnectionManager)

Bases: hip_data_tools.google.adwords.AdWordsDataReader

Handles the querying of Adwords AdGroup service :param conn: Connection manager to handle the creation of :type conn: GoogleAdWordsConnectionManager :param adwords client:

set_query_to_fetch_all(start_index: int = 0, page_size: int = 500) → None

Get all Ad groups in the account Args: page_size:

start_index:

Returns: None

set_query_to_fetch_by_campaign(campaign_id: str, start_index: int = 0, page_size: int = 500) → None

Get all AdGroups for the given Campaign :param campaign_id: the adwords campaign to query :type campaign_id: str :param page_size: :param start_index:

Returns: None

class hip_data_tools.google.adwords.AdWordsCampaignUtil(conn: hip_data_tools.google.adwords.GoogleAdWordsConnectionManager)

Bases: hip_data_tools.google.adwords.AdWordsDataReader

Handles the querying of Adwords Campaign service :param conn: Connection manager to handle the creation of :type conn: GoogleAdWordsConnectionManager :param adwords client:

set_query_to_fetch_all(start_index: int = 0, page_size: int = 500) → None

Get all campaigns associated with an account Returns: None

class hip_data_tools.google.adwords.AdWordsCustomerUtil(conn: hip_data_tools.google.adwords.GoogleAdWordsConnectionManager)

Bases: hip_data_tools.google.adwords.AdWordsDataReader

Adwords Utility to handle customer details, customer here meaning, the Adwords customer account, ie. the accounts that you see on top right corner on the AdWords console :param conn: Connection manager to handle the creation of :type conn: GoogleAdWordsConnectionManager :param adwords client:

get_customers() → List[dict]

Gets the customer details of the adwords accounts associated with the connection Returns: List[dict]

class hip_data_tools.google.adwords.AdWordsDataReader(conn: hip_data_tools.google.adwords.GoogleAdWordsConnectionManager, service: str, version: str, page_size: int = 1000)

Bases: hip_data_tools.google.adwords.AdWordsUtil

Generic Adwords Utility class generates the required services to consume adwords API :param conn: Connection manager to handle the creation of :type conn: GoogleAdWordsConnectionManager :param adwords client:

download_all_as_dataframe() → pandas.core.frame.DataFrame

Generates a data frame from the next page of the API call to adwords Returns: List[dict]

download_all_as_dict() → List[dict]

Generates list of Dict from the adwords query language query as described in adwords api Returns: List[dict]

download_next_page_as_dataframe() → pandas.core.frame.DataFrame

Generates a data frame from the next page of the API call to adwords Returns: List[dict]

download_next_page_as_dict() → List[dict]

Generates a list of dict from the next page of the API call to adwords Returns: List[dict]

get_parallel_payloads(page_size: int, number_of_workers: int) → List[dict]

gives a list of dicts that contain start index, page size, and number of iterations :param page_size: number of elements in each page / api call :type page_size: int :param number_of_workers: total number of parallel workers for which the payload needs :type number_of_workers: int :param to be distributed:

Returns: List[dict] eg: [

{‘number_of_pages’: 393, ‘page_size’: 1000, ‘start_index’: 0, ‘worker’: 0}, {‘number_of_pages’: 393, ‘page_size’: 1000, ‘start_index’: 393000, ‘worker’: 1}, {‘number_of_pages’: 393, ‘page_size’: 1000, ‘start_index’: 786000, ‘worker’: 2},

]

set_query(query: googleads.adwords.ServiceQueryBuilder) → None

Sets the new query for the class to use awql, once the query is set, the download methods can iterate over paged results :param query: query built as per adwords query language :type query: ServiceQueryBuilder

Returns: None

class hip_data_tools.google.adwords.AdWordsManagedCustomerUtil(conn: hip_data_tools.google.adwords.GoogleAdWordsConnectionManager)

Bases: hip_data_tools.google.adwords.AdWordsUtil

Adwords Utility to parse through and gather Account Information for all sub accounts :param conn: Connection manager to handle the creation of :type conn: GoogleAdWordsConnectionManager :param adwords client:

get_all_accounts(page_size: int = 1000) → List[dict]

Gets the customer details of the adwords accounts associated with the connection Returns: List[dict]

get_all_accounts_as_dataframe(page_size: int = 1000) → pandas.core.frame.DataFrame

Gets the customer details of the adwords accounts associated with the connection Returns: DataFrame

class hip_data_tools.google.adwords.AdWordsOfflineConversionUtil(conn: hip_data_tools.google.adwords.GoogleAdWordsConnectionManager)

Bases: hip_data_tools.google.adwords.AdWordsUtil

Adwords Utility to handle offline conversions :param conn: Connection manager to handle the creation of :type conn: GoogleAdWordsConnectionManager :param adwords client:

upload_conversions(data: List[dict]) -> (typing.List[dict], typing.List[dict])

Upload a list of conversions as a batch :param data List[dict]: a List of conversion dictionaries like: :param [:

{
‘googleClickId’: ‘some valid gclid’, ‘conversionName’: ‘some conversion name’, ‘conversionTime’: ‘20200309 074353 UTC’, ‘conversionValue’: 17.0, ‘conversionCurrencyCode’: ‘AUD’,

}, {

‘googleClickId’: ‘some other valid gclid’, ‘conversionName’: ‘some conversion name’, ‘conversionTime’: ‘20200309 023001 UTC’, ‘conversionValue’: 17.0, ‘conversionCurrencyCode’: ‘AUD’, ‘externalAttributionCredit’: 0.3, ‘externalAttributionModel’: ‘Linear’,

},

Parameters:]

Returns (List[dict], List[dict]): A tuple of lists holding succeeded and failed records, respectively eg. (

[
{
‘googleClickId’: ‘gclid that succeeded’, ‘conversionName’: ‘some conversions name’, ‘conversionTime’: ‘20200309 074353 UTC’, ‘conversionValue’: 17.0, ‘conversionCurrencyCode’: ‘AUD’, ‘externalAttributionCredit’: None, ‘externalAttributionModel’: None

},

] ,
[
{

‘fieldPath’: ‘operations[0].operand’, ‘fieldPathElements’: [

{
‘field’: ‘operations’, ‘index’: 0

}, {

‘field’: ‘operand’, ‘index’: None

}

], ‘trigger’: None, ‘errorString’: ‘OfflineConversionError.UNPARSEABLE_GCLID’, ‘ApiError.Type’: ‘OfflineConversionError’, ‘reason’: ‘UNPARSEABLE_GCLID’, ‘data’: {

‘googleClickId’: ‘Gclid that failed’, ‘conversionName’: ‘some conversion name’, ‘conversionTime’: ‘20200309 074353 UTC’, ‘conversionValue’: 17.0, ‘conversionCurrencyCode’: ‘AUD’, ‘externalAttributionCredit’: None, ‘externalAttributionModel’: None

}

},

]

)

class hip_data_tools.google.adwords.AdWordsParallelDataReadEstimator(conn: hip_data_tools.google.adwords.GoogleAdWordsConnectionManager, service: str, version: str, query: googleads.adwords.ServiceQueryBuilder)

Bases: hip_data_tools.google.adwords.AdWordsUtil

Class to use a service endpoint and awql query to estimate the number of parallel payloads, and their offsets :param conn: Connection manager to handle the creation of :type conn: GoogleAdWordsConnectionManager :param adwords client: :param service: Adwords service api to use for querying :type service: str :param version: Adwords service api version to use for querying :type version: str :param query: the Query builder object without limit clause :type query: ServiceQueryBuilder

get_parallel_payloads(page_size: int, number_of_workers: int) → List[dict]

gives a list of dicts that contain start index, page size, and number of iterations :param page_size: number of elements in each page / api call :type page_size: int :param number_of_workers: total number of parallel workers for which the payload needs :type number_of_workers: int :param to be distributed:

Returns: List[dict] eg: [

{‘number_of_pages’: 393, ‘page_size’: 1000, ‘start_index’: 0, ‘worker’: 0}, {‘number_of_pages’: 393, ‘page_size’: 1000, ‘start_index’: 393000, ‘worker’: 1}, {‘number_of_pages’: 393, ‘page_size’: 1000, ‘start_index’: 786000, ‘worker’: 2},

]

class hip_data_tools.google.adwords.AdWordsReportDefinitionReader(conn: hip_data_tools.google.adwords.GoogleAdWordsConnectionManager)

Bases: hip_data_tools.google.adwords.AdWordsUtil

Class to interact with the ReportDefinitionService and access fields for adwords reports :param conn: Connection manager to handle the creation of :type conn: GoogleAdWordsConnectionManager

adwords client

get_report_fields(report_type: str) → List[dict]

Get a list of fields for a given report. :param report_type: Possible reports are defined in the documentation here - :type report_type: str :param https: //developers.google.com/adwords/api/docs/appendix/reports/all-reports

Returns: List[dict]

class hip_data_tools.google.adwords.AdWordsReportReader(conn: hip_data_tools.google.adwords.GoogleAdWordsConnectionManager)

Bases: object

Generic data reader class for downloading data from report awql efficiently :param conn: Connection manager to handle the creation of :type conn: GoogleAdWordsConnectionManager

adwords client
awql_to_dataframe(query: googleads.adwords.ReportQuery, include_zero_impressions: bool = True, **kwargs) → pandas.core.frame.DataFrame

Download the data returned by report query in a compressed format and return it in form of a pandas dataframe :param query: an awql report query, see example :type query: ReportQuery :param https: //github.com/googleads/googleads-python-lib/blob/master/examples/adwords :param /v201809/reporting/stream_criteria_report_results.py#L34-L39: :param include_zero_impressions: include_zero_impressions :type include_zero_impressions: bool

Returns: DataFrame

class hip_data_tools.google.adwords.AdWordsUtil(conn: hip_data_tools.google.adwords.GoogleAdWordsConnectionManager, service: str, version: str)

Bases: object

Generic Adwords Utility class generates the required services to consume adwords API :param conn: Connection manager to handle the creation of :type conn: GoogleAdWordsConnectionManager :param adwords client:

class hip_data_tools.google.adwords.GoogleAdWordsConnectionManager(settings: hip_data_tools.google.adwords.GoogleAdWordsConnectionSettings)

Bases: hip_data_tools.google.adwords.GoogleOAuthConnectionManager

AdWords Connection Manager that manages the lifecycle of authentication and the resulting adwords client :param settings: setting to use for connecting to adwords :type settings: GoogleAdWordsConnectionSettings

get_adwords_client(**kwargs) → googleads.adwords.AdWordsClient

Gets the connected adwords client, and creates one if not exist Returns (AdWordsClient): Adwords Client

class hip_data_tools.google.adwords.GoogleAdWordsConnectionSettings(client_id: str, secrets_manager: hip_data_tools.google.adwords.GoogleAdWordsSecretsManager, user_agent: str, client_customer_id: Optional[str])

Bases: hip_data_tools.google.adwords.GoogleOAuthConnectionSettings

Handle connection settings for AdWords client

class hip_data_tools.google.adwords.GoogleAdWordsSecretsManager(source: hip_data_tools.common.KeyValueSource = <hip_data_tools.common.EnvironmentKeyValueSource object>, client_secret_var: str = 'adwords_client_secret', refresh_token_var: str = 'adwords_refresh_token', developer_token_var: str = 'adwords_developer_token')

Bases: hip_data_tools.common.SecretsManager

Secrets manager for Google Adwords Specific secrets, these are modeled to handle the OAuth based google client and refresh token secrets :param source: The Key Value source which holds secrets :type source: KeyValueSource :param client_secret_var: The Key pointer for client_secret :type client_secret_var: str :param refresh_token_var: The Key pointer for refresh_token :type refresh_token_var: str :param developer_token_var: The Key pointer for developer_token :type developer_token_var: str

class hip_data_tools.google.adwords.GoogleOAuthConnectionManager(settings: hip_data_tools.google.adwords.GoogleOAuthConnectionSettings)

Bases: object

Creates an OAuth client from google adwords library :param settings: connection settings to use for creation :type settings: GoogleOAuthConnectionSettings

class hip_data_tools.google.adwords.GoogleOAuthConnectionSettings(client_id: str, secrets_manager: hip_data_tools.google.adwords.GoogleAdWordsSecretsManager)

Bases: object

Handle connection settings for AdWords client

hip_data_tools.google.adwords.dataclass(maybe_cls=None, these=None, repr_ns=None, repr=True, cmp=None, hash=None, init=True, slots=False, frozen=False, weakref_slot=True, str=False, *, auto_attribs=True, kw_only=False, cache_hash=False, auto_exc=False, eq=None, order=None)

A class decorator that adds dunder-methods according to the specified attributes using attr.ib or the these argument.

Parameters:
  • these (dict of str to attr.ib) –

    A dictionary of name to attr.ib mappings. This is useful to avoid the definition of your attributes within the class body because you can’t (e.g. if you want to add __repr__ methods to Django models) or don’t want to.

    If these is not None, attrs will not search the class body for attributes and will not remove any attributes from it.

    If these is an ordered dict (dict on Python 3.6+, collections.OrderedDict otherwise), the order is deduced from the order of the attributes inside these. Otherwise the order of the definition of the attributes is used.

  • repr_ns (str) – When using nested classes, there’s no way in Python 2 to automatically detect that. Therefore it’s possible to set the namespace explicitly for a more meaningful repr output.
  • repr (bool) – Create a __repr__ method with a human readable representation of attrs attributes..
  • str (bool) – Create a __str__ method that is identical to __repr__. This is usually not necessary except for Exceptions.
  • eq (bool or None) –

    If True or None (default), add __eq__ and __ne__ methods that check two instances for equality.

    They compare the instances as if they were tuples of their attrs attributes, but only iff the types of both classes are identical!

  • order (bool or None) – If True, add __lt__, __le__, __gt__, and __ge__ methods that behave like eq above and allow instances to be ordered. If None (default) mirror value of eq.
  • cmp (bool or None) – Setting to True is equivalent to setting eq=True, order=True. Deprecated in favor of eq and order, has precedence over them for backward-compatibility though. Must not be mixed with eq or order.
  • hash (bool or None) –

    If None (default), the __hash__ method is generated according how eq and frozen are set.

    1. If both are True, attrs will generate a __hash__ for you.
    2. If eq is True and frozen is False, __hash__ will be set to None, marking it unhashable (which it is).
    3. If eq is False, __hash__ will be left untouched meaning the __hash__ method of the base class will be used (if base class is object, this means it will fall back to id-based hashing.).

    Although not recommended, you can decide for yourself and force attrs to create one (e.g. if the class is immutable even though you didn’t freeze it programmatically) by passing True or not. Both of these cases are rather special and should be used carefully.

    See our documentation on hashing, Python’s documentation on object.__hash__, and the GitHub issue that led to the default behavior for more details.

  • init (bool) – Create a __init__ method that initializes the attrs attributes. Leading underscores are stripped for the argument name. If a __attrs_post_init__ method exists on the class, it will be called after the class is fully initialized.
  • slots (bool) – Create a slotted class <slotted classes> that’s more memory-efficient.
  • frozen (bool) –

    Make instances immutable after initialization. If someone attempts to modify a frozen instance, attr.exceptions.FrozenInstanceError is raised.

    Please note:

    1. This is achieved by installing a custom __setattr__ method on your class, so you can’t implement your own.
    2. True immutability is impossible in Python.
    3. This does have a minor a runtime performance impact <how-frozen> when initializing new instances. In other words: __init__ is slightly slower with frozen=True.
    4. If a class is frozen, you cannot modify self in __attrs_post_init__ or a self-written __init__. You can circumvent that limitation by using object.__setattr__(self, "attribute_name", value).
  • weakref_slot (bool) – Make instances weak-referenceable. This has no effect unless slots is also enabled.
  • auto_attribs (bool) –

    If True, collect PEP 526-annotated attributes (Python 3.6 and later only) from the class body.

    In this case, you must annotate every field. If attrs encounters a field that is set to an attr.ib but lacks a type annotation, an attr.exceptions.UnannotatedAttributeError is raised. Use field_name: typing.Any = attr.ib(...) if you don’t want to set a type.

    If you assign a value to those attributes (e.g. x: int = 42), that value becomes the default value like if it were passed using attr.ib(default=42). Passing an instance of Factory also works as expected.

    Attributes annotated as typing.ClassVar, and attributes that are neither annotated nor set to an attr.ib are ignored.

  • kw_only (bool) – Make all attributes keyword-only (Python 3+) in the generated __init__ (if init is False, this parameter is ignored).
  • cache_hash (bool) – Ensure that the object’s hash code is computed only once and stored on the object. If this is set to True, hashing must be either explicitly or implicitly enabled for this class. If the hash code is cached, avoid any reassignments of fields involved in hash code computation or mutations of the objects those fields point to after object creation. If such changes occur, the behavior of the object’s hash code is undefined.
  • auto_exc (bool) –

    If the class subclasses BaseException (which implicitly includes any subclass of any exception), the following happens to behave like a well-behaved Python exceptions class:

    • the values for eq, order, and hash are ignored and the instances compare and hash by the instance’s ids (N.B. attrs will not remove existing implementations of __hash__ or the equality methods. It just won’t add own ones.),
    • all attributes that are either passed into __init__ or have a default value are additionally available as a tuple in the args attribute,
    • the value of str is ignored leaving __str__ to base classes.

New in version 16.0.0: slots

New in version 16.1.0: frozen

New in version 16.3.0: str

New in version 16.3.0: Support for __attrs_post_init__.

Changed in version 17.1.0: hash supports None as value which is also the default now.

New in version 17.3.0: auto_attribs

Changed in version 18.1.0: If these is passed, no attributes are deleted from the class body.

Changed in version 18.1.0: If these is ordered, the order is retained.

New in version 18.2.0: weakref_slot

Deprecated since version 18.2.0: __lt__, __le__, __gt__, and __ge__ now raise a DeprecationWarning if the classes compared are subclasses of each other. __eq and __ne__ never tried to compared subclasses to each other.

Changed in version 19.2.0: __lt__, __le__, __gt__, and __ge__ now do not consider subclasses comparable anymore.

New in version 18.2.0: kw_only

New in version 18.2.0: cache_hash

New in version 19.1.0: auto_exc

Deprecated since version 19.2.0: cmp Removal on or after 2021-06-01.

New in version 19.2.0: eq and order

hip_data_tools.google.adwords.get_page_as_list_of_dict(page: dict) → List[collections.OrderedDict]

Converts a list of entries from google adwords response into a list of Ordered Dictionaries :param page: the response page from google adwords api :type page: dict

Returns: List[dict]

hip_data_tools.google.adwords.zeep_object_to_dict(obj: Any) → collections.OrderedDict

converts the zeep client objects used in google adwords to Ordered Dict, also converts nested objects to ordered dict recursively :param obj: the Zeep object to be converted :type obj: Any

Returns: OrderedDict

hip_data_tools.google.common module

Module contains variables and methods used for common / shared operations throughput the google services package

class hip_data_tools.google.common.GoogleApiConnectionManager(settings: hip_data_tools.google.common.GoogleApiConnectionSettings, scope: List[str])

Bases: abc.ABC

Google API connection manager abstract class

get_client()

Get the connection for google sheets Returns: authenticated client object of the connection library

class hip_data_tools.google.common.GoogleApiConnectionSettings(secrets_manager: hip_data_tools.google.common.GoogleApiSecretsManager)

Bases: object

Encapsulates the Google API connection settings

class hip_data_tools.google.common.GoogleApiSecretsManager(source: hip_data_tools.common.KeyValueSource = <hip_data_tools.common.EnvironmentKeyValueSource object>, key_json_var: str = 'key_json')

Bases: hip_data_tools.common.SecretsManager

Parameters:
  • source (KeyValueSource) – a kv source that has secrets
  • key_json_var (str) – The variable name or the key for finding the key file json object
hip_data_tools.google.common.dataclass(maybe_cls=None, these=None, repr_ns=None, repr=True, cmp=None, hash=None, init=True, slots=False, frozen=False, weakref_slot=True, str=False, *, auto_attribs=True, kw_only=False, cache_hash=False, auto_exc=False, eq=None, order=None)

A class decorator that adds dunder-methods according to the specified attributes using attr.ib or the these argument.

Parameters:
  • these (dict of str to attr.ib) –

    A dictionary of name to attr.ib mappings. This is useful to avoid the definition of your attributes within the class body because you can’t (e.g. if you want to add __repr__ methods to Django models) or don’t want to.

    If these is not None, attrs will not search the class body for attributes and will not remove any attributes from it.

    If these is an ordered dict (dict on Python 3.6+, collections.OrderedDict otherwise), the order is deduced from the order of the attributes inside these. Otherwise the order of the definition of the attributes is used.

  • repr_ns (str) – When using nested classes, there’s no way in Python 2 to automatically detect that. Therefore it’s possible to set the namespace explicitly for a more meaningful repr output.
  • repr (bool) – Create a __repr__ method with a human readable representation of attrs attributes..
  • str (bool) – Create a __str__ method that is identical to __repr__. This is usually not necessary except for Exceptions.
  • eq (bool or None) –

    If True or None (default), add __eq__ and __ne__ methods that check two instances for equality.

    They compare the instances as if they were tuples of their attrs attributes, but only iff the types of both classes are identical!

  • order (bool or None) – If True, add __lt__, __le__, __gt__, and __ge__ methods that behave like eq above and allow instances to be ordered. If None (default) mirror value of eq.
  • cmp (bool or None) – Setting to True is equivalent to setting eq=True, order=True. Deprecated in favor of eq and order, has precedence over them for backward-compatibility though. Must not be mixed with eq or order.
  • hash (bool or None) –

    If None (default), the __hash__ method is generated according how eq and frozen are set.

    1. If both are True, attrs will generate a __hash__ for you.
    2. If eq is True and frozen is False, __hash__ will be set to None, marking it unhashable (which it is).
    3. If eq is False, __hash__ will be left untouched meaning the __hash__ method of the base class will be used (if base class is object, this means it will fall back to id-based hashing.).

    Although not recommended, you can decide for yourself and force attrs to create one (e.g. if the class is immutable even though you didn’t freeze it programmatically) by passing True or not. Both of these cases are rather special and should be used carefully.

    See our documentation on hashing, Python’s documentation on object.__hash__, and the GitHub issue that led to the default behavior for more details.

  • init (bool) – Create a __init__ method that initializes the attrs attributes. Leading underscores are stripped for the argument name. If a __attrs_post_init__ method exists on the class, it will be called after the class is fully initialized.
  • slots (bool) – Create a slotted class <slotted classes> that’s more memory-efficient.
  • frozen (bool) –

    Make instances immutable after initialization. If someone attempts to modify a frozen instance, attr.exceptions.FrozenInstanceError is raised.

    Please note:

    1. This is achieved by installing a custom __setattr__ method on your class, so you can’t implement your own.
    2. True immutability is impossible in Python.
    3. This does have a minor a runtime performance impact <how-frozen> when initializing new instances. In other words: __init__ is slightly slower with frozen=True.
    4. If a class is frozen, you cannot modify self in __attrs_post_init__ or a self-written __init__. You can circumvent that limitation by using object.__setattr__(self, "attribute_name", value).
  • weakref_slot (bool) – Make instances weak-referenceable. This has no effect unless slots is also enabled.
  • auto_attribs (bool) –

    If True, collect PEP 526-annotated attributes (Python 3.6 and later only) from the class body.

    In this case, you must annotate every field. If attrs encounters a field that is set to an attr.ib but lacks a type annotation, an attr.exceptions.UnannotatedAttributeError is raised. Use field_name: typing.Any = attr.ib(...) if you don’t want to set a type.

    If you assign a value to those attributes (e.g. x: int = 42), that value becomes the default value like if it were passed using attr.ib(default=42). Passing an instance of Factory also works as expected.

    Attributes annotated as typing.ClassVar, and attributes that are neither annotated nor set to an attr.ib are ignored.

  • kw_only (bool) – Make all attributes keyword-only (Python 3+) in the generated __init__ (if init is False, this parameter is ignored).
  • cache_hash (bool) – Ensure that the object’s hash code is computed only once and stored on the object. If this is set to True, hashing must be either explicitly or implicitly enabled for this class. If the hash code is cached, avoid any reassignments of fields involved in hash code computation or mutations of the objects those fields point to after object creation. If such changes occur, the behavior of the object’s hash code is undefined.
  • auto_exc (bool) –

    If the class subclasses BaseException (which implicitly includes any subclass of any exception), the following happens to behave like a well-behaved Python exceptions class:

    • the values for eq, order, and hash are ignored and the instances compare and hash by the instance’s ids (N.B. attrs will not remove existing implementations of __hash__ or the equality methods. It just won’t add own ones.),
    • all attributes that are either passed into __init__ or have a default value are additionally available as a tuple in the args attribute,
    • the value of str is ignored leaving __str__ to base classes.

New in version 16.0.0: slots

New in version 16.1.0: frozen

New in version 16.3.0: str

New in version 16.3.0: Support for __attrs_post_init__.

Changed in version 17.1.0: hash supports None as value which is also the default now.

New in version 17.3.0: auto_attribs

Changed in version 18.1.0: If these is passed, no attributes are deleted from the class body.

Changed in version 18.1.0: If these is ordered, the order is retained.

New in version 18.2.0: weakref_slot

Deprecated since version 18.2.0: __lt__, __le__, __gt__, and __ge__ now raise a DeprecationWarning if the classes compared are subclasses of each other. __eq and __ne__ never tried to compared subclasses to each other.

Changed in version 19.2.0: __lt__, __le__, __gt__, and __ge__ now do not consider subclasses comparable anymore.

New in version 18.2.0: kw_only

New in version 18.2.0: cache_hash

New in version 19.1.0: auto_exc

Deprecated since version 19.2.0: cmp Removal on or after 2021-06-01.

New in version 19.2.0: eq and order

hip_data_tools.google.sheets module

This module is responsible for all Google sheets operations

class hip_data_tools.google.sheets.GoogleSheetConnectionManager(settings: hip_data_tools.google.common.GoogleApiConnectionSettings)

Bases: hip_data_tools.google.common.GoogleApiConnectionManager

Encapsulates the Google sheets API connection settings

get_client()

Get the connection for google sheets Returns: authorised connection for google sheets

class hip_data_tools.google.sheets.SheetUtil(conn_manager: hip_data_tools.google.sheets.GoogleSheetConnectionManager, workbook_url, sheet)

Bases: object

Utility class for connecting to google sheets :param conn_manager: connection to read google sheets :type conn_manager: GoogleSheetConnectionManager :param conn_manager: row number of the filed names :type conn_manager: integer :param conn_manager: row number of the field types :type conn_manager: integer

get_dataframe(field_names_row_number: int, field_types_row_number: int, row_range=None, data_start_row_number=None) → pandas.core.frame.DataFrame

Get the field types as a list :param field_names_row_number: Row number of field names :type field_names_row_number: int :param field_types_row_number: Row number of field types :type field_types_row_number: int :param row_range: Row range eg: “3:4” :type row_range: str :param data_start_row_number: Starting row number of actual data :type data_start_row_number: int

Returns: field types list

get_fields_names(field_names_row_number: int) → List[str]

Get the field names as a list :param field_names_row_number: row number of field names :type field_names_row_number: int

Returns: field names list

get_fields_types(field_types_row_number: int) → List[str]

Get the field types as a list :param field_types_row_number: Row number of field types :type field_types_row_number: int

Returns: field types list

get_value_matrix(row_range=None, data_start_row_number=None) → List[List[Any]]

Get the values of the sheet as a 2D array :param row_range: [optional]range of the rows that need to be selected (eg: ‘1:7’) :type row_range: string :param data_start_row_number: (eg: 2) :type data_start_row_number: integer

Returns: values of the sheet as a 2D array

Module contents