Skip to content

Fetch data for 28 days to stay within quota - #45

Merged
hugovk merged 1 commit into
mainfrom
28-days
Mar 1, 2025
Merged

hugovk merged 1 commit into
mainfrom
28-days

Conversation

@hugovk

@hugovk hugovk commented Mar 1, 2025

Copy link
Copy Markdown
Owner

29 days uses too much quota:

from google.cloud import bigquery

# Construct a BigQuery client object.
# client = bigquery.Client()
client = bigquery.Client.from_service_account_json("pypinfo-key.json")

job_config = bigquery.QueryJobConfig(dry_run=True, use_query_cache=False)

# Start the query, passing in the extra configuration.
query_job = client.query(
    (
        """
        SELECT
          file.project as project,
          COUNT(*) as download_count,
        FROM `bigquery-public-data.pypi.file_downloads`
        WHERE timestamp BETWEEN TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL -30 DAY) AND TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL -1 DAY)
        GROUP BY
          project
        ORDER BY
          download_count DESC
        LIMIT 15000
        """
    ),
    job_config=job_config,
)  # Make an API request.



# A dry run query completes immediately.
print(
    f"This query will process {query_job.total_bytes_processed:,} bytes or"
    f" {query_job.total_bytes_processed / 2**40:.2f} TiB."
)
❯ p dry-run.py
This query will process 1,125,717,300,161 bytes or 1.02 TiB.

Reducing by a day, -30->-29 for a 28 day period should be okay:

❯ p dry-run.py
This query will process 1,084,266,719,315 bytes or 0.99 TiB.

@hugovk
hugovk merged commit 2d0cd07 into main Mar 1, 2025
@hugovk
hugovk deleted the 28-days branch March 1, 2025 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant