india-regions 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.
@@ -0,0 +1,9 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .pytest_cache/
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ node_modules/
8
+ .venv/
9
+ .DS_Store
@@ -0,0 +1,11 @@
1
+ # Data licence
2
+
3
+ The files in `src/india_regions/data/` are licensed under the
4
+ [Creative Commons Attribution 4.0 International licence (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/).
5
+
6
+ Credit: **TheMapsDaily (themapsdaily.com)**.
7
+
8
+ The tables are compiled from public records: Census of India reports, the Local Government
9
+ Directory (LGD, published under the Government Open Data Licence – India), state gazette
10
+ notifications, and the source linked on each district event. Facts (names, dates, codes) are
11
+ not copyrightable; the compilation, ids and corrections are ours and are what this licence covers.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TheMapsDaily
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,115 @@
1
+ Metadata-Version: 2.5
2
+ Name: india-regions
3
+ Version: 0.1.0
4
+ Summary: India's states and districts through time: which existed in which year, LGD/Census codes, and matching for messy or misspelt names.
5
+ Project-URL: Homepage, https://themapsdaily.com
6
+ Project-URL: Source, https://github.com/themapsdaily/india-regions
7
+ Author: TheMapsDaily
8
+ License: MIT (code), CC-BY-4.0 (data)
9
+ License-File: LICENSE
10
+ Keywords: census,data-cleaning,districts,fuzzy-matching,geography,india,lgd,states
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: 3.15
19
+ Classifier: Topic :: Scientific/Engineering :: GIS
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+
23
+ # india-regions
24
+
25
+ Indian data is full of state and district names that don't line up. "Orissa" in one table and "Odisha" in the next. "Gurgaon" in 2014 and "Gurugram" in 2020. "Telengana", "Chattisgarh", "Ladakh @", "Delhi (NCT)". Telangana figures that were part of Andhra Pradesh until 2014. A district called "Aurangabad" in two different states.
26
+
27
+ `india-regions` sorts this out in Python and JavaScript, with no dependencies:
28
+
29
+ - **Which state or district existed in which year.** States and UTs from 1947, including princely states and provinces. Districts from 1961.
30
+ - **Names to ids.** A label from any source, including the typos publishers really make, becomes one stable id.
31
+ - **The right unit for any year.** "Uttarakhand" in 1995 becomes Uttar Pradesh. "Allahabad" in 2020 becomes Prayagraj.
32
+ - **Codes.** LGD and Census 2011 district codes, plus short state codes such as `UP`, `TN` and `OD`.
33
+
34
+ ```
35
+ pip install india-regions
36
+ npm install india-regions
37
+ ```
38
+
39
+ ## States
40
+
41
+ ```python
42
+ from india_regions import normalize_state, normalize_region, resolve_state_for_year, match_state
43
+
44
+ normalize_state("ODISHA #") # 'odisha' (footnote marks dropped)
45
+ normalize_state("Telengana") # 'telangana' (known typo)
46
+ normalize_state("UP") # 'uttar-pradesh'
47
+
48
+ normalize_region("Orissa", 1998) # 'orissa' the id that year
49
+ normalize_region("Uttarakhand", 1995) # 'uttar-pradesh' (two hops: Uttaranchal, then UP)
50
+ resolve_state_for_year("telangana", 1950) # 'hyderabad-state'
51
+ resolve_state_for_year("dnh", 2021) # 'dnhdd' (merged in 2020)
52
+
53
+ match_state("Utter Pradesh") # Match(id='uttar-pradesh', score=0.9091, method='fuzzy', ...)
54
+ ```
55
+
56
+ Normalising answers *which territory is this?* Historical spellings map to today's id, so "Orissa" gives `odisha`. Resolving answers *what was it called in year Y?* and walks back to `orissa` for 1998. Because the two steps are separate, one table works for data from any year.
57
+
58
+ Other helpers:
59
+ - `origin_state("telangana")` gives `andhra-pradesh`: the state it was carved out of.
60
+ - `era_state_id("keralam", 2018)` gives `kerala`: renames only, it never folds a split back into its parent.
61
+ - `merge_group("dnh", 2021)` gives `dnhdd`: tells you two values must be combined into one. Whether you sum them or weight them is up to you.
62
+
63
+ ## Districts
64
+
65
+ ```python
66
+ from india_regions import match_district, district_candidates, district_for_year, district_by_lgd
67
+
68
+ match_district("Gurgaon", "Haryana", 2020)
69
+ # Match(id='gurugram-district', name='Gurugram', score=1.0, method='exact', state='haryana', in_year=True, via='gurgaon-district')
70
+
71
+ match_district("East Medinipur", "WB") # 'purba-medinipur-district' (Purba = East)
72
+ match_district("Thoothukudi", "Tamil Nadu") # 'thoothukkudi-district' (LGD spelling)
73
+ match_district("Mahabubnagar", "Telangana", 2012) # found under Andhra Pradesh, where it was in 2012
74
+
75
+ match_district("Aurangabad") # None: there's one in Bihar and one in Maharashtra
76
+ district_candidates("Aurangabad") # both, ranked
77
+
78
+ district_for_year("hapur-district", 2005) # ['ghaziabad-district'] (Hapur was carved out of it in 2011)
79
+ district_by_lgd(501) # Adilabad's record
80
+ ```
81
+
82
+ How matching works:
83
+ 1. Folding: ASCII only, no brackets, no "district". Uttar/Dakshin/Purba/Paschim count as North/South/East/West.
84
+ 2. Exact match against every name and old id a district has had.
85
+ 3. Spelling fold: aa/a, ee/i, oo/u, w/v, doubled letters.
86
+ 4. Fuzzy score, 0.85 cutoff by default.
87
+
88
+ A guard stops the classic false matches. "Garo Hills" never matches "West Garo Hills", and "Bangalore Urban" never matches "Bangalore Rural". When two districts fit equally well, `match_district` returns `None` rather than guessing.
89
+
90
+ JavaScript uses the same names in camelCase (`matchDistrict`, `resolveStateForYear`, ...). It reads the same data and gives the same answers, fuzzy scores included. CI checks this on every change.
91
+
92
+ ## Data
93
+
94
+ | File | What's in it |
95
+ |---|---|
96
+ | `states.json` | 83 states, UTs, provinces and princely units with the years they existed, the parent chain, renames, merges and 87 name aliases |
97
+ | `districts.json` | 959 districts across 1,149 periods (a district that moved state or was renamed has one period per spell), with LGD and Census 2011 codes, where each period came from and how it ended, and 809 dated change events with source links |
98
+
99
+ Rules the data follows:
100
+ - A change counts from the calendar year it takes effect.
101
+ - A rename gets a new id (`orissa` becomes `odisha`, `gurgaon-district` becomes `gurugram-district`).
102
+ - In a split, the parent keeps its id.
103
+ - A district that changes state keeps its id.
104
+
105
+ `last_year: null` means the unit still exists.
106
+
107
+ The data comes from TheMapsDaily's region tables, built from Census reports, LGD, state gazettes and the dated sources listed for each event. It's rebuilt with `scripts/export_from_tmd.py`, which refuses to write if any check fails.
108
+
109
+ **Not included:** map boundaries. Bring your own, and check how a boundary file draws India's border before you publish a map.
110
+
111
+ ## Licence
112
+
113
+ Code: MIT. Data: CC BY 4.0. Credit "TheMapsDaily (themapsdaily.com)" when you publish anything made with it. See `DATA_LICENSE.md`.
114
+
115
+ Found a district we've got wrong, or a spelling we don't catch? Open an issue with the source.
@@ -0,0 +1,93 @@
1
+ # india-regions
2
+
3
+ Indian data is full of state and district names that don't line up. "Orissa" in one table and "Odisha" in the next. "Gurgaon" in 2014 and "Gurugram" in 2020. "Telengana", "Chattisgarh", "Ladakh @", "Delhi (NCT)". Telangana figures that were part of Andhra Pradesh until 2014. A district called "Aurangabad" in two different states.
4
+
5
+ `india-regions` sorts this out in Python and JavaScript, with no dependencies:
6
+
7
+ - **Which state or district existed in which year.** States and UTs from 1947, including princely states and provinces. Districts from 1961.
8
+ - **Names to ids.** A label from any source, including the typos publishers really make, becomes one stable id.
9
+ - **The right unit for any year.** "Uttarakhand" in 1995 becomes Uttar Pradesh. "Allahabad" in 2020 becomes Prayagraj.
10
+ - **Codes.** LGD and Census 2011 district codes, plus short state codes such as `UP`, `TN` and `OD`.
11
+
12
+ ```
13
+ pip install india-regions
14
+ npm install india-regions
15
+ ```
16
+
17
+ ## States
18
+
19
+ ```python
20
+ from india_regions import normalize_state, normalize_region, resolve_state_for_year, match_state
21
+
22
+ normalize_state("ODISHA #") # 'odisha' (footnote marks dropped)
23
+ normalize_state("Telengana") # 'telangana' (known typo)
24
+ normalize_state("UP") # 'uttar-pradesh'
25
+
26
+ normalize_region("Orissa", 1998) # 'orissa' the id that year
27
+ normalize_region("Uttarakhand", 1995) # 'uttar-pradesh' (two hops: Uttaranchal, then UP)
28
+ resolve_state_for_year("telangana", 1950) # 'hyderabad-state'
29
+ resolve_state_for_year("dnh", 2021) # 'dnhdd' (merged in 2020)
30
+
31
+ match_state("Utter Pradesh") # Match(id='uttar-pradesh', score=0.9091, method='fuzzy', ...)
32
+ ```
33
+
34
+ Normalising answers *which territory is this?* Historical spellings map to today's id, so "Orissa" gives `odisha`. Resolving answers *what was it called in year Y?* and walks back to `orissa` for 1998. Because the two steps are separate, one table works for data from any year.
35
+
36
+ Other helpers:
37
+ - `origin_state("telangana")` gives `andhra-pradesh`: the state it was carved out of.
38
+ - `era_state_id("keralam", 2018)` gives `kerala`: renames only, it never folds a split back into its parent.
39
+ - `merge_group("dnh", 2021)` gives `dnhdd`: tells you two values must be combined into one. Whether you sum them or weight them is up to you.
40
+
41
+ ## Districts
42
+
43
+ ```python
44
+ from india_regions import match_district, district_candidates, district_for_year, district_by_lgd
45
+
46
+ match_district("Gurgaon", "Haryana", 2020)
47
+ # Match(id='gurugram-district', name='Gurugram', score=1.0, method='exact', state='haryana', in_year=True, via='gurgaon-district')
48
+
49
+ match_district("East Medinipur", "WB") # 'purba-medinipur-district' (Purba = East)
50
+ match_district("Thoothukudi", "Tamil Nadu") # 'thoothukkudi-district' (LGD spelling)
51
+ match_district("Mahabubnagar", "Telangana", 2012) # found under Andhra Pradesh, where it was in 2012
52
+
53
+ match_district("Aurangabad") # None: there's one in Bihar and one in Maharashtra
54
+ district_candidates("Aurangabad") # both, ranked
55
+
56
+ district_for_year("hapur-district", 2005) # ['ghaziabad-district'] (Hapur was carved out of it in 2011)
57
+ district_by_lgd(501) # Adilabad's record
58
+ ```
59
+
60
+ How matching works:
61
+ 1. Folding: ASCII only, no brackets, no "district". Uttar/Dakshin/Purba/Paschim count as North/South/East/West.
62
+ 2. Exact match against every name and old id a district has had.
63
+ 3. Spelling fold: aa/a, ee/i, oo/u, w/v, doubled letters.
64
+ 4. Fuzzy score, 0.85 cutoff by default.
65
+
66
+ A guard stops the classic false matches. "Garo Hills" never matches "West Garo Hills", and "Bangalore Urban" never matches "Bangalore Rural". When two districts fit equally well, `match_district` returns `None` rather than guessing.
67
+
68
+ JavaScript uses the same names in camelCase (`matchDistrict`, `resolveStateForYear`, ...). It reads the same data and gives the same answers, fuzzy scores included. CI checks this on every change.
69
+
70
+ ## Data
71
+
72
+ | File | What's in it |
73
+ |---|---|
74
+ | `states.json` | 83 states, UTs, provinces and princely units with the years they existed, the parent chain, renames, merges and 87 name aliases |
75
+ | `districts.json` | 959 districts across 1,149 periods (a district that moved state or was renamed has one period per spell), with LGD and Census 2011 codes, where each period came from and how it ended, and 809 dated change events with source links |
76
+
77
+ Rules the data follows:
78
+ - A change counts from the calendar year it takes effect.
79
+ - A rename gets a new id (`orissa` becomes `odisha`, `gurgaon-district` becomes `gurugram-district`).
80
+ - In a split, the parent keeps its id.
81
+ - A district that changes state keeps its id.
82
+
83
+ `last_year: null` means the unit still exists.
84
+
85
+ The data comes from TheMapsDaily's region tables, built from Census reports, LGD, state gazettes and the dated sources listed for each event. It's rebuilt with `scripts/export_from_tmd.py`, which refuses to write if any check fails.
86
+
87
+ **Not included:** map boundaries. Bring your own, and check how a boundary file draws India's border before you publish a map.
88
+
89
+ ## Licence
90
+
91
+ Code: MIT. Data: CC BY 4.0. Credit "TheMapsDaily (themapsdaily.com)" when you publish anything made with it. See `DATA_LICENSE.md`.
92
+
93
+ Found a district we've got wrong, or a spelling we don't catch? Open an issue with the source.
@@ -0,0 +1,40 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.25"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "india-regions"
7
+ version = "0.1.0"
8
+ description = "India's states and districts through time: which existed in which year, LGD/Census codes, and matching for messy or misspelt names."
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = { text = "MIT (code), CC-BY-4.0 (data)" }
12
+ authors = [{ name = "TheMapsDaily" }]
13
+ keywords = ["india", "states", "districts", "lgd", "census", "geography", "data-cleaning", "fuzzy-matching"]
14
+ classifiers = [
15
+ "License :: OSI Approved :: MIT License",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Programming Language :: Python :: 3.14",
21
+ "Programming Language :: Python :: 3.15",
22
+ "Topic :: Scientific/Engineering :: GIS",
23
+ "Intended Audience :: Science/Research",
24
+ ]
25
+ dependencies = []
26
+
27
+ [project.urls]
28
+ Homepage = "https://themapsdaily.com"
29
+ Source = "https://github.com/themapsdaily/india-regions"
30
+
31
+ [tool.hatch.build.targets.wheel]
32
+ packages = ["src/india_regions"]
33
+
34
+ [tool.hatch.build.targets.sdist]
35
+ include = ["src/india_regions", "tests", "README.md", "LICENSE", "DATA_LICENSE.md"]
36
+
37
+ [tool.pytest.ini_options]
38
+ pythonpath = ["src"]
39
+ addopts = "--doctest-modules"
40
+ testpaths = ["tests", "src"]
@@ -0,0 +1,50 @@
1
+ """india-regions: India's states and districts through time.
2
+
3
+ >>> from india_regions import normalize_region, match_district
4
+ >>> normalize_region("Orissa", 1998)
5
+ 'orissa'
6
+ >>> match_district("Gurgaon", "Haryana", 2020).id
7
+ 'gurugram-district'
8
+ """
9
+
10
+ from ._core import ( # noqa: F401
11
+ DATA_VERSION,
12
+ DIRECTION_WORDS,
13
+ DISTRICT_ALIASES,
14
+ DISTRICT_EVENTS,
15
+ DISTRICT_SUCCESSOR,
16
+ DISTRICTS,
17
+ MERGES,
18
+ PARENT,
19
+ PARENT_BEFORE,
20
+ RENAMED_FROM,
21
+ STATE_ALIASES,
22
+ STATES,
23
+ SUCCESSOR,
24
+ Match,
25
+ district_by_census2011,
26
+ district_by_lgd,
27
+ district_candidates,
28
+ district_for_year,
29
+ district_periods,
30
+ districts_in_year,
31
+ era_state_id,
32
+ get_district,
33
+ get_state,
34
+ is_valid_in_year,
35
+ match_district,
36
+ match_districts,
37
+ match_state,
38
+ merge_group,
39
+ normalize_district_key,
40
+ normalize_region,
41
+ normalize_state,
42
+ normalize_state_key,
43
+ origin_state,
44
+ resolve_state_for_year,
45
+ same_territory,
46
+ similarity,
47
+ states_in_year,
48
+ )
49
+
50
+ __version__ = "0.1.0"