Skip to main content

Python SDK

The official Python SDK for the Generator Labs API v4.0. Includes full type hints with mypy strict mode support.

Packagegeneratorlabs (PyPI)
Minimum versionPython 3.8+
HTTP clientrequests
GitHubgenerator-labs/python-sdk

Installation

pip install generatorlabs

Usage

import generatorlabs

client = generatorlabs.Client("your_account_sid", "your_auth_token")

# Get a single host
host = client.rbl.hosts.get("host_id")

# List all hosts with automatic pagination
hosts = client.rbl.hosts.get_all()

# Create a certificate monitor
monitor = client.cert.monitors.create({
"name": "example.com",
})

# Responses support dict-like access
print(host["data"]["name"])

Configuration

config = generatorlabs.Config(
timeout=45,
max_retries=5,
retry_backoff=2.0,
)

client = generatorlabs.Client("your_account_sid", "your_auth_token", config)
OptionDefaultDescription
timeout30Total request timeout in seconds
connect_timeout5TCP connection timeout in seconds
max_retries3Maximum number of retry attempts
retry_backoff1.0Backoff multiplier between retries
base_urlOverride the default API base URL

Webhook Verification

from generatorlabs import Webhook

Webhook.verify(body, signature_header, secret, tolerance)

See Using Web Hooks for more details on webhook payloads and signature verification.

Error Handling

The Python SDK raises generatorlabs.Exception errors that you can catch with standard try / except:

import generatorlabs

try:
host = client.rbl.hosts.get("host_id")
except generatorlabs.Exception as e:
print(e)

Rate Limit Information

Rate limit details are available on every response:

print(response.rate_limit_info.remaining)
print(response.rate_limit_info.reset)

See What Are the API Rate Limits? for more information.