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.
Metadata
Release files for opencellid-downloader 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| opencellid_downloader-0.1.1.tar.gz | 13.4 kB | Without provenance | Details for opencellid_downloader-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| opencellid_downloader-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for opencellid_downloader-0.1.1-py3-none-any.whl |
Total release size: 24.4 kB
Release files / opencellid_downloader-0.1.1.tar.gz
| Download URL | opencellid_downloader-0.1.1.tar.gz |
|---|---|
| Size | 13.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0bf0f2baf7fdba5fb4b5cb21de18fc45ca52b42ec32e5524772377c75fc90f5f
|
|
BLAKE2b-256 checksum How to use checksums |
204d1f336ba7e2c0bcb1370af48377d0cf0366d993ae6b2a082b5f05832b0557
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / opencellid_downloader-0.1.1-py3-none-any.whl
| Download URL | opencellid_downloader-0.1.1-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
538a2ed74d262f9d68c40da79503e029048d0963c2b3db99f769315acb7e95bb
|
|
BLAKE2b-256 checksum How to use checksums |
1972ab168476d583c5499a70f4b81320c336f2a1fc6c4c73e430ca1ce44cc45e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Security for opencellid-downloader 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.