Skip to main content

A Python Client and CLI for the Windsor.ai API

Project description

Windsor.ai Python SDK

A powerful, lightweight Python client and command-line interface (CLI) for the Windsor.ai API.

Easily fetch marketing data from Facebook, Google Ads, LinkedIn, and dozens of other platforms, unify it, and stream it directly into your Python scripts or data pipelines.

Features

  • Easy-to-use Client: Simple Python wrapper for API endpoints.
  • Built-in CLI: Query data directly from your terminal—perfect for cron jobs or quick checks.
  • Smart Filtering: Helper classes to construct complex API filters easily.
  • Data Streaming: Efficiently handle massive datasets with pagination automagically handled via generators.
  • Type Hints: Fully typed for better developer experience in modern IDEs.

Installation

Install the package via pip:

pip install windsor-ai

Authentication

You need a Windsor.ai API key. You can pass it explicitly to the client or set it as an environment variable (recommended).

Environment Variable:

export WINDSOR_API_KEY="your_api_key_here"

Python Library Usage

1. Basic Data Fetching

from windsor_ai import Client

# Initialize (automatically reads WINDSOR_API_KEY env var)
client = Client(api_key="your_api_key") 

# Fetch data
response = client.connectors(
    connector="facebook",
    date_preset="last_7d",
    fields=["date", "campaign", "clicks", "spend", "impressions"]
)

for row in response['data']:
    print(f"{row['date']}: {row['campaign']} - ${row['spend']}")

2. Advanced Filtering

Use the Filter class to create readable, robust queries.

from windsor_ai import Client, Filter

client = Client("your_api_key")

# Define filters
filters = [
    Filter("clicks", "gt", 100),            # Clicks greater than 100
    Filter("campaign", "contains", "Q4"),   # Campaign name contains "Q4"
]

data = client.connectors(
    connector="google_ads",
    date_preset="last_30d",
    fields=["campaign", "clicks", "cpc"],
    filters=filters
)

3. Handling Large Datasets (Streaming)

If you are exporting millions of rows, use stream_connectors. It yields records one by one, handling pagination behind the scenes so you don't run out of RAM.

client = Client("your_api_key")

# Returns a generator, not a list
iterator = client.stream_connectors(
    connector="all",
    date_preset="last_year",
    fields=["source", "campaign", "clicks", "spend"]
)

for row in iterator:
    # Process row immediately (e.g., write to CSV or Database)
    save_to_db(row)

CLI Usage

This package installs a command-line tool named windsor.

1. List Available Connectors

windsor list-connectors

2. Check Available Fields

See which metrics and dimensions are available for a specific platform.

windsor fields facebook

3. Query Data

Fetch data and output as JSON (default) or CSV.

# Fetch last 7 days of Facebook data
windsor query \
  --connector facebook \
  --date-preset last_7d \
  --fields date,campaign,clicks,spend \
  --format json

4. CLI Filtering and Exporting

You can filter data using the field:operator:value syntax.

Operators: eq, neq, gt, gte, lt, lte, contains, ncontains, null, notnull.

# Export Google Ads data to a CSV file
windsor query \
  --connector google_ads \
  --date-preset last_30d \
  --fields campaign,clicks,impressions \
  --filter "clicks:gt:50" \
  --filter "campaign:contains:Summer" \
  --format csv \
  --out report.csv

Development

To contribute to this project:

  1. Clone the repository.
  2. Install dependencies and the package in editable mode:
    pip install -e .
    pip install build twine pytest flake8
    
  3. Run tests:
    # Requires WINDSOR_API_KEY to be set
    pytest
    

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

windsor_ai-0.2.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

windsor_ai-0.2.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file windsor_ai-0.2.0.tar.gz.

File metadata

  • Download URL: windsor_ai-0.2.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for windsor_ai-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9fc1f9a0ff67e899c1746ebadb2ab30f993cdc1c5590a5a4c1bd2086c236ac3b
MD5 5338b0501e70dda9991278842394639d
BLAKE2b-256 02e15ec3e5a87b84bdddbb71ce2c35ea418c613704ccd3d52851dee6e2c16738

See more details on using hashes here.

File details

Details for the file windsor_ai-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: windsor_ai-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for windsor_ai-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2dcf990e09a1f6fb876bba0c9924abe1a7467c3a277d32ae523017a23df5be0e
MD5 c4716578f2762507adcc1f5e6633d7d2
BLAKE2b-256 35fec38d95cac74e04e6647c41502d23e5e9876f77c467dc5fbbdbf8c098567d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page