Skip to main content

Bing Webmaster Tools API Client

PyPI version Python versions License CI

An async Python client library for the Bing Webmaster Tools API, providing a clean interface for managing websites, analyzing search traffic, handling content submissions, and more.

Overview

Description

The Bing Webmaster API Client is a modern, async Python library that provides a comprehensive interface to Bing Webmaster Tools API. The library is designed with a focus on developer experience, type safety, and reliability, offering structured access to all Bing Webmaster Tools features through a clean, domain-driven API.

Key Features

  • Async/await support - Built on aiohttp for efficient async operations
  • Type-safe - Full typing support with runtime validation using Pydantic
  • Domain-driven design - Operations organized into logical service groups
  • Comprehensive - Complete coverage of Bing Webmaster Tools API
  • Developer-friendly - Intuitive interface with detailed documentation
  • Reliable - Built-in retry logic, rate limiting, and error handling
  • Flexible - Support for both Pydantic models and dictionaries as input
  • Production-ready - Extensive logging, testing, and error handling

Requirements

  • Python 3.9 or higher
  • Bing Webmaster API key (follow the instructions here)

Installation

PyPI Installation

Install the package using pip:

pip install bing-webmaster-tools

Quick Start

Basic Setup

  1. Get your API key from Bing Webmaster Tools

  2. Set your API key as an environment variable:

export BING_WEBMASTER_API_KEY=your_api_key_here

Or use a .env file:

BING_WEBMASTER_API_KEY=your_api_key_here

Examples

Look under the examples subdirectory to see boilerplate scripts which can help you get started. These assume you are using the environment variable BING_WEBMASTER_API_KEY as described in the Basic Setup.

Authentication

The client supports several ways to provide authentication:

  1. Environment variables (recommended):
client = BingWebmasterClient(Settings.from_env())
  1. Direct initialization:
client = BingWebmasterClient(Settings(api_key="your_api_key_here"))
  1. Configuration file:
from dotenv import load_dotenv
load_dotenv()  # Load from .env file
client = BingWebmasterClient(Settings.from_env())

Usage

Client Initialization

The client can be initialized in several ways:

from bing_webmaster_tools import Settings, BingWebmasterClient

# Using environment variables
async with BingWebmasterClient(Settings.from_env()) as client:
    sites = await client.sites.get_sites()

# Direct initialization
settings = Settings(
    api_key="your_api_key",
    timeout=30,  # Custom timeout
    max_retries=5  # Custom retry count
)
async with BingWebmasterClient(settings) as client:
    sites = await client.sites.get_sites()

# Manual session management
client = BingWebmasterClient(Settings.from_env())
await client.init()
try:
    sites = await client.sites.get_sites()
finally:
    await client.close()

Configuration Options

The client behavior can be customized through the Settings class:

from bing_webmaster_tools import Settings

settings = Settings(
    # Required
    api_key="your_api_key",  # Also via BING_WEBMASTER_API_KEY env var

    # Optional with defaults
    base_url="https://ssl.bing.com/webmaster/api.svc/json",
    timeout=30,  # Request timeout in seconds
    max_retries=3,  # Maximum number of retry attempts
    rate_limit_calls=10,  # Number of calls allowed per period
    rate_limit_period=1,  # Rate limit period in seconds
    disable_destructive_operations=False
    # Disable destructive operations, if you want to prevent accidental deletions etc. 
)

Environment variables can be used with the BING_WEBMASTER_ prefix:

BING_WEBMASTER_API_KEY=your_api_key
BING_WEBMASTER_TIMEOUT=60
BING_WEBMASTER_MAX_RETRIES=5

Error Handling

The client provides structured error handling:

from bing_webmaster_tools.exceptions import (
    BingWebmasterError,
    AuthenticationError,
    RateLimitError
)


async def handle_api_calls():
    try:
        await client.sites.get_sites()
    except AuthenticationError:
        # Handle authentication issues
        print("Check your API key")
    except RateLimitError:
        # Handle rate limiting
        print("Too many requests")
    except BingWebmasterError as e:
        # Handle other API errors
        print(f"API error: {e.message}, Status: {e.status_code}")

Rate Limiting

The client includes built-in rate limiting:

  • Default: 5 calls per second
  • Configurable via settings
  • Automatic retry with exponential backoff on rate limit errors

To turn off rate limiting, simply set the rate limit configuration variables to None.

Services

The client provides access to different API functionalities through specialized services. For full details on available services and methods, refer to the API documentation.

Development

Development Installation

To install from source for development:

# Clone the repository
git clone https://github.com/merj/bing-webmaster-tools
cd bing-webmaster-tools

# Install poetry if you haven't already
pip install poetry

# Install dependencies and setup development environment
poetry install

Metadata

Release files for bing-webmaster-tools 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bing-webmaster-tools 1.2.0
File Size Uploaded Provenance Actions
bing_webmaster_tools-1.2.0.tar.gz 25.7 kB Without provenance Details for bing_webmaster_tools-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bing-webmaster-tools 1.2.0
File Interpreter ABI Platform Actions
bing_webmaster_tools-1.2.0-py3-none-any.whl Python 3 none any Details for bing_webmaster_tools-1.2.0-py3-none-any.whl

Total release size: 63.2 kB

Release files / bing_webmaster_tools-1.2.0.tar.gz

Download URL bing_webmaster_tools-1.2.0.tar.gz
Size 25.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0c4aa582ce5536280ae2cc80fc19e81e79af78796bf84d25a4d418b78590c5ab
BLAKE2b-256 checksum
How to use checksums
b1c7351df1478e039f88c2f34968a7f98478f1b17e82ad9617f6262150d988a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.9.22 Linux/6.11.0-1012-azure

Release files / bing_webmaster_tools-1.2.0-py3-none-any.whl

Download URL bing_webmaster_tools-1.2.0-py3-none-any.whl
Size 37.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
599a4ec439ae36c20ee6852faf26c3bef0a460ba4f9de691ebccf5d5ba8a39ac
BLAKE2b-256 checksum
How to use checksums
3e7647c6dcf1bc567c655f93b14f3f587203fe0d8e5f2c53b9a6349433294c09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.9.22 Linux/6.11.0-1012-azure

Security for bing-webmaster-tools 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page