Demandbase Python SDK Overview

Use the Demandbase Python SDK to access Demandbase APIs through a typed Python client and Pydantic models. The SDK supports B2B search, data import, data export, and related API workflows.


What You Can Do with the Demandbase Python SDK

  • Build Python integrations that connect to Demandbase services.

  • Search for companies and contacts and perform bulk matching.

  • Create and monitor export jobs.

  • Submit data import jobs.

  • Use typed request and response models instead of raw dictionaries.

  • Use administrative APIs when they become available.


Prerequisites for Using the Demandbase Python SDK

Before you install and initialize the SDK, make sure you have the required Python runtime and Demandbase API credentials.

  • Python >=3.8
  • Demandbase client ID with API access.
  • Demandbase client secret with API access.

Install the Demandbase Python SDK

Install the SDK from PyPI
pip install demandbase-sdk
Configure Demandbase API Credentials

Set the following environment variables before your application creates a Demandbase client:

  • DEMANDBASE_CLIENT_ID (required)
  • DEMANDBASE_CLIENT_SECRET (required)

Security best practices for Demandbase SDK Credentials:

  • Do not commit DEMANDBASE_CLIENT_SECRET to source control.
  • Store credentials in environment variables or a secret manager.

Initialize the Demandbase Python SDK Client

Create a DBClient instance to call Demandbase APIs. The following example lists B2B subscriptions and catches Demandbase API errors.

Example API Call to List Subscriptions
import demandbase

# Export credentials in your environment first
# export DEMANDBASE_CLIENT_ID=YOUR_ID
# export DEMANDBASE_CLIENT_SECRET=YOUR_SECRET

with demandbase.DBClient(timeout=60.0, retry_count=2) as client:
    try:
        # Example: list subscriptions (B2B API)
        subs = client.b2b_api.list_subscriptions(page=1, per_page=10)
        print(subs)
    except demandbase.DemandBaseAPIError as error:
        print(f"Demandbase API error: {error.http_status_code} - {error.error_message}")

The SDK returns a Pydantic SubscriptionList model, instead of a raw dict. Access model fields directly or serialize the model when you need JSON:

print(subs.subscriptions)
print(subs.model_dump())
Example Serialized Response
{
    "subscriptions": [
        {
            "subscriptionId": "SUBSCRIPTION_ID",
            "name": "Example subscription",
            "description": "Example subscription description",
            "subscriptionType": "company",
            "frequency": "daily",
            "fields": ["companyId", "name"],
            "createdAt": "2026-01-01T00:00:00Z",
            "nextFireTime": "2026-01-02T00:00:00Z"
        }
    ]
}

Authenticate and Configure the Demandbase Python SDK

The SDK uses the OAuth 2.0 client credentials flow. It reads credentials fromDEMANDBASE_CLIENT_ID and DEMANDBASE_CLIENT_SECRET environment variables.

Configure Request Timeouts and Retries

Use DBClient(timeout=..., retry_count=...) to configure the request timeout in seconds and the number of retry attempts.

Configure Logging for the Demandbase Python SDK

SDK logging is disabled by default except for warnings and errors emitted through your application's logging configuration. Enable SDK logging when troubleshooting requests, retries, authentication, or response handling.

Enable Default SDK Logging

Enable warning-level SDK logs:

import demandbase

demandbase.enable_logging()
Set the SDK Log Level

Set a specific log level in code:

import demandbase

demandbase.enable_logging("INFO")

Supported log levels are DEBUG, INFO, WARNING, and ERROR.

Send SDK Logs to a Different Destination

By default, SDK logs are written to standard error (stderr). Pass a stream to send logs to another destination.

Write SDK logs to standard output:

import sys
import demandbase

demandbase.enable_logging("INFO", stream=sys.stdout)

Write SDK logs to a file:

import demandbase

log_file = open("demandbase-sdk.log", "a", encoding="utf-8")
demandbase.enable_logging("DEBUG", stream=log_file)
Configure the SDK Log Level with an Environment Variable

Set the log level before your application starts:

export DEMANDBASE_LOG_LEVEL=INFO

Configure logging once near application startup so the SDK uses the intended level and destination. UseDEBUGonly for troubleshooting because it can generate verbose request diagnostics. Authorization tokens are redacted from SDK log output.

Common Workflows with the Demandbase Python SDK

Initialize the Demandbase Python SDK

Use with demandbase.DBClient() as client or instantiate and call close().

Make an API Request with the Demandbase Python SDK

Call resource methods such as client.b2b_api.search_companies(...) with Pydantic request models.

Handle API Errors

Catch DemandBaseAPIError when an API request fails.

See Demandbase Python SDK Common Errors, Troubleshooting, and FAQs for error classes, handling patterns, and retry guidance.

Submit Bulk CSV Imports

Use client.data_import_api.submit_import_data(...) with CSV data as a pandas.DataFrame, raw bytes, or a local file path string. When you provide a path string, the SDK opens and reads the file.

Manage Pagination, Rate Limits, and Retries

Paginate List Responses

List methods commonly accept a page number and a value that controls how many results are returned per page.

Understand Automatic Retries

If a request receives a 401 because the access token is invalid or expired, DBClient refreshes the token and retries the request. The client also retries 429 and 5xx responses up to retry_count with exponential backoff. The initial delay is 30 seconds and doubles up to 600 seconds.

Handle API Rate Limits

If retries are exhausted after a rate-limit response, the SDK raises DemandBaseAPIError. Check the error status and response headers to decide when to retry the request.


Next Steps for the Demandbase Python SDK

Use the following articles for detailed implementation and troubleshooting guidance:


Did this page help you?