GSC Client
Google Search Console authentication, date range helpers, and data fetching utilities.
GSCAuth
def GSCAuth(
secrets_file:str='./client_secrets.json', # Path to OAuth client secrets
token_file:str='./token.pickle', # Path to cached token
):
Google Search Console authentication handler.
get_date_range
def get_date_range(
range_type:str='today', days:int | None=None, # Number of days for `last_days`
months:int | None=None, # Number of months for `last_months`
start_date:str | None=None, # Start date for `custom` (YYYY-MM-DD)
end_date:str | None=None, # End date for `custom` (YYYY-MM-DD)
)->tuple:
Generate a date range for GSC queries, accounting for the 3-day data delay.
fetch_gsc_data
def fetch_gsc_data(
auth:GSCAuth, # Authenticated GSCAuth instance
site_url:str, # GSC property URL
start_date:str, # Start date (YYYY-MM-DD)
end_date:str, # End date (YYYY-MM-DD)
dimensions:list[str] | None=None, # GSC dimensions to group by
row_limit:int=25000, # Max rows to fetch
)->list:
Fetch analytics rows from Google Search Console.
get_verified_sites
def get_verified_sites(
auth:GSCAuth, # Authenticated GSCAuth instance
)->list:
Get all verified GSC properties for the authenticated account.