Skip to main content

A Python library and CLI tool for downloading OpenCellID data by MCC code or country name.

Project description

OpenCellID Downloader

A Python library and command-line tool for downloading OpenCellID data by MCC code or country name.

Project Status

This project is currently in active development.

Current Phase: Phase 4 — Command-line interface functionality

Current test status:

32 passed

Goals

  • Download OpenCellID data using an API key
  • Support downloads by MCC code
  • Support downloads by country name
  • Provide a Python library interface
  • Provide a command-line interface
  • Support automatic .csv.gz extraction
  • Prepare the package for TestPyPI and PyPI release

Installation

Installation from PyPI is coming soon.

For local development, install the package in editable mode:

pip install -e .

Development Setup

Create and activate the conda environment:

conda create -n opencellid-downloader python=3.11
conda activate opencellid-downloader

Install the package locally:

pip install -e .

Run the test suite:

pytest

API Key Setup

Create a local .env file in the project root:

OPENCELLID_API_KEY=your_api_key_here

Do not commit your .env file to GitHub.

The project includes .env.example as a safe template:

OPENCELLID_API_KEY=your_api_key_here

You can also pass a token directly through the CLI with:

opencellid-download Mexico --token YOUR_TOKEN

Python Usage

Build a download URL

from opencellid_downloader import OpenCellIdClient

client = OpenCellIdClient(api_key="fake-key")
url = client.build_mcc_download_url(334)

print(url)

Expected output:

https://opencellid.org/downloads.php?token=fake-key&type=mcc&file=334.csv.gz

Download by MCC

from opencellid_downloader import OpenCellIdClient

client = OpenCellIdClient()
client.download_mcc(334, output_dir="data")

This downloads the OpenCellID file for MCC 334, which corresponds to Mexico.

The file will be saved as:

data/334.csv.gz

Download by country name

from opencellid_downloader import OpenCellIdClient

client = OpenCellIdClient()
client.download_country("Mexico", output_dir="data")

This downloads the OpenCellID file for Mexico using the country-to-MCC lookup helper.

Download and unzip

from opencellid_downloader import OpenCellIdClient

client = OpenCellIdClient()
client.download_country(
    "Mexico",
    output_dir="data",
    unzip=True,
    keep_compressed=True,
)

This downloads:

data/334.csv.gz

and extracts:

data/334.csv

If you do not want to keep the compressed file, use:

client.download_country(
    "Mexico",
    output_dir="data",
    unzip=True,
    keep_compressed=False,
)

Command-Line Usage

After installing the package locally with:

pip install -e .

you can use the CLI command:

opencellid-download --help

Download by country name

opencellid-download Mexico

This downloads OpenCellID data for Mexico using the country-to-MCC lookup helper.

Download by MCC code

opencellid-download 334 --by-mcc

This downloads OpenCellID data for MCC 334.

Choose an output folder

opencellid-download Mexico --output data

Use a token directly

opencellid-download Mexico --token YOUR_TOKEN

If --token is not provided, the package will try to read the token from:

OPENCELLID_API_KEY=your_api_key_here

Download and unzip

opencellid-download Mexico --unzip

This downloads the .csv.gz file and extracts it to .csv.

Download, unzip, and remove the compressed file

opencellid-download Mexico --unzip --remove-compressed

This keeps the extracted .csv file and removes the original .csv.gz file.

Download by MCC, unzip, and choose output folder

opencellid-download 334 --by-mcc --output data --unzip

How Downloads Work

The downloader uses streaming so large files are not loaded into memory all at once.

The file is downloaded in chunks and first written to a temporary .part file. After the download completes successfully, the .part file is renamed to the final filename.

This helps prevent broken or incomplete files from appearing as valid downloads.

Current Features

  • OpenCellIdClient
  • API key support through direct argument or .env
  • MCC download URL builder
  • Download by MCC code
  • Country name to MCC lookup
  • Country aliases such as MX, USA, and UK
  • Download by country name
  • Support for countries with multiple MCC codes
  • Auto-unzip for .csv.gz files
  • Option to keep or remove compressed files after extraction
  • Streaming downloads with requests
  • Progress bar with tqdm
  • Temporary .part file handling
  • Custom exceptions
  • Command-line interface with opencellid-download
  • CLI support for country downloads
  • CLI support for MCC downloads
  • CLI support for --output, --token, --unzip, and --remove-compressed
  • Pytest test suite with mocked downloads and CLI tests

Coming Soon

  • TestPyPI release
  • PyPI release
  • More complete country/MCC coverage
  • Improved documentation
  • Optional CI testing with GitHub Actions

License

MIT License.

Disclaimer

This package is not affiliated with OpenCellID or Unwired Labs.

Users are responsible for complying with OpenCellID's API usage, licensing, and attribution requirements.

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

opencellid_downloader-0.1.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

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

opencellid_downloader-0.1.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file opencellid_downloader-0.1.0.tar.gz.

File metadata

  • Download URL: opencellid_downloader-0.1.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for opencellid_downloader-0.1.0.tar.gz
Algorithm Hash digest
SHA256 23161babb4ab0a46437b0fe31f0ae8a939e2cc5295655ef83da2309cc4861e9f
MD5 28128b84103793cc5c660840509790d4
BLAKE2b-256 382e60a7093da5d5a6366a825914c73eb10735708eeb654e465492feb4301c4c

See more details on using hashes here.

File details

Details for the file opencellid_downloader-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for opencellid_downloader-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df9b83d89253169c1cbcd603cd787f25832f1f47e78c2087370a8acbc8b999c7
MD5 03caa93bf1bea3e46074232ad7c46b78
BLAKE2b-256 581b443759dfacbf37ab0c5c4ce62921cca8f197b7a4124e0598b30bf4be5629

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