Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch data for 28 days to stay within quota #45

Merged
merged 1 commit into from
Mar 1, 2025
Merged

Fetch data for 28 days to stay within quota #45

merged 1 commit into from
Mar 1, 2025

Conversation

hugovk
Copy link
Owner

@hugovk hugovk commented Mar 1, 2025

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
3 checks passed
@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