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.1.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.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: opencellid_downloader-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 0bf0f2baf7fdba5fb4b5cb21de18fc45ca52b42ec32e5524772377c75fc90f5f
MD5 6bc3a95be7a751325feb1344b3b65ca2
BLAKE2b-256 204d1f336ba7e2c0bcb1370af48377d0cf0366d993ae6b2a082b5f05832b0557

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencellid_downloader-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 538a2ed74d262f9d68c40da79503e029048d0963c2b3db99f769315acb7e95bb
MD5 d22c7f0d8eb8d8d159b8c628cbeede5a
BLAKE2b-256 1972ab168476d583c5499a70f4b81320c336f2a1fc6c4c73e430ca1ce44cc45e

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