Python client for downloading data from the MoSPI Microdata Portal (https://microdata.gov.in)
Project description
MoSPI Unit Data Client
A Python client for downloading microdata from the MoSPI Microdata Portal. This package provides a convenient interface to browse, search, and download datasets from the Government of India's National Statistical Office (NSO).
Installation
pip install mospi-unitdata
Getting an API Key
To use this package, you need an API key from the MoSPI Microdata Portal:
- Visit the MoSPI Microdata Portal.
- Create an account or sign in if you already have one.
- Verify your email address (check your inbox for a confirmation link).
- Login to your account.
- Navigate to your Profile section.
- Click on Generate API Key (or view your existing key).
Usage
from MospiUnitdata import list_datasets, list_files, download_file, download_dataset
List datasets
# List all datasets
datasets = list_datasets("YOUR_API_KEY")
# List a specific page
datasets = list_datasets("YOUR_API_KEY", page=1)
# Search by keyword
datasets = list_datasets("YOUR_API_KEY", query="labour force")
for d in datasets:
print(f"{d['id']} ({d['idno']}): {d['title']}")
List files in a dataset
files = list_files("DDI-IND-NSO-ASI-2020-21", "YOUR_API_KEY")
for f in files:
print(f"{f['name']} ({f.get('size', '?')})")
Download a single file
download_file("DDI-IND-NSO-ASI-2020-21", "ASI_DATA_2020_21_CSV.zip", "./data", "YOUR_API_KEY")
Download all files in a dataset
download_dataset("DDI-IND-NSO-ASI-2020-21", "./data", "YOUR_API_KEY")
Interactive mode (legacy)
from MospiUnitdata import getDatasets
getDatasets("./data", "YOUR_API_KEY")
This opens an interactive prompt to browse and select datasets page by page.
API Reference
| Function | Description |
|---|---|
list_datasets(api_key, page=None, query=None) |
List datasets. Returns all if no page specified. Optional keyword search. |
list_files(dataset_id, api_key) |
List files available in a dataset. |
download_file(dataset_id, file_name, folder_path, api_key) |
Download a single file from a dataset. |
download_dataset(dataset_id, folder_path, api_key) |
Download all files from a dataset. |
getDatasets(folder_path, api_key) |
Interactive browser and downloader (legacy). |
Requirements
- Python 3.9+
requests>= 2.31.0
License
This project is licensed under the MIT License.
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 mospi_unitdata-0.2.0.tar.gz.
File metadata
- Download URL: mospi_unitdata-0.2.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc99d2df4c3353635394e92963216a7c8328cb5268a172969c59eb6802de1479
|
|
| MD5 |
631f61e592a3129a76c4e34bd136c225
|
|
| BLAKE2b-256 |
064531799058e2fefd0354f22bc84a287a7b2580bdce41b62f38fb25fb410255
|
File details
Details for the file mospi_unitdata-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mospi_unitdata-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24c050d15e0513d8ad2fabac3b298e2c2a2b4ab28dd59b6fc0369be10943252e
|
|
| MD5 |
9910d576f589bbfeb579ab60c30ae0ed
|
|
| BLAKE2b-256 |
b552f87e8252aaba41a409ae4bcc1b1166af4969e3ee9732ad7a8e7eb52fea36
|