### Install and Configure OpenAlex Downloader Source: https://github.com/ourresearch/openalex-official/blob/main/examples/notebooks/download_workflow.ipynb Initial setup steps including package installation and environment variable configuration for the OpenAlex API key. ```python # !pip install openalex-content-downloader import os import asyncio os.environ["OPENALEX_API_KEY"] = "your-api-key-here" from openalex_content.api_client import OpenAlexAPIClient from openalex_content.downloader import DownloadConfig, DownloadOrchestrator from openalex_content.progress import ProgressTracker from openalex_content.utils import ContentFormat, StorageType ``` -------------------------------- ### Execute Content Download Source: https://github.com/ourresearch/openalex-official/blob/main/examples/notebooks/download_workflow.ipynb Configures and runs the download orchestrator to fetch files. Supports progress tracking and allows for resuming interrupted tasks. ```python config = DownloadConfig( api_key=os.environ["OPENALEX_API_KEY"], output_path="./ml_papers_2024", storage_type=StorageType.LOCAL, filter_str="publication_year:2024,topics.id:T10207", content_format=ContentFormat.PDF, with_metadata=True, workers=20, ) progress = ProgressTracker(output_dir=config.output_path, quiet=True) orchestrator = DownloadOrchestrator(config) try: await orchestrator.run(progress_tracker=progress) except KeyboardInterrupt: print("\nDownload paused.") ``` -------------------------------- ### Configure S3 Storage and CLI Usage Source: https://github.com/ourresearch/openalex-official/blob/main/examples/notebooks/download_workflow.ipynb Alternative configuration for S3 cloud storage and command-line interface usage for production environments. ```python config = DownloadConfig( storage_type=StorageType.S3, s3_bucket="my-bucket", s3_prefix="openalex/", ... ) ``` ```bash openalex-content download --api-key KEY --output ./pdfs --filter "publication_year:2024" ``` -------------------------------- ### Download data to S3 storage using CLI Source: https://github.com/ourresearch/openalex-official/blob/main/README.md Configures the OpenAlex CLI to stream downloaded data directly to an Amazon S3 bucket. This approach is recommended for large-scale downloads to bypass local disk limitations. ```bash openalex download \ --api-key KEY \ --storage s3 \ --s3-bucket my-corpus \ --workers 200 ``` -------------------------------- ### Examine Downloaded Files Source: https://github.com/ourresearch/openalex-official/blob/main/examples/notebooks/download_workflow.ipynb Utility script to verify the number of downloaded PDFs and inspect the associated JSON metadata files. ```python from pathlib import Path import json output_dir = Path("./ml_papers_2024") pdf_files = list(output_dir.rglob("*.pdf")) json_files = list(output_dir.rglob("*.json")) if json_files: with open(json_files[0]) as f: metadata = json.load(f) print(f"Title: {metadata.get('title')}") ``` -------------------------------- ### Verify API Status Source: https://github.com/ourresearch/openalex-official/blob/main/examples/notebooks/download_workflow.ipynb Checks the current API rate limits to ensure connectivity and available quota before initiating large download tasks. ```python async def check_status(): client = OpenAlexAPIClient(api_key=os.environ["OPENALEX_API_KEY"]) try: status = await client.get_status() print(f"Rate limit remaining: {status.rate_limit_remaining:,}") finally: await client.close() await check_status() ``` -------------------------------- ### Count Filtered Works Source: https://github.com/ourresearch/openalex-official/blob/main/examples/notebooks/download_workflow.ipynb Queries the OpenAlex API to determine the number of records matching specific criteria, such as publication year or research topics. ```python import aiohttp async def count_works(filter_str: str): api_key = os.environ["OPENALEX_API_KEY"] url = "https://api.openalex.org/works" params = { "filter": f"has_content.pdf:true,{filter_str}", "per-page": 1, "api_key": api_key, } async with aiohttp.ClientSession() as session: async with session.get(url, params=params) as response: data = await response.json() return data.get("meta", {}).get("count", 0) filter_str = "publication_year:2024,topics.id:T10207" count = await count_works(filter_str) print(f"Works matching filter: {count:,}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.