mospi-unitdata 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mospi_unitdata-0.1.0/.gitignore +30 -0
- mospi_unitdata-0.1.0/LICENSE +21 -0
- mospi_unitdata-0.1.0/MospiUnitdata/MospiUnitdata.py +112 -0
- mospi_unitdata-0.1.0/MospiUnitdata/__init__.py +3 -0
- mospi_unitdata-0.1.0/PKG-INFO +94 -0
- mospi_unitdata-0.1.0/README.md +65 -0
- mospi_unitdata-0.1.0/pyproject.toml +51 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.pyc
|
|
4
|
+
*.pyo
|
|
5
|
+
*.egg-info/
|
|
6
|
+
*.egg
|
|
7
|
+
.eggs/
|
|
8
|
+
dist/
|
|
9
|
+
build/
|
|
10
|
+
|
|
11
|
+
# Virtual environments
|
|
12
|
+
.venv/
|
|
13
|
+
venv/
|
|
14
|
+
env/
|
|
15
|
+
|
|
16
|
+
# Testing
|
|
17
|
+
.pytest_cache/
|
|
18
|
+
.coverage
|
|
19
|
+
htmlcov/
|
|
20
|
+
|
|
21
|
+
# IDE
|
|
22
|
+
.vscode/
|
|
23
|
+
.idea/
|
|
24
|
+
*.swp
|
|
25
|
+
*.swo
|
|
26
|
+
*~
|
|
27
|
+
|
|
28
|
+
# OS
|
|
29
|
+
.DS_Store
|
|
30
|
+
Thumbs.db
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Ministry of Statistics and Programme Implementation, Government of India
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import os
|
|
3
|
+
from typing import List, Dict, Any
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def listDatasets(pageNo=1) -> List[Dict[str, Any]]:
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
|
|
10
|
+
response = requests.get("https://microdata.gov.in/NADA/index.php/api/listdatasets?page="+str(pageNo),headers=None)
|
|
11
|
+
|
|
12
|
+
data = response.json()
|
|
13
|
+
|
|
14
|
+
return data
|
|
15
|
+
|
|
16
|
+
except Exception as e:
|
|
17
|
+
print('Error while downloading the data:',e)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
return None
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def getDatasets(folderPath, apiKey):
|
|
24
|
+
|
|
25
|
+
page = 1
|
|
26
|
+
errorFlag = False
|
|
27
|
+
|
|
28
|
+
while True:
|
|
29
|
+
|
|
30
|
+
data = listDatasets(page)
|
|
31
|
+
|
|
32
|
+
if data is None:
|
|
33
|
+
print('Error occurred while downloading the data!')
|
|
34
|
+
errorFlag = True
|
|
35
|
+
break
|
|
36
|
+
|
|
37
|
+
rows = data["result"]["rows"]
|
|
38
|
+
|
|
39
|
+
indexed_data = [
|
|
40
|
+
{**item, "index": i}
|
|
41
|
+
for i, item in enumerate(rows, start=1)
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
for item in indexed_data:
|
|
45
|
+
print(item["id"] + ":" + item["title"])
|
|
46
|
+
|
|
47
|
+
total = int(data["result"]["total"])
|
|
48
|
+
limit = int(data["result"]["limit"])
|
|
49
|
+
|
|
50
|
+
pages = total // limit + (1 if total % limit else 0)
|
|
51
|
+
|
|
52
|
+
user_input = input(
|
|
53
|
+
f"Total pages:{pages}, Page:{page} of {pages},\n"
|
|
54
|
+
"Enter Survey index number (put n to Navigate to Next Page): "
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
if user_input.strip().lower() == 'n':
|
|
59
|
+
page = page + 1
|
|
60
|
+
|
|
61
|
+
if page > pages:
|
|
62
|
+
print("No more Pages left to browse the data.")
|
|
63
|
+
break
|
|
64
|
+
else:
|
|
65
|
+
continue
|
|
66
|
+
|
|
67
|
+
else:
|
|
68
|
+
if errorFlag == False:
|
|
69
|
+
idno = None
|
|
70
|
+
if user_input.isdigit():
|
|
71
|
+
|
|
72
|
+
for item in indexed_data:
|
|
73
|
+
if item["id"] == user_input:
|
|
74
|
+
idno = item["idno"]
|
|
75
|
+
|
|
76
|
+
if idno is not None:
|
|
77
|
+
|
|
78
|
+
url = "https://microdata.gov.in/NADA/index.php/api/datasets/" + idno + "/fileslist"
|
|
79
|
+
|
|
80
|
+
headers = {
|
|
81
|
+
"Host": "microdata.gov.in",
|
|
82
|
+
"X-API-KEY": apiKey
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
response = requests.get(url, headers=headers)
|
|
86
|
+
|
|
87
|
+
data = response.json()
|
|
88
|
+
|
|
89
|
+
folder = folderPath
|
|
90
|
+
|
|
91
|
+
for item1 in data["files"]:
|
|
92
|
+
|
|
93
|
+
url = "https://microdata.gov.in/NADA/index.php/api/fileslist/download/" + idno + "/" + item1["base64"]
|
|
94
|
+
|
|
95
|
+
response = requests.get(url, headers=headers)
|
|
96
|
+
|
|
97
|
+
filename = os.path.join(folder, item1["name"])
|
|
98
|
+
|
|
99
|
+
with open(filename, "wb") as f:
|
|
100
|
+
f.write(response.content)
|
|
101
|
+
print(filename + ":Downloaded successfully!")
|
|
102
|
+
break
|
|
103
|
+
else:
|
|
104
|
+
print('No such index Exists to download the Data. Kindly check and try again!')
|
|
105
|
+
break
|
|
106
|
+
|
|
107
|
+
else:
|
|
108
|
+
print("Invalid Index no.")
|
|
109
|
+
break
|
|
110
|
+
|
|
111
|
+
else:
|
|
112
|
+
print('Error occurred while downloading the data!')
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mospi-unitdata
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python client for downloading data from the MoSPI Microdata Portal (https://microdata.gov.in)
|
|
5
|
+
Project-URL: Homepage, https://microdata.gov.in
|
|
6
|
+
Project-URL: Repository, https://github.com/nso-india/mospi-unitdata
|
|
7
|
+
Project-URL: Issues, https://github.com/nso-india/mospi-unitdata/issues
|
|
8
|
+
Author: DIID, Ministry of Statistics and Programme Implementation, Neeraj Prakash, Satvik Bajpai, Sarthak Srivastava
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: api,data,government,india,microdata,mospi,nso,nsoindia,statistics
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Requires-Dist: requests>=2.31.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: build>=1.2.2; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# MoSPI Unit Data Client
|
|
31
|
+
|
|
32
|
+
[](https://badge.fury.io/py/mospi-unitdata)
|
|
33
|
+
[](https://opensource.org/licenses/MIT)
|
|
34
|
+
|
|
35
|
+
A Python client for downloading microdata from the [MoSPI Microdata Portal](https://microdata.gov.in).
|
|
36
|
+
This package provides a convenient interface to browse and download datasets from the Government of India's National Statistical Office (NSO).
|
|
37
|
+
|
|
38
|
+
### About
|
|
39
|
+
This package is used to download the data from the MoSPI Microdata Portal. Specifically, you can browse available datasets interactively and download them by calling the provided methods with your API key.
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
You can install the package directly from PyPI:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install mospi-unitdata
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Getting an API Key
|
|
50
|
+
|
|
51
|
+
To use this package, you need an API key from the MoSPI Microdata Portal:
|
|
52
|
+
|
|
53
|
+
1. Visit the [MoSPI Microdata Portal](https://microdata.gov.in).
|
|
54
|
+
2. **Create an account** or sign in if you already have one.
|
|
55
|
+
3. **Verify your email** address (check your inbox for a confirmation link).
|
|
56
|
+
4. **Login** to your account.
|
|
57
|
+
5. Navigate to your **Profile** section.
|
|
58
|
+
6. Click on **Generate API Key** (or view your existing key).
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
To download datasets, use the `getDatasets` method. This method takes two mandatory parameters:
|
|
63
|
+
1. **First parameter (`folderPath`)**: The location/folder on your computer where you want to save the downloaded data.
|
|
64
|
+
2. **Second parameter (`apiKey`)**: Your API key generated from the [MicroData Portal Profile Section](https://microdata.gov.in/NADA/index.php/auth/profile).
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from MospiUnitdata import getDatasets
|
|
68
|
+
|
|
69
|
+
# Provide the save location and your API Key
|
|
70
|
+
getDatasets("path/to/save/data", "YOUR_API_KEY")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The function provides an interactive prompt to browse through the available datasets:
|
|
74
|
+
|
|
75
|
+
```text
|
|
76
|
+
277:Annual Survey of Industries 2019-20
|
|
77
|
+
275:Annual Survey of Industries 2020-21
|
|
78
|
+
256:Annual Survey of Industries 2023-24
|
|
79
|
+
...
|
|
80
|
+
Total pages:13,Page:1 of 13,
|
|
81
|
+
Enter Survey index number(put n to Navigate to Next Page):
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Type the numeric index to download the associated dataset, or `n` to view the next page.
|
|
85
|
+
|
|
86
|
+
## Requirements
|
|
87
|
+
- Python 3.9+
|
|
88
|
+
- `requests` >= 2.31.0
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
This project is licensed under the MIT License.
|
|
94
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# MoSPI Unit Data Client
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/py/mospi-unitdata)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
A Python client for downloading microdata from the [MoSPI Microdata Portal](https://microdata.gov.in).
|
|
7
|
+
This package provides a convenient interface to browse and download datasets from the Government of India's National Statistical Office (NSO).
|
|
8
|
+
|
|
9
|
+
### About
|
|
10
|
+
This package is used to download the data from the MoSPI Microdata Portal. Specifically, you can browse available datasets interactively and download them by calling the provided methods with your API key.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
You can install the package directly from PyPI:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install mospi-unitdata
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Getting an API Key
|
|
21
|
+
|
|
22
|
+
To use this package, you need an API key from the MoSPI Microdata Portal:
|
|
23
|
+
|
|
24
|
+
1. Visit the [MoSPI Microdata Portal](https://microdata.gov.in).
|
|
25
|
+
2. **Create an account** or sign in if you already have one.
|
|
26
|
+
3. **Verify your email** address (check your inbox for a confirmation link).
|
|
27
|
+
4. **Login** to your account.
|
|
28
|
+
5. Navigate to your **Profile** section.
|
|
29
|
+
6. Click on **Generate API Key** (or view your existing key).
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
To download datasets, use the `getDatasets` method. This method takes two mandatory parameters:
|
|
34
|
+
1. **First parameter (`folderPath`)**: The location/folder on your computer where you want to save the downloaded data.
|
|
35
|
+
2. **Second parameter (`apiKey`)**: Your API key generated from the [MicroData Portal Profile Section](https://microdata.gov.in/NADA/index.php/auth/profile).
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from MospiUnitdata import getDatasets
|
|
39
|
+
|
|
40
|
+
# Provide the save location and your API Key
|
|
41
|
+
getDatasets("path/to/save/data", "YOUR_API_KEY")
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The function provides an interactive prompt to browse through the available datasets:
|
|
45
|
+
|
|
46
|
+
```text
|
|
47
|
+
277:Annual Survey of Industries 2019-20
|
|
48
|
+
275:Annual Survey of Industries 2020-21
|
|
49
|
+
256:Annual Survey of Industries 2023-24
|
|
50
|
+
...
|
|
51
|
+
Total pages:13,Page:1 of 13,
|
|
52
|
+
Enter Survey index number(put n to Navigate to Next Page):
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Type the numeric index to download the associated dataset, or `n` to view the next page.
|
|
56
|
+
|
|
57
|
+
## Requirements
|
|
58
|
+
- Python 3.9+
|
|
59
|
+
- `requests` >= 2.31.0
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
This project is licensed under the MIT License.
|
|
65
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mospi-unitdata"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python client for downloading data from the MoSPI Microdata Portal (https://microdata.gov.in)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "DIID, Ministry of Statistics and Programme Implementation" },
|
|
14
|
+
{ name = "Neeraj Prakash" },
|
|
15
|
+
{ name = "Satvik Bajpai" },
|
|
16
|
+
{ name = "Sarthak Srivastava" },
|
|
17
|
+
]
|
|
18
|
+
keywords = ["microdata", "mospi", "nso", "nsoindia", "india", "statistics", "government", "data", "api"]
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Development Status :: 3 - Alpha",
|
|
21
|
+
"Intended Audience :: Developers",
|
|
22
|
+
"Intended Audience :: Science/Research",
|
|
23
|
+
"License :: OSI Approved :: MIT License",
|
|
24
|
+
"Programming Language :: Python :: 3",
|
|
25
|
+
"Programming Language :: Python :: 3.9",
|
|
26
|
+
"Programming Language :: Python :: 3.10",
|
|
27
|
+
"Programming Language :: Python :: 3.11",
|
|
28
|
+
"Programming Language :: Python :: 3.12",
|
|
29
|
+
"Topic :: Scientific/Engineering",
|
|
30
|
+
]
|
|
31
|
+
dependencies = [
|
|
32
|
+
"requests>=2.31.0",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.optional-dependencies]
|
|
36
|
+
dev = [
|
|
37
|
+
"build>=1.2.2",
|
|
38
|
+
"pytest>=7.0",
|
|
39
|
+
"pytest-asyncio>=0.21",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Homepage = "https://microdata.gov.in"
|
|
44
|
+
Repository = "https://github.com/nso-india/mospi-unitdata"
|
|
45
|
+
Issues = "https://github.com/nso-india/mospi-unitdata/issues"
|
|
46
|
+
|
|
47
|
+
[tool.hatch.build.targets.wheel]
|
|
48
|
+
packages = ["MospiUnitdata"]
|
|
49
|
+
|
|
50
|
+
[tool.hatch.build.targets.sdist]
|
|
51
|
+
include = ["MospiUnitdata/**"]
|