### Serve MkDocs Documentation Locally (Bash) Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/README.md Starts a local development server to preview the MkDocs documentation. This command allows for live reloading as changes are made to the documentation source files. ```bash mkdocs serve ``` -------------------------------- ### Install IndexNow Python Package Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/getting-started/index.md Installs the 'index-now-for-python' package using pip. This is the first step to using the IndexNow API with Python. ```shell pip install index-now-for-python ``` -------------------------------- ### Install MkDocs Dependencies (Bash) Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/README.md Installs project documentation dependencies using uv, a fast Python package installer and resolver. This command is typically run from the project root after setting up a virtual environment. ```bash uv sync --frozen --group docs ``` -------------------------------- ### Install IndexNow for Python using PyPI Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/getting-started/installation.md Installs the IndexNow Python package using pip, the Python Package Installer. This command fetches and installs the latest version of the package from the Python Package Index (PyPI). It's recommended to keep the package updated using the upgrade command. ```shell pip install index-now-for-python ``` ```shell pip install --upgrade index-now-for-python ``` -------------------------------- ### Example Sitemap XML Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/reference/sitemap-filter/sitemap-filter.md A sample sitemap.xml file demonstrating different URL properties like last modified date, change frequency, and priority. This serves as input for the filtering examples. ```xml https://example.com 2025-01-01 always 1.0 https://example.com/page1 2025-02-01 hourly 0.8 https://example.com/page2 2025-03-01 daily 0.5 ``` -------------------------------- ### Submit URL to IndexNow API with Python Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/getting-started/index.md Submits a URL to the IndexNow API using the 'index-now-for-python' library. Requires authentication details including host, API key, and API key location. ```python from index_now import submit_url_to_index_now, IndexNowAuthentication authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4", api_key_location="https://example.com/a1b2c3d4.txt", ) submit_url_to_index_now(authentication, "https://example.com/page1") ``` -------------------------------- ### Build MkDocs Documentation (Bash) Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/README.md Builds the static site for MkDocs documentation. The --strict flag enforces stricter checks, and --verbose provides more detailed output during the build process. ```bash mkdocs build ``` ```bash mkdocs build --strict --verbose ``` -------------------------------- ### Install IndexNow for Python using Homebrew Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/getting-started/installation.md Installs the IndexNow Python package using Homebrew, a package manager for macOS and Linux. This involves tapping the custom repository and then installing the package. Similar to PyPI, updates are managed with the same commands. ```shell brew tap jakob-bagterp/index-now-for-python brew install index-now-for-python ``` -------------------------------- ### Example Sitemap Index XML Structure Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/how-to-submit/sitemap.md An example XML structure for a sitemap index file. This file lists other sitemaps, allowing for hierarchical organization of sitemaps. IndexNow for Python can process such index files to include URLs from all linked sitemaps. ```xml https://example.com/sitemap1.xml https://example.com/sitemap2.xml ``` -------------------------------- ### Run MkDocs Commands in Virtual Environment (Bash) Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/README.md Executes MkDocs build or serve commands within an activated virtual environment using 'uv run'. This is a troubleshooting step for potential dependency issues. ```bash uv run mkdocs build ``` ```bash uv run mkdocs serve ``` -------------------------------- ### Run All Tests with Pytest Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/test/README.md Executes all unit tests within the project using the pytest framework. Ensure pytest is installed before running this command. ```shell pytest ``` -------------------------------- ### Custom GitHub Actions Workflow for Sitemap Submission (YAML) Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/github-actions/automated-workflows.md This YAML defines a custom GitHub Actions workflow that triggers on push or pull request events to the 'master' branch. It checks out the repository, sets up Python, installs the 'index-now-for-python' library, and then executes a Python script to submit a sitemap to IndexNow. ```yaml name: Submit sitemap to IndexNow on: pull_request: branches: - master push: branches: - master jobs: submit-sitemap: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v5 - name: Set up Python uses: actions/setup-python@v6 with: python-version: "3.14" - name: Install dependencies run: pip install index-now-for-python - name: Submit sitemap to IndexNow uses: jannekem/run-python-script-action@v1 with: script: | from index_now import submit_sitemap_to_index_now, IndexNowAuthentication, SearchEngineEndpoint authentication = IndexNowAuthentication( host="example.com", api_key="${{ secrets.INDEX_NOW_API_KEY }}", api_key_location="https://example.com/${{ secrets.INDEX_NOW_API_KEY }}.txt", ) submit_sitemap_to_index_now(authentication, "https://example.com/sitemap.xml", endpoint=SearchEngineEndpoint.YANDEX) ``` -------------------------------- ### Generate API Key for IndexNow in Python Source: https://context7.com/jakob-bagterp/index-now-for-python/llms.txt Shows how to generate a random hexadecimal API key for IndexNow using the `generate_api_key` function. It supports default 32-character keys and custom lengths, and includes an example of saving the key to a file. ```python from index_now import generate_api_key # Generate default 32-character API key api_key = generate_api_key() print(f"Default key: {api_key}") # Output: Default key: 5017988d51af458491d21ecab6ed1811 # Generate custom length keys short_key = generate_api_key(length=8) long_key = generate_api_key(length=64) print(f"8-char key: {short_key}") print(f"64-char key: {long_key}") # Save the key to a text file for hosting on your website with open(f"{api_key}.txt", "w") as f: f.write(api_key) ``` -------------------------------- ### IndexNow DateRange Filtering Examples Source: https://context7.com/jakob-bagterp/index-now-for-python/llms.txt Illustrates various ways to filter sitemap URLs using DateRange classes provided by the IndexNow library. These filters allow for precise selection of URLs based on their last modification dates, such as today, yesterday, specific days, or custom ranges. ```python from datetime import datetime from index_now import ( DateRange, Between, Today, Yesterday, Day, DaysAgo, LaterThan, LaterThanAndIncluding, EarlierThan, EarlierThanAndIncluding, SitemapFilter ) # Today and Yesterday today_filter = SitemapFilter(date_range=Today()) yesterday_filter = SitemapFilter(date_range=Yesterday()) # Specific day new_year = SitemapFilter(date_range=Day(datetime(2025, 1, 1))) # Last N days (inclusive of today) last_week = SitemapFilter(date_range=DaysAgo(7)) last_month = SitemapFilter(date_range=DaysAgo(30)) # Custom date range (inclusive of start and end) q1_2025 = SitemapFilter(date_range=DateRange( start=datetime(2025, 1, 1), end=datetime(2025, 3, 31) )) # Between dates (exclusive of start and end) february_only = SitemapFilter(date_range=Between( start=datetime(2025, 1, 31), end=datetime(2025, 3, 1) )) # After a specific date after_launch = SitemapFilter(date_range=LaterThan(datetime(2025, 6, 1))) launch_or_after = SitemapFilter(date_range=LaterThanAndIncluding(datetime(2025, 6, 1))) # Before a specific date before_migration = SitemapFilter(date_range=EarlierThan(datetime(2024, 1, 1))) migration_or_before = SitemapFilter(date_range=EarlierThanAndIncluding(datetime(2024, 1, 1))) ``` -------------------------------- ### Generate Default Length API Key with Python Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/tips-and-tricks/generate-api-keys.md Generates a random 32-character hexadecimal API key using the `generate_api_key()` method from the `index_now` library. This is a basic usage example for beginners. ```python from index_now import generate_api_key api_key = generate_api_key() print(api_key) ``` -------------------------------- ### Create API Key File for IndexNow Authentication Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/search-engines/authentication.md Demonstrates how to create a text file containing your IndexNow API key. This file needs to be hosted on your website at a specified location, which is then referenced during API requests for domain verification. ```text a1b2c3d4 ``` -------------------------------- ### Initialize IndexNow Authentication in Python Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/search-engines/authentication.md Shows how to initialize the `IndexNowAuthentication` class in Python with your domain host, API key, and the URL to your API key file. This object is then used for authenticating subsequent IndexNow API calls. ```python from index_now import IndexNowAuthentication authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4", api_key_location="https://example.com/a1b2c3d4.txt", ) ``` -------------------------------- ### Trigger Workflow on GitHub Pages Deployment (YAML) Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/github-actions/automated-workflows.md This YAML configuration sets up a GitHub Actions workflow to run after the 'pages-build-deployment' workflow is completed. This ensures that the sitemap is submitted only after the GitHub Pages site has been successfully built and deployed. ```yaml on: workflow_run: workflows: [pages-build-deployment] types: [completed] ``` -------------------------------- ### SitemapFilter Configuration Source: https://context7.com/jakob-bagterp/index-now-for-python/llms.txt A configuration class for filtering sitemap URLs based on text patterns, change frequency, date ranges, and pagination. All filter parameters are optional and can be combined for precise URL selection. ```APIDOC ## SitemapFilter ### Description A configuration class for filtering sitemap URLs based on text patterns, change frequency, date ranges, and pagination. All filter parameters are optional and can be combined for precise URL selection. ### Method N/A (Class definition) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **contains** (string) - Optional - Filter URLs that contain the specified text pattern (regex supported). - **excludes** (string) - Optional - Filter URLs that exclude the specified text pattern (regex supported). - **change_frequency** (ChangeFrequency or string) - Optional - Filter URLs based on their change frequency (e.g., 'daily', 'weekly'). - **date_range** (DateRange object) - Optional - Filter URLs based on their last modification date. - **skip** (int) - Optional - Number of URLs to skip from the beginning. - **take** (int) - Optional - Maximum number of URLs to process. ### Request Example ```python from datetime import datetime from index_now import ( SitemapFilter, ChangeFrequency, DateRange, DaysAgo, Today, Yesterday, LaterThan, EarlierThan, Between ) # Filter by URL pattern (supports regex) filter_blog = SitemapFilter(contains="blog") filter_sections = SitemapFilter(contains=r"(section1)|(section2)") # Exclude URLs matching a pattern filter_exclude = SitemapFilter(excludes="draft|test|preview") # Filter by change frequency filter_daily = SitemapFilter(change_frequency=ChangeFrequency.DAILY) filter_weekly = SitemapFilter(change_frequency="weekly") # String also works # Filter by date range filter_today = SitemapFilter(date_range=Today()) filter_yesterday = SitemapFilter(date_range=Yesterday()) filter_recent = SitemapFilter(date_range=DaysAgo(7)) filter_after_date = SitemapFilter(date_range=LaterThan(datetime(2025, 1, 1))) filter_before_date = SitemapFilter(date_range=EarlierThan(datetime(2024, 12, 31))) filter_january = SitemapFilter(date_range=DateRange( start=datetime(2025, 1, 1), end=datetime(2025, 1, 31) )) # Pagination: skip and take filter_paginated = SitemapFilter(skip=100, take=50) # Combine multiple filters advanced_filter = SitemapFilter( date_range=DaysAgo(30), contains="products", excludes="out-of-stock", change_frequency=ChangeFrequency.DAILY, skip=0, take=200 ) ``` ### Response #### Success Response (200) N/A (This is a configuration class, not an endpoint) #### Response Example N/A ``` -------------------------------- ### Configure Sitemap Filtering (Python) Source: https://context7.com/jakob-bagterp/index-now-for-python/llms.txt Defines how to use the SitemapFilter class to specify criteria for selecting URLs from sitemaps. Supports pattern matching, date ranges, change frequency, and pagination. ```python from datetime import datetime from index_now import ( SitemapFilter, ChangeFrequency, DateRange, DaysAgo, Today, Yesterday, LaterThan, EarlierThan, Between ) # Filter by URL pattern (supports regex) filter_blog = SitemapFilter(contains="blog") filter_sections = SitemapFilter(contains=r"(section1)|(section2)") # Exclude URLs matching a pattern filter_exclude = SitemapFilter(excludes="draft|test|preview") # Filter by change frequency filter_daily = SitemapFilter(change_frequency=ChangeFrequency.DAILY) filter_weekly = SitemapFilter(change_frequency="weekly") # String also works # Filter by date range filter_today = SitemapFilter(date_range=Today()) filter_yesterday = SitemapFilter(date_range=Yesterday()) filter_recent = SitemapFilter(date_range=DaysAgo(7)) filter_after_date = SitemapFilter(date_range=LaterThan(datetime(2025, 1, 1))) filter_before_date = SitemapFilter(date_range=EarlierThan(datetime(2024, 12, 31))) filter_january = SitemapFilter(date_range=DateRange( start=datetime(2025, 1, 1), end=datetime(2025, 1, 31) )) # Pagination: skip and take filter_paginated = SitemapFilter(skip=100, take=50) # Combine multiple filters advanced_filter = SitemapFilter( date_range=DaysAgo(30), contains="products", excludes="out-of-stock", change_frequency=ChangeFrequency.DAILY, skip=0, take=200 ) ``` -------------------------------- ### Submit Multiple URLs and Sitemap with IndexNow Authentication (Python) Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/search-engines/authentication.md Demonstrates how to use the same `IndexNowAuthentication` object to submit multiple URLs at once or an entire sitemap to the IndexNow API. This highlights the reusability of authentication credentials across different submission methods. ```python from index_now import submit_url_to_index_now, submit_urls_to_index_now, submit_sitemap_to_index_now, IndexNowAuthentication authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4", api_key_location="https://example.com/a1b2c3d4.txt", ) urls = ["https://example.com/page1", "https://example.com/page2", "https://example.com/page3"] submit_url_to_index_now(authentication, urls[0]) submit_urls_to_index_now(authentication, urls) submit_sitemap_to_index_now(authentication, "https://example.com/sitemap.xml") ``` -------------------------------- ### Generate Custom Length API Keys with Python Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/tips-and-tricks/generate-api-keys.md Demonstrates how to generate API keys of specified lengths (e.g., 16 and 64 characters) using the `generate_api_key()` method by adjusting the `length` parameter. This caters to advanced usage scenarios. ```python from index_now import generate_api_key api_key_16 = generate_api_key(length=16) api_key_64 = generate_api_key(length=64) print(api_key_16) print(api_key_64) ``` -------------------------------- ### Submit Sitemap with Daily Change Frequency Filter (Python) Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/reference/sitemap-filter/change-frequency.md Demonstrates how to use the IndexNow Python library to submit a sitemap, filtering URLs with a 'daily' change frequency. It initializes authentication and a SitemapFilter with ChangeFrequency.DAILY. ```python from index_now import submit_sitemap_to_index_now, IndexNowAuthentication, SitemapFilter, ChangeFrequency authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4", api_key_location="https://example.com/a1b2c3d4.txt", ) filter = SitemapFilter(change_frequency=ChangeFrequency.DAILY) submit_sitemap_to_index_now( authentication, "https://example.com/sitemap.xml", filter) ``` -------------------------------- ### Trigger Workflow on Deployment Completion (YAML) Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/github-actions/automated-workflows.md This YAML snippet configures a GitHub Actions workflow to trigger after another workflow named 'My Deployment Workflow' completes successfully on the 'master' branch. It's useful for ensuring sitemap submission only after a site is deployed. ```yaml on: workflow_run: workflows: ["My Deployment Workflow"] branches: [master] types: [completed] ``` -------------------------------- ### Submit URLs to IndexNow Endpoints (Python) Source: https://context7.com/jakob-bagterp/index-now-for-python/llms.txt Demonstrates how to submit a single URL to different search engine endpoints using the IndexNow API. Requires an authentication object and the URL to be submitted. ```python from index_now import SearchEngineEndpoint # Assuming 'authentication' and 'submit_url_to_index_now' are defined elsewhere endpoints = [ SearchEngineEndpoint.INDEXNOW, # https://api.indexnow.org/indexnow (default) SearchEngineEndpoint.BING, # https://www.bing.com/indexnow SearchEngineEndpoint.YANDEX, # https://yandex.com/indexnow SearchEngineEndpoint.NAVER, # https://searchadvisor.naver.com/indexnow SearchEngineEndpoint.SEZNAM, # https://search.seznam.cz/indexnow SearchEngineEndpoint.YEP, # https://indexnow.yep.com/indexnow ] # Submit to all search engines url = "https://example.com/important-update" for endpoint in endpoints: print(f"Submitting to {endpoint.name}...") submit_url_to_index_now(authentication, url, endpoint) ``` -------------------------------- ### Filter Sitemap URLs with Python Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/reference/sitemap-filter/sitemap-filter.md Python code demonstrating how to use `SitemapFilter` to submit URLs within a specific date range and exclude URLs containing certain keywords. It requires the `index_now` library and `datetime`. ```python from index_now import DateRange, SitemapFilter, submit_sitemap_to_index_now, IndexNowAuthentication from datetime import datetime year_2025 = DateRange( start=datetime(2025, 1, 1), end=datetime(2025, 12, 31), ) filter = SitemapFilter(date_range=year_2025, excludes="page") authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4", api_key_location="https://example.com/a1b2c3d4.txt", ) submit_sitemap_to_index_now( authentication, "https://example.com/sitemap.xml", filter) ``` -------------------------------- ### SearchEngineEndpoint Enum for IndexNow in Python Source: https://context7.com/jakob-bagterp/index-now-for-python/llms.txt Illustrates the use of the `SearchEngineEndpoint` enumeration to specify target search engines for IndexNow submissions. It shows how to import and use these predefined endpoints. ```python from index_now import submit_url_to_index_now, IndexNowAuthentication, SearchEngineEndpoint authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4e5f6g7h8", api_key_location="https://example.com/a1b2c3d4e5f6g7h8.txt", ) # Example usage within a submission function (as shown in other snippets) # submit_url_to_index_now(authentication, "https://example.com/page", endpoint=SearchEngineEndpoint.BING) ``` -------------------------------- ### Configure GitHub Actions Workflow for IndexNow Sitemap Submission Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/github-actions/automated-workflows.md This YAML configuration sets up a GitHub Actions workflow to automatically submit sitemap URLs to the IndexNow API. It requires an API key and sitemap location, and can be scheduled to run at specific intervals. ```yaml name: Submit Sitemap to IndexNow on: schedule: - cron: 0 0 1 * * # Run at midnight UTC on the 1st day of each month. jobs: submit-sitemap: runs-on: ubuntu-latest steps: - name: Submit sitemap URLs to IndexNow uses: jakob-bagterp/index-now-submit-sitemap-urls-action@v1 with: host: example.com api_key: ${{ secrets.INDEX_NOW_API_KEY }} api_key_location: https://example.com/${{ secrets.INDEX_NOW_API_KEY }}.txt endpoint: yandex sitemap_locations: https://example.com/sitemap.xml ``` -------------------------------- ### Configure GitHub Actions for Daily IndexNow Submission of Latest Changes Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/github-actions/automated-workflows.md This YAML configuration sets up a daily GitHub Actions workflow to submit only the latest updated URLs from a sitemap to the IndexNow API. The `sitemap_days_ago` parameter is used to specify how many days back to check for modifications. ```yaml name: Submit Sitemap to IndexNow on: schedule: - cron: 0 0 * * * # Run daily at midnight UTC. jobs: submit-sitemap: runs-on: ubuntu-latest steps: - name: Submit sitemap URLs to IndexNow uses: jakob-bagterp/index-now-submit-sitemap-urls-action@v1 with: host: example.com api_key: ${{ secrets.INDEX_NOW_API_KEY }} api_key_location: https://example.com/${{ secrets.INDEX_NOW_API_KEY }}.txt endpoint: yandex sitemap_locations: https://example.com/sitemap.xml sitemap_days_ago: 1 ``` -------------------------------- ### Submit Single URL to IndexNow API in Python Source: https://context7.com/jakob-bagterp/index-now-for-python/llms.txt Demonstrates submitting a single URL to the IndexNow API using `submit_url_to_index_now`. It covers submitting to the default endpoint, specific search engines like Bing, and custom endpoints. ```python from index_now import submit_url_to_index_now, IndexNowAuthentication, SearchEngineEndpoint authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4e5f6g7h8", api_key_location="https://example.com/a1b2c3d4e5f6g7h8.txt", ) # Submit to default IndexNow endpoint status_code = submit_url_to_index_now( authentication, "https://example.com/new-blog-post" ) # Output: 1 URL was submitted successfully to this IndexNow API endpoint: ... # Status code: 200 OK # Submit to specific search engines submit_url_to_index_now( authentication, "https://example.com/updated-page", endpoint=SearchEngineEndpoint.BING ) # Submit to custom endpoint submit_url_to_index_now( authentication, "https://example.com/page", endpoint="https://custom-search.example.com/indexnow" ) ``` -------------------------------- ### Reuse IndexNow Authentication Credentials Across Files (Python) Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/search-engines/authentication.md Illustrates a best practice for managing IndexNow API authentication by creating a separate Python file to define the `IndexNowAuthentication` object. This object can then be imported and reused in other scripts for submitting URLs or sitemaps, avoiding repetitive credential entry. ```python from index_now import IndexNowAuthentication my_authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4", api_key_location="https://example.com/a1b2c3d4.txt", ) ``` ```python from index_now import submit_url_to_index_now from .authentication import my_authentication submit_url_to_index_now(my_authentication, "https://example.com/page1") ``` ```python from index_now import submit_sitemap_to_index_now from .authentication import my_authentication submit_sitemap_to_index_now(my_authentication, "https://example.com/sitemap.xml") ``` -------------------------------- ### IndexNow Change Frequencies and Sitemap Submission Source: https://context7.com/jakob-bagterp/index-now-for-python/llms.txt Demonstrates the available change frequencies for IndexNow and how to submit a sitemap with a daily update filter. This is useful for notifying search engines about the frequency of content changes on a website. ```python from index_now import ChangeFrequency, SitemapFilter, submit_sitemap_to_index_now # Available change frequencies frequencies = [ ChangeFrequency.ALWAYS, # Resources that change constantly ChangeFrequency.HOURLY, # Changes every hour ChangeFrequency.DAILY, # Changes every day ChangeFrequency.WEEKLY, # Changes every week ChangeFrequency.MONTHLY, # Changes every month ChangeFrequency.YEARLY, # Changes every year ChangeFrequency.NEVER, # Archived/static content ] # Assume 'authentication' is defined elsewhere # authentication = "YOUR_API_KEY" # Submit only daily-updated URLs # submit_sitemap_to_index_now( # authentication, # "https://example.com/sitemap.xml", # filter=SitemapFilter(change_frequency=ChangeFrequency.DAILY) # ) ``` -------------------------------- ### Submit URL with Failover Strategy to Multiple Search Engines (Python) Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/search-engines/default-endpoints.md Shows how to iterate through available search engine endpoints and submit a URL, using the status code to determine success. This implements a failover strategy to ensure URL submission. ```python from index_now import submit_url_to_index_now, IndexNowAuthentication, SearchEngineEndpoint authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4", api_key_location="https://example.com/a1b2c3d4.txt", ) for endpoint in SearchEngineEndpoint: status_code = submit_url_to_index_now(authentication, "https://example.com/page1", endpoint) if status_code in [200, 202]: print("URL was submitted successfully to IndexNow.") break ``` -------------------------------- ### IndexNowAuthentication Dataclass for Python Source: https://context7.com/jakob-bagterp/index-now-for-python/llms.txt Demonstrates how to create an IndexNowAuthentication object to store credentials for IndexNow API requests. This includes the host, API key, and the URL of the API key file. ```python from index_now import IndexNowAuthentication # Create authentication credentials authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4e5f6g7h8", api_key_location="https://example.com/a1b2c3d4e5f6g7h8.txt", ) # The authentication object is used in all submission functions print(f"Host: {authentication.host}") print(f"API Key: {authentication.api_key}") print(f"Key Location: {authentication.api_key_location}") ``` -------------------------------- ### Combine Multiple Sitemap Filtering Rules (Python) Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/how-to-submit/sitemap.md This snippet shows how to combine multiple filtering rules within a single `SitemapFilter` instance. The order of parameters in the constructor dictates the order in which filtering rules are applied. ```python from index_now import SitemapFilter, DaysAgo filter = SitemapFilter( change_frequency="daily", date_range=DaysAgo(2), contains="section1", excludes="search", skip=1, take=1 ) ``` -------------------------------- ### Filter Sitemap by Skip and Take Amount (Python) Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/how-to-submit/sitemap.md This snippet demonstrates how to limit the number of URLs processed from a sitemap using the `skip` and `take` parameters. `skip` defines how many URLs to ignore from the beginning, and `take` specifies how many to process afterward. ```python from index_now import SitemapFilter filter = SitemapFilter(skip=10, take=20) ``` -------------------------------- ### Define Change Frequency for Sitemaps (Python) Source: https://context7.com/jakob-bagterp/index-now-for-python/llms.txt Illustrates the use of the ChangeFrequency enumeration for specifying URL change frequency within sitemap filters. This helps in prioritizing submissions based on how often content is updated. ```python from index_now import SitemapFilter, ChangeFrequency, submit_sitemap_to_index_now, IndexNowAuthentication authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4e5f6g7h8", api_key_location="https://example.com/a1b2c3d4e5f6g7h8.txt", ) # Example usage with submit_sitemap_to_index_now (assuming sitemap URL and authentication are set) # submit_sitemap_to_index_now( # authentication, # "https://example.com/sitemap.xml", # filter=SitemapFilter(change_frequency=ChangeFrequency.HOURLY) # ) ``` -------------------------------- ### Submit URL to IndexNow Endpoints (Python) Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/index.md This snippet demonstrates how to submit a URL to different IndexNow endpoints, including default ones like Bing and custom ones. It requires the `index_now` library and an `IndexNowAuthentication` object. ```python from index_now import submit_url_to_index_now, IndexNowAuthentication, SearchEngineEndpoint authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4", api_key_location="https://example.com/a1b2c3d4.txt", ) endpoint_bing = SearchEngineEndpoint.BING endpoint_custom = "https://example.com/indexnow" for endpoint in [endpoint_bing, endpoint_custom]: submit_url_to_index_now(authentication, "https://example.com/page1", endpoint) ``` -------------------------------- ### Schedule GitHub Actions Workflow for Daily IndexNow Sitemap Submission Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/github-actions/automated-workflows.md This snippet defines a cron job within a GitHub Actions workflow to execute a sitemap submission to IndexNow on a daily basis. The schedule is set to run at midnight UTC every day. ```yaml - cron: 0 0 * * * ``` -------------------------------- ### Schedule GitHub Actions Workflow for Monthly IndexNow Sitemap Submission Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/github-actions/automated-workflows.md This snippet defines a cron job within a GitHub Actions workflow to execute a sitemap submission to IndexNow once a month. The schedule is set to run at midnight UTC on the first day of each month. ```yaml - cron: 0 0 1 * * ``` -------------------------------- ### Schedule GitHub Actions Workflow for Weekly IndexNow Sitemap Submission Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/github-actions/automated-workflows.md This snippet defines a cron job within a GitHub Actions workflow to execute a sitemap submission to IndexNow once a week. The schedule is set to run at midnight UTC on the first day of each week (Sunday). ```yaml - cron: 0 0 * * 0 ``` -------------------------------- ### Submit Sitemap to IndexNow API (Python) Source: https://context7.com/jakob-bagterp/index-now-for-python/llms.txt Submits all URLs from a sitemap XML file to the IndexNow API. Supports nested sitemaps up to level 2 and allows optional filtering of URLs using SitemapFilter. ```python from index_now import submit_sitemap_to_index_now, IndexNowAuthentication, SitemapFilter, DaysAgo authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4e5f6g7h8", api_key_location="https://example.com/a1b2c3d4e5f6g7h8.txt", ) # Submit entire sitemap status_code = submit_sitemap_to_index_now( authentication, "https://example.com/sitemap.xml" ) # Output: Found 150 URL(s) in total from this sitemap: ... # 150 URL(s) were submitted successfully to this IndexNow API endpoint: ... # Submit only URLs modified in the last 7 days submit_sitemap_to_index_now( authentication, "https://example.com/sitemap.xml", filter=SitemapFilter(date_range=DaysAgo(7)) ) # Submit only blog URLs, skip first 10, take next 50 submit_sitemap_to_index_now( authentication, "https://example.com/sitemap.xml", filter=SitemapFilter(contains="blog", skip=10, take=50) ) ``` -------------------------------- ### Submit Sitemap to IndexNow API Source: https://context7.com/jakob-bagterp/index-now-for-python/llms.txt Parses and submits all URLs from a sitemap XML file to the IndexNow API. Supports nested sitemaps up to level 2. Optionally filter URLs using `SitemapFilter` before submission. ```APIDOC ## submit_sitemap_to_index_now ### Description Parses and submits all URLs from a sitemap XML file to the IndexNow API. Supports nested sitemaps up to level 2. Optionally filter URLs using `SitemapFilter` before submission. ### Method POST ### Endpoint https://api.indexnow.org/indexnow (default, can be overridden) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **authentication** (IndexNowAuthentication) - Required - Authentication object containing API key and host. - **sitemap_location** (string) - Required - URL of the sitemap XML file. - **filter** (SitemapFilter) - Optional - Filter object to specify which URLs to submit. ### Request Example ```python from index_now import submit_sitemap_to_index_now, IndexNowAuthentication, SitemapFilter, DaysAgo authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4e5f6g7h8", api_key_location="https://example.com/a1b2c3d4e5f6g7h8.txt", ) # Submit entire sitemap status_code = submit_sitemap_to_index_now( authentication, "https://example.com/sitemap.xml" ) # Submit only URLs modified in the last 7 days submit_sitemap_to_index_now( authentication, "https://example.com/sitemap.xml", filter=SitemapFilter(date_range=DaysAgo(7)) ) # Submit only blog URLs, skip first 10, take next 50 submit_sitemap_to_index_now( authentication, "https://example.com/sitemap.xml", filter=SitemapFilter(contains="blog", skip=10, take=50) ) ``` ### Response #### Success Response (200) - **status_code** (int) - The HTTP status code of the submission response. #### Response Example ```json { "message": "150 URL(s) were submitted successfully to this IndexNow API endpoint: ..." } ``` ``` -------------------------------- ### Submit Single Sitemap to IndexNow API using Python Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/how-to-submit/sitemap.md Submits a single sitemap's URLs to the IndexNow API for indexing. It requires authentication details and the sitemap's URL. The library handles downloading, parsing, filtering (if applied), and submitting URLs. ```python from index_now import submit_sitemap_to_index_now, IndexNowAuthentication authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4", api_key_location="https://example.com/a1b2c3d4.txt", ) submit_sitemap_to_index_now(authentication, "https://example.com/sitemap.xml") ``` -------------------------------- ### Filter Sitemap by Change Frequency (Python) Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/how-to-submit/sitemap.md This snippet demonstrates how to filter sitemap URLs based on their change frequency using the `SitemapFilter` class. You can use predefined `ChangeFrequency` enumerations or basic string inputs. ```python from index_now import SitemapFilter, ChangeFrequency filter = SitemapFilter(change_frequency=ChangeFrequency.DAILY) ``` ```python from index_now import SitemapFilter filter = SitemapFilter(change_frequency="daily") ``` -------------------------------- ### Run Tests in Parallel with Pytest-xdist Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/test/README.md Runs unit tests in parallel using the pytest-xdist plugin. This can significantly speed up test execution on multi-core processors. The '-n auto' option utilizes all available CPU cores, while '--numprocesses' allows for manual core limitation. ```shell pytest -n auto ``` ```shell pytest -n auto -v ``` ```shell pytest --numprocesses 4 -v ``` -------------------------------- ### Submit Sitemap with Custom String Change Frequency Filter (Python) Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/reference/sitemap-filter/change-frequency.md Shows an alternative way to filter sitemap URLs by change frequency using a custom string value directly within the SitemapFilter. This is useful for non-standard or specific change frequency values. ```python filter = SitemapFilter(change_frequency="daily") ``` -------------------------------- ### Submit URL to Specific Search Engine Endpoint (Python) Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/search-engines/default-endpoints.md Demonstrates how to submit a URL to a specific search engine endpoint using the IndexNow Python library. It requires an `IndexNowAuthentication` object and the desired `SearchEngineEndpoint` enum. ```python from index_now import submit_url_to_index_now, IndexNowAuthentication, SearchEngineEndpoint authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4", api_key_location="https://example.com/a1b2c3d4.txt", ) submit_url_to_index_now(authentication, "https://example.com/page1", SearchEngineEndpoint.BING) submit_url_to_index_now(authentication, "https://example.com/page2", SearchEngineEndpoint.YANDEX) ``` -------------------------------- ### Submit Multiple URLs using Python IndexNow Library Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/how-to-submit/multiple-urls.md This snippet demonstrates how to submit a list of URLs in bulk to the IndexNow API using the `index_now` Python library. It requires the `IndexNowAuthentication` object and a list of URLs. The `submit_urls_to_index_now` function handles the API request. ```python from index_now import submit_urls_to_index_now, IndexNowAuthentication authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4", api_key_location="https://example.com/a1b2c3d4.txt", ) urls = [ "https://example.com/page1", "https://example.com/page2", "https://example.com/page3", ] submit_urls_to_index_now(authentication, urls) ``` -------------------------------- ### Submit Multiple Sitemaps to IndexNow API using Python Source: https://github.com/jakob-bagterp/index-now-for-python/blob/master/docs/user-guide/how-to-submit/sitemap.md Submits URLs from multiple sitemaps to the IndexNow API. This method takes authentication details and a list of sitemap URLs. The library processes all provided sitemaps, including nested ones, for submission. ```python from index_now import submit_sitemaps_to_index_now, IndexNowAuthentication authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4", api_key_location="https://example.com/a1b2c3d4.txt", ) sitemap_locations = [ "https://example.com/sitemap1.xml", "https://example.com/sitemap2.xml", "https://example.com/sitemap3.xml", ] submit_sitemaps_to_index_now(authentication, sitemap_locations) ``` -------------------------------- ### Submit Multiple Sitemaps to IndexNow API (Python) Source: https://context7.com/jakob-bagterp/index-now-for-python/llms.txt Submits multiple sitemaps to the IndexNow API in a single operation, merging all URLs. Supports the same filtering options as single sitemap submission. ```python from index_now import submit_sitemaps_to_index_now, IndexNowAuthentication, SitemapFilter authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4e5f6g7h8", api_key_location="https://example.com/a1b2c3d4e5f6g7h8.txt", ) # Submit multiple sitemaps sitemap_locations = [ "https://example.com/sitemap-posts.xml", "https://example.com/sitemap-pages.xml", "https://example.com/sitemap-products.xml", ] status_code = submit_sitemaps_to_index_now(authentication, sitemap_locations) # Output: Found 500 URL(s) in total from these sitemaps: ... # With filtering applied across all sitemaps submit_sitemaps_to_index_now( authentication, sitemap_locations, filter=SitemapFilter(excludes="draft", take=100) ) ``` -------------------------------- ### Submit Multiple Sitemaps to IndexNow API Source: https://context7.com/jakob-bagterp/index-now-for-python/llms.txt Submits multiple sitemaps to the IndexNow API in a single operation. All URLs from all sitemaps are merged and submitted together. Supports the same filtering options as single sitemap submission. ```APIDOC ## submit_sitemaps_to_index_now ### Description Submits multiple sitemaps to the IndexNow API in a single operation. All URLs from all sitemaps are merged and submitted together. Supports the same filtering options as single sitemap submission. ### Method POST ### Endpoint https://api.indexnow.org/indexnow (default, can be overridden) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **authentication** (IndexNowAuthentication) - Required - Authentication object containing API key and host. - **sitemap_locations** (list of strings) - Required - A list of URLs for the sitemap XML files. - **filter** (SitemapFilter) - Optional - Filter object to specify which URLs to submit across all sitemaps. ### Request Example ```python from index_now import submit_sitemaps_to_index_now, IndexNowAuthentication, SitemapFilter authentication = IndexNowAuthentication( host="example.com", api_key="a1b2c3d4e5f6g7h8", api_key_location="https://example.com/a1b2c3d4e5f6g7h8.txt", ) # Submit multiple sitemaps sitemap_locations = [ "https://example.com/sitemap-posts.xml", "https://example.com/sitemap-pages.xml", "https://example.com/sitemap-products.xml", ] status_code = submit_sitemaps_to_index_now(authentication, sitemap_locations) # With filtering applied across all sitemaps submit_sitemaps_to_index_now( authentication, sitemap_locations, filter=SitemapFilter(excludes="draft|test", take=100) ) ``` ### Response #### Success Response (200) - **status_code** (int) - The HTTP status code of the submission response. #### Response Example ```json { "message": "500 URL(s) were submitted successfully from these sitemaps: ..." } ``` ```