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.gzextraction - 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, andUK - Download by country name
- Support for countries with multiple MCC codes
- Auto-unzip for
.csv.gzfiles - Option to keep or remove compressed files after extraction
- Streaming downloads with
requests - Progress bar with
tqdm - Temporary
.partfile 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23161babb4ab0a46437b0fe31f0ae8a939e2cc5295655ef83da2309cc4861e9f
|
|
| MD5 |
28128b84103793cc5c660840509790d4
|
|
| BLAKE2b-256 |
382e60a7093da5d5a6366a825914c73eb10735708eeb654e465492feb4301c4c
|
File details
Details for the file opencellid_downloader-0.1.0-py3-none-any.whl.
File metadata
- Download URL: opencellid_downloader-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df9b83d89253169c1cbcd603cd787f25832f1f47e78c2087370a8acbc8b999c7
|
|
| MD5 |
03caa93bf1bea3e46074232ad7c46b78
|
|
| BLAKE2b-256 |
581b443759dfacbf37ab0c5c4ce62921cca8f197b7a4124e0598b30bf4be5629
|