Skip to main content

Official command-line interface for OpenAlex

Project description

OpenAlex Official CLI

Official command-line interface for OpenAlex. Currently supports bulk downloading PDFs and TEI XML files, with more features planned.

Note: This package was formerly known as openalex-content-downloader. If you have that installed, please switch to openalex-official.

Installation

pip install openalex-official

Quick Start

# Download PDFs with a filter
openalex download \
  --api-key YOUR_API_KEY \
  --output ./pdfs \
  --filter "publication_year:>2020,type:article"

# Download specific works by ID or DOI
openalex download \
  --api-key YOUR_API_KEY \
  --output ./pdfs \
  --ids "W2741809807,10.1038/nature12373"

# Download from a list of IDs via stdin
cat work_ids.txt | openalex download \
  --api-key YOUR_API_KEY \
  --output ./pdfs \
  --stdin

# Download to S3
openalex download \
  --api-key YOUR_API_KEY \
  --storage s3 \
  --s3-bucket my-bucket \
  --s3-prefix openalex/ \
  --filter "topics.id:T12345"

# Download both PDFs and TEI XML with full metadata
openalex download \
  --api-key YOUR_API_KEY \
  --output ./content \
  --format both \
  --with-full-metadata

# Check API key status
openalex status --api-key YOUR_API_KEY

Features

  • High-throughput async downloads - Targets 5M downloads/day with configurable concurrency
  • Automatic checkpointing - Resume interrupted downloads without re-downloading
  • Adaptive rate limiting - Automatically adjusts to API conditions
  • Multiple storage backends - Local filesystem or S3
  • Progress tracking - Rich terminal UI with live stats, or headless logging
  • Flexible filtering - Use any OpenAlex filter syntax
  • Multiple input modes - Filter, explicit IDs, or piped stdin
  • DOI support - Auto-detects and resolves DOIs to OpenAlex work IDs

CLI Reference

openalex download

Download content from OpenAlex.

Option Description Default
--api-key OpenAlex API key (required) $OPENALEX_API_KEY
--output, -o Output directory ./openalex-downloads
--storage Storage backend: local or s3 local
--s3-bucket S3 bucket name -
--s3-prefix S3 key prefix ""
--filter OpenAlex filter string None (all content)
--ids Comma-separated work IDs or DOIs -
--stdin Read work IDs/DOIs from stdin false
--format Content format: pdf, xml, both pdf
--with-metadata Save basic JSON metadata from list API false
--with-full-metadata Save complete JSON metadata from singleton API false
--nested Use nested folder structure (W##/##/) false
--workers Concurrent download workers (1-200) 50
--resume/--no-resume Resume from checkpoint true
--fresh Ignore checkpoint, start fresh false
--quiet, -q Minimal output (log file only) false
--verbose, -v Extra debug output false

openalex status

Check API key status and credit information.

Option Description
--api-key OpenAlex API key (required)

Filter Examples

# Recent articles
--filter "publication_year:>2020,type:article"

# Specific topic
--filter "topics.id:T12345"

# From a specific institution
--filter "authorships.institutions.id:I123456789"

# Open access only
--filter "open_access.is_oa:true"

# Combined filters
--filter "publication_year:2023,type:article,open_access.is_oa:true"

See OpenAlex filter documentation for all available filters.

File Organization

By default, files are saved flat in the output directory:

output/
├── W2741809807.pdf
├── W2741809807.json  # if --with-metadata or --with-full-metadata
├── W1234567890.pdf
└── .openalex-checkpoint.json

For large downloads (>10,000 files), use --nested to organize files in a nested structure that avoids filesystem issues:

output/
├── W27/
│   └── 41/
│       ├── W2741809807.pdf
│       └── W2741809807.json
├── W12/
│   └── 34/
│       └── W1234567890.pdf
└── .openalex-checkpoint.json

When downloading by DOI, files are named using the DOI (with / replaced by _):

output/
├── 10.1038_nature12373.pdf
└── 10.1038_nature12373.json

Checkpointing

The downloader automatically saves progress to .openalex-checkpoint.json in the output directory. If interrupted, run the same command again to resume.

To start fresh and ignore the checkpoint:

openalex download --api-key KEY --output ./pdfs --fresh

Logging

All activity is logged to openalex-download.log in the output directory, regardless of terminal mode.

High-Throughput Deployment

The download speed is typically limited by network bandwidth, not the tool or API. On a typical home connection (~400 Mbps), expect ~10-15 files/sec (~1M files/day). To achieve higher throughput (5M+ files/day), deploy from a cloud environment:

Performance scaling:

Environment Bandwidth Workers Expected Rate
Home connection 400 Mbps 50 ~10-15 files/sec
Cloud VM (standard) 1-5 Gbps 100-150 ~30-50 files/sec
Cloud VM (high-perf) 10+ Gbps 200-300 ~60+ files/sec

Recommendations for large-scale downloads:

  1. Run from cloud - Deploy on AWS EC2, GCP, or Azure VMs with high network bandwidth. Instances close to Cloudflare edge locations will have lower latency.

  2. Increase workers - Use --workers 150 or higher to saturate available bandwidth. Monitor with verbose mode to find the optimal setting.

  3. Use S3 storage - For very large downloads, stream directly to S3 instead of local disk:

    openalex download \
      --api-key KEY \
      --storage s3 \
      --s3-bucket my-corpus \
      --workers 200
    
  4. Parallelize across machines - For the full corpus, run multiple instances with different filters (e.g., by publication year) on separate machines.

Roadmap

We plan to add more commands to the CLI, including:

  • CSV/JSON export of search results
  • More entity types beyond works

Have a feature request? Open an issue.

Requirements

  • Python 3.9+
  • OpenAlex API key with sufficient credits

Documentation

Full documentation: docs.openalex.org/download/openalex-official

License

MIT

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

openalex_official-0.2.0.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

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

openalex_official-0.2.0-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file openalex_official-0.2.0.tar.gz.

File metadata

  • Download URL: openalex_official-0.2.0.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for openalex_official-0.2.0.tar.gz
Algorithm Hash digest
SHA256 dbf551a7e780e7a9c14db9ed58dc13c9e979489616339ea2114e63f0f0e13869
MD5 241697ddc94522265f7655e482e68644
BLAKE2b-256 eacc59ec579d597574aae2f2fbba6c596bcaaaa8a7499063aefdaade6178dd2c

See more details on using hashes here.

File details

Details for the file openalex_official-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openalex_official-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7c35fc1171282ed9ee3f65a21c93267b2aa7826db4133e76e932f8071f17b1f
MD5 331c977ba9751526fea6102d7b239b3d
BLAKE2b-256 db35ddc058a1326d1700c6608526068576c3369d3c061e2940e4eb0ae25f7913

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