Python SDK Python 3.7+

Build intelligent Python applications with our official Python client library

Installation

Install the WebburnsTech Python SDK using pip. Requires Python 3.7 or higher.

Terminal
pip install webburnstech
Terminal
poetry add webburnstech
Terminal
conda install -c webburnstech webburnstech
Virtual Environment Recommended

We recommend installing the SDK in a virtual environment to avoid conflicts with other packages.

python -m venv webburnstech-env
source webburnstech-env/bin/activate  # On Windows: webburnstech-env\Scripts\activate
pip install webburnstech

Quick Start

Initialize the SDK with your API key and start making requests in seconds.

Python
import webburnstech
from webburnstech import Client

# Initialize the client
client = Client(
    api_key="your-api-key-here",  # Get from https://dashboard.webburnstech.dev
    environment="production"      # or 'development' for testing
)

# Make your first API call
try:
    response = client.nlp.analyze_sentiment(
        text="WebburnsTech makes AI integration incredibly simple!",
        language="en"
    )
    
    print("Sentiment:", response.sentiment)      # 'positive'
    print("Confidence:", response.confidence)    # 0.95
    print("Emotions:", response.emotions)        # {'joy': 0.8, ...}
    
except webburnstech.APIError as e:
    print(f"API Error: {e.message}")
except Exception as e:
    print(f"Unexpected error: {e}")

API Reference

Explore the complete Python SDK API with detailed examples for each method.

Natural Language Processing

Process and understand human language with our advanced NLP models.

POST client.nlp.analyze_sentiment()

Analyze the sentiment and emotional tone of text.

Python
response = client.nlp.analyze_sentiment(
    text="I absolutely love this product! It has changed my workflow completely.",
    language="en",  # optional, auto-detected if not provided
    detailed=True   # optional, returns emotion breakdown
)

# Response object attributes:
print(response.sentiment)    # 'positive'
print(response.confidence)   # 0.92
print(response.emotions)     # Emotions object with joy, trust, etc.

# Access emotion scores:
print(response.emotions.joy)        # 0.85
print(response.emotions.trust)      # 0.78
print(response.emotions.anticipation) # 0.64

Parameters

Parameter Type Required Description
text str Yes The text to analyze for sentiment
language str No Language code (e.g., 'en', 'es', 'fr'). Auto-detected if not provided.
detailed bool No Whether to return detailed emotion analysis
POST client.nlp.extract_entities()

Extract named entities (people, organizations, locations) from text.

Python
response = client.nlp.extract_entities(
    text="Apple Inc. was founded by Steve Jobs in Cupertino, California.",
    types=["PERSON", "ORGANIZATION", "LOCATION"]  # optional filter
)

# Iterate through entities
for entity in response.entities:
    print(f"Text: {entity.text}")
    print(f"Type: {entity.type}")
    print(f"Confidence: {entity.confidence}")
    print("---")

# Response:
# Text: Apple Inc.
# Type: ORGANIZATION
# Confidence: 0.98
# ---
# Text: Steve Jobs
# Type: PERSON
# Confidence: 0.95

Computer Vision

Analyze and understand visual content with our computer vision models.

POST client.vision.analyze_image()

Analyze images for objects, scenes, and visual content.

Python
# From URL
response = client.vision.analyze_image(
    image="https://example.com/image.jpg",
    features=["objects", "faces", "text"]  # optional
)

# From local file
with open("image.jpg", "rb") as image_file:
    response = client.vision.analyze_image(
        image=image_file,
        features=["objects", "colors"]
    )

# From PIL Image
from PIL import Image
pil_image = Image.open("image.jpg")
response = client.vision.analyze_image(
    image=pil_image,
    features=["objects", "faces"]
)

# Access results
for obj in response.objects:
    print(f"Detected: {obj.label} (confidence: {obj.confidence})")

if response.faces:
    for face in response.faces:
        print(f"Age: {face.age}, Gender: {face.gender}")
        print(f"Emotions: {face.emotions}")

print(f"Dominant color: {response.colors.dominant}")
print(f"Detected text: {response.text}")

Chat & Conversations

Build intelligent conversational interfaces with our chat API.

POST client.chat.create_conversation() New

Start a new conversation with context and personality settings.

