Skip to main content

Cloudflare Analytics GraphQL API client

Project description

Python Cloudflare Analytics Client

A Python client for interacting with the Cloudflare GraphQL Analytics API.

Note: The official Cloudflare Python library does not support the GraphQL Analytics API endpoints. This library provides dedicated support for querying Cloudflare analytics data.

Installation

uv add cloudflare-analytics

Usage

from cloudflare_analytics import client

# Execute a GraphQL query
query = '''
query GetStreamMinutes($accountTag: string!, $start: Date, $end: Date) {
  viewer {
    accounts(filter: { accountTag: $accountTag }) {
      streamMinutesViewedAdaptiveGroups(
        filter: { date_geq: $start, date_lt: $end }
        orderBy: [date_ASC]
      ) {
        dimensions { date }
        sum { minutesViewed }
      }
    }
  }
}
'''

response = client.query(
    query,
    variables={
        "accountTag": "your_account_id",
        "start": "2025-10-01",
        "end": "2025-10-28"
    },
    api_token="your_cloudflare_api_token"
)

if response.errors:
    print(f"Errors: {response.errors}")
elif response.data:
    groups = response.data["viewer"]["accounts"][0]["streamMinutesViewedAdaptiveGroups"]
    for group in groups:
        minutes = group["sum"]["minutesViewed"]
        date = group["dimensions"]["date"]
        print(f"Date: {date}, Minutes: {minutes}")

Features

  • Simple, clean API for Cloudflare GraphQL Analytics
  • Built-in retry logic with exponential backoff
  • Type-safe responses using Pydantic models
  • Comprehensive error handling

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

cloudflare_analytics-0.1.1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

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

cloudflare_analytics-0.1.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file cloudflare_analytics-0.1.1.tar.gz.

File metadata

File hashes

Hashes for cloudflare_analytics-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d8b0c5e0637055ce5b9e364eacde124a61494bdd81229f56d1b91d02681417d0
MD5 6daffa2804bce132805949b8092ca2d9
BLAKE2b-256 11fbaec67381bc93edfd300988a13b9bebf1e727ee9875242a5451de182b4e1b

See more details on using hashes here.

File details

Details for the file cloudflare_analytics-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cloudflare_analytics-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 98f8acc4e820c999c6fbcb20e90e963a91588f41f9372d49016e5a750cd37a2e
MD5 cda8da745985e42e1a8ab531de172ec8
BLAKE2b-256 84637ccac01296895fb98eb7ad3a90af205ab3c9034a296136a9016069441da7

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