### Retrieve Raw DataFrame with show_data() Source: https://context7.com/antoineeripret/gsc_wrapper/llms.txt Use `show_data()` to get the underlying Pandas DataFrame after performing analysis. This is useful for inspection or exporting results. ```python df = report.show_data() # page query clicks impressions ctr position # https://example.com/blog/post-1 seo tips 45 1200 3.75 4.2 # https://example.com/blog/post-2 python seo 12 340 3.53 6.1 ``` -------------------------------- ### Get CTR Yield Curve Source: https://github.com/antoineeripret/gsc_wrapper/blob/master/README-METHODS.md Generate a CTR yield curve report. Requires 'query' or 'date' dimensions and 'clicks', 'impressions', or 'position' metrics. Useful for analyzing CTR performance across different positions. ```python ( report .ctr_yield_curve() ) ``` -------------------------------- ### Get Response Codes for Pages Source: https://github.com/antoineeripret/gsc_wrapper/blob/master/README-METHODS.md Retrieves HTTP response codes for pages listed in the report. Use with caution on large datasets as it's not optimized for large-scale crawling. Includes an optional wait time parameter to avoid rate limiting. ```python (report.get_response_codes( wait_time=0 )) ``` -------------------------------- ### Initialize GSC Wrapper and Select Web Property Source: https://github.com/antoineeripret/gsc_wrapper/blob/master/README-API.md Authenticate with Google Search Console using a client secret file and select a specific web property for further operations. ```python import gscwrapper #authentificate account = gscwrapper.generate_auth( 'config/client_secret_mvp.json', serialize='config/credentials.json' ) #we choose the website we want webproperty = account['https://www.exemple.com/'] #we create the sitemap obkect sitemap = (webproperty.sitemap) ``` -------------------------------- ### Authenticate and Initialize GSC Wrapper Source: https://github.com/antoineeripret/gsc_wrapper/blob/master/README-API.md Authenticates with Google Search Console using a client secret file and serializes credentials. Choose the desired website from the authenticated account. ```python import gscwrapper #authentificate account = gscwrapper.generate_auth( 'config/client_secret_mvp.json', serialize='config/credentials.json' ) #we choose the website we want webproperty = account['https://www.exemple.com/'] #we create the sitemap obkect inspect = (webproperty.inspect) ``` -------------------------------- ### report.get_response_codes() Source: https://context7.com/antoineeripret/gsc_wrapper/llms.txt Fetches the HTTP status codes for pages listed in the report. This method iterates through unique page URLs and uses the `requests` library to get their response codes, appending a 'response_code' column to the report. Requires the 'page' dimension. ```APIDOC ## report.get_response_codes() ### Description Fetches HTTP status codes for report pages. Iterates over unique page URLs and returns their HTTP response codes using the `requests` library. Appends a `response_code` column to the report. Requires the `page` dimension. ### Parameters - **wait_time** (float) - Optional - The time in seconds to wait between requests to avoid overwhelming the server (default is 0.5s). ### Request Example ```python report = ( webproperty.query .range(start='2024-01-01', stop='2024-03-31') .dimensions(['page']) .get() ) with_codes = report.get_response_codes(wait_time=0.5) # 0.5s between requests ``` ### Response #### Success Response - **with_codes** (Report object) - The report object with an added 'response_code' column. ### Response Example ``` # page clicks response_code # https://example.com/blog/post-1 45 200 # https://example.com/old-page 2 301 # https://example.com/deleted 0 404 ``` ``` -------------------------------- ### List Webproperties Source: https://github.com/antoineeripret/gsc_wrapper/blob/master/README-API.md Lists all webproperties linked to the authenticated account along with their permission levels. Requires prior authentication. ```python account.list_webproperties() ``` -------------------------------- ### Compare Branded vs. Non-Branded Traffic with brand_vs_no_brand() Source: https://context7.com/antoineeripret/gsc_wrapper/llms.txt Compares branded vs. non-branded traffic over time by splitting clicks and impressions into groups daily. Requires `query` and `date` dimensions. Use `brand_variants` to specify terms considered branded. ```python report = ( webproperty.query .range(start='2024-01-01', stop='2024-01-31') .dimensions(['query', 'date']) .get() ) bvnb = report.brand_vs_no_brand(brand_variants=['acme', 'acme corp']) print(bvnb) # date clicks_brand impressions_brand clicks_no_brand impressions_no_brand # 2024-01-01 0.0 4.0 60 4917 # 2024-01-02 1.0 10.0 84 6648 ``` -------------------------------- ### List and Select Web Properties with account.list_webproperties() Source: https://context7.com/antoineeripret/gsc_wrapper/llms.txt Retrieves a Pandas DataFrame of all accessible GSC web properties. Supports filtering by permission level or property type, and allows selection by URL or index. ```python # List all properties df = account.list_webproperties() # siteUrl permissionLevel # https://www.example.com/ siteOwner # sc-domain:example.com siteOwner # Filter to owned properties only owned = account.list_webproperties(permissionLevel='siteOwner') # Filter to domain properties only domain_props = account.list_webproperties(is_domain_property=True) # Select a web property by URL or integer index webproperty = account['https://www.example.com/'] webproperty = account[0] ``` -------------------------------- ### Querying Search Analytics Data Source: https://github.com/antoineeripret/gsc_wrapper/blob/master/README-API.md This section covers how to query data from Google Search Console's Search Analytics. You can filter data by date range, dimensions, specific filters, search type, and limit the number of results. The `get()` method is used to retrieve the report. ```APIDOC ## Querying Search Analytics ### Description Query data from search analytics by filtering based on date range, dimensions, filters, search type, and result limits. ### Method Signature ```python webproperty.query.range(start: str, stop: str).dimensions(list[str]).filter(dimension: str, value: str, operator: str).search_type(str).limit(int).get() ``` ### Parameters #### `range` (Method) - **start** (str) - Required - The start date for the query in YYYY-MM-DD format. - **stop** (str) - Required - The end date for the query in YYYY-MM-DD format. #### `dimensions` (Method) - **dimensions** (list[str]) - Required - A list of dimensions to include in the report. At least one dimension must be specified. - Supported dimensions: `date`, `hour`, `query`, `page`, `country`, `device`, `searchAppearance`. #### `filter` (Method) - **dimension** (str) - Required - The dimension to filter on. - **value** (str) - Required - The value to filter by. - **operator** (str) - Required - The operator to use for filtering. Supported operators: `equals`, `notEquals`, `contains`, `notContains`, `includingRegex`, `excludingRegex`. #### `search_type` (Method) - **type** (str) - Optional - The type of search to query. Defaults to 'web'. Other options are available. #### `limit` (Method) - **limit** (int) - Optional - The maximum number of results to retrieve. #### `data_state` (Method) - **state** (str) - Optional - The state of the data to retrieve. Options: `all` (fresh data), `final` (default, finalized data), `hourly_all` (hourly breakdown, including partial data). ### Request Example ```python report = ( webproperty .query .range(start="2023-01-01", stop="2023-02-01") .dimensions(["date"]) .filter("page", "blog", "contains") .search_type('discover') .limit(50) .get() ) ``` ### Response - Returns a `Report` object containing the queried data. ``` -------------------------------- ### Initialize URL Inspection Source: https://github.com/antoineeripret/gsc_wrapper/blob/master/README-API.md Initializes the Inspect object by authenticating and selecting a web property. This is the first step before adding URLs for inspection. ```APIDOC ## Initialize URL Inspection ### Description Initializes the Inspect object by authenticating and selecting a web property. This is the first step before adding URLs for inspection. ### Method ```python import gscwrapper # Authenticate account = gscwrapper.generate_auth( 'config/client_secret_mvp.json', serialize='config/credentials.json' ) # Select the website webproperty = account['https://www.exemple.com/'] # Create the inspect object inspect = webproperty.inspect ``` ``` -------------------------------- ### Build and Execute Search Analytics Queries Source: https://context7.com/antoineeripret/gsc_wrapper/llms.txt Uses a fluent builder to construct Google Search Console Search Analytics API requests. Supports chaining methods for date ranges, dimensions, filters, search types, data states, and limits before fetching data. ```python import gscwrapper account = gscwrapper.generate_auth( 'config/client_secret.json', credentials='config/credentials.json' ) webproperty = account['https://www.example.com/'] # Basic query: clicks and impressions by page for January 2024 report = ( webproperty .query .range(start='2024-01-01', stop='2024-01-31') .dimensions(['page', 'query']) .get() ) # With a dimension filter (page contains "blog") and search type report = ( webproperty .query .range(start='2024-01-01', stop='2024-01-31') .dimensions(['page', 'date']) .filter('page', 'blog', 'contains') .filter('device', 'MOBILE', 'equals') .search_type('web') # web | image | video | discover | googleNews | news .data_state('all') # all | final (default) | hourly_all .limit(500) # cap results; default fetches all available rows .get() ) # Load a Report from an existing DataFrame (no API call) import pandas as pd df = pd.read_csv('gsc_export.csv') report = gscwrapper.query.from_dataframe(df, webproperty) print(report) #