Python
# Create a conversation
conversation = client.chat.create_conversation(
    context="You are a helpful customer support assistant for a tech company.",
    personality="friendly",  # 'professional', 'casual', 'humorous'
    memory=True  # remember conversation history
)

# Send messages
response = conversation.send_message("How do I reset my password?")

print("Assistant:", response.message)
print("Conversation ID:", response.conversation_id)
print("Suggestions:", response.suggestions)

# Continue the conversation
follow_up = conversation.send_message("What are my security options?")
print("Assistant:", follow_up.message)

# Save conversation state for later
conversation_id = conversation.id
# Later, retrieve the conversation
conversation = client.chat.get_conversation(conversation_id)

Advanced Usage

Learn about advanced features and Python-specific configuration options.

Error Handling

Proper error handling for robust Python applications.

Python
from webburnstech import APIError, AuthenticationError, RateLimitError

try:
    response = client.nlp.analyze_sentiment(
        text="Sample text"
    )
except AuthenticationError as e:
    print("Authentication failed. Please check your API key.")
except RateLimitError as e:
    print(f"Rate limit exceeded. Retry after: {e.retry_after} seconds")
except APIError as e:
    print(f"API Error {e.status_code}: {e.message}")
except Exception as e:
    print(f"Unexpected error: {e}")

Configuration Options

Customize the SDK behavior with various configuration options.

Python
import webburnstech
from webburnstech import Client

client = Client(
    api_key="your-api-key-here",
    
    # Configuration options
    environment="production",  # 'production' or 'development'
    timeout=30,               # request timeout in seconds
    max_retries=3,            # automatic retry attempts
    base_url="https://api.webburnstech.dev/v1",  # custom API endpoint
    
    # Request logging
    debug=False,              # enable debug logging
    
    # Custom headers
    headers={
        "X-Custom-Header": "value"
    },
    
    # HTTP session configuration
    session=None,             # custom requests.Session instance
    
    # Async support
    async_mode=False,         # enable async/await support
)

# For async usage
async_client = Client(
    api_key="your-api-key-here",
    async_mode=True
)

# Async example
async def analyze_async():
    response = await async_client.nlp.analyze_sentiment(
        text="Async text analysis"
    )
    return response

Working with Files

Handle file uploads and binary data with Pythonic interfaces.

Python
# Working with different file types
from pathlib import Path

# From file path
response = client.vision.analyze_image(
    image=Path("/path/to/image.jpg")
)

# From bytes
with open("image.jpg", "rb") as f:
    image_bytes = f.read()

response = client.vision.analyze_image(
    image=image_bytes
)

# From file-like object
with open("image.jpg", "rb") as file_obj:
    response = client.vision.analyze_image(
        image=file_obj
    )

# Batch processing
image_paths = ["image1.jpg", "image2.jpg", "image3.jpg"]
results = []

for path in image_paths:
    try:
        response = client.vision.analyze_image(image=path)
        results.append(response)
    except webburnstech.APIError as e:
        print(f"Failed to process {path}: {e}")

Python-Specific Features

Take advantage of Python-specific features and best practices.

Context Managers

Use context managers for proper resource cleanup and connection management.

with Client(api_key="your-key") as client:
    response = client.nlp.analyze_sentiment(
        text="Using context manager"
    )
# Client automatically closes connections

Type Hints

Full type hint support for better IDE integration and code quality.

from webburnstech import Client
from webburnstech.types import SentimentResponse

def analyze_text(text: str) -> SentimentResponse:
    client = Client(api_key="your-key")
    return client.nlp.analyze_sentiment(text=text)

Custom Exceptions

Rich exception hierarchy for precise error handling.

from webburnstech.exceptions import (
    APIError,
    AuthenticationError,
    RateLimitError,
    InvalidRequestError
)

try:
    response = client.nlp.analyze_sentiment(text="test")
except InvalidRequestError as e:
    print(f"Invalid request: {e}")

Examples & Tutorials

Explore practical Python examples and tutorials to get started quickly.

Flask Web App

Build a sentiment analysis web application with Flask.

View Tutorial →

Django Integration

Integrate WebburnsTech APIs into your Django projects.

View Tutorial →

Data Analysis

Analyze text data with pandas and WebburnsTech NLP.

View Tutorial →
Python Best Practices

The WebburnsTech Python SDK follows Python best practices and conventions. All methods use snake_case naming, return rich objects with proper type hints, and provide comprehensive exception handling.