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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cloudflare_analytics-0.1.1.tar.gz.
File metadata
- Download URL: cloudflare_analytics-0.1.1.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8b0c5e0637055ce5b9e364eacde124a61494bdd81229f56d1b91d02681417d0
|
|
| MD5 |
6daffa2804bce132805949b8092ca2d9
|
|
| BLAKE2b-256 |
11fbaec67381bc93edfd300988a13b9bebf1e727ee9875242a5451de182b4e1b
|
File details
Details for the file cloudflare_analytics-0.1.1-py3-none-any.whl.
File metadata
- Download URL: cloudflare_analytics-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98f8acc4e820c999c6fbcb20e90e963a91588f41f9372d49016e5a750cd37a2e
|
|
| MD5 |
cda8da745985e42e1a8ab531de172ec8
|
|
| BLAKE2b-256 |
84637ccac01296895fb98eb7ad3a90af205ab3c9034a296136a9016069441da7
|