tuik 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.
- tuik-0.1.0/.gitignore +9 -0
- tuik-0.1.0/LICENSE +21 -0
- tuik-0.1.0/PKG-INFO +186 -0
- tuik-0.1.0/README.md +148 -0
- tuik-0.1.0/README.tr.md +148 -0
- tuik-0.1.0/pyproject.toml +65 -0
- tuik-0.1.0/src/tuik/__init__.py +36 -0
- tuik-0.1.0/src/tuik/_cache.py +91 -0
- tuik-0.1.0/src/tuik/_fetch.py +123 -0
- tuik-0.1.0/src/tuik/_http.py +140 -0
- tuik-0.1.0/src/tuik/_text.py +45 -0
- tuik-0.1.0/src/tuik/_validate.py +102 -0
- tuik-0.1.0/src/tuik/_version.py +1 -0
- tuik-0.1.0/src/tuik/_warn.py +20 -0
- tuik-0.1.0/src/tuik/cite.py +39 -0
- tuik-0.1.0/src/tuik/data/historical.csv +8 -0
- tuik-0.1.0/src/tuik/data/provinces.csv +82 -0
- tuik-0.1.0/src/tuik/errors.py +29 -0
- tuik-0.1.0/src/tuik/migration.py +172 -0
- tuik-0.1.0/src/tuik/population.py +197 -0
- tuik-0.1.0/src/tuik/provinces.py +110 -0
- tuik-0.1.0/src/tuik/py.typed +0 -0
tuik-0.1.0/.gitignore
ADDED
tuik-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Arda Eren Canpolat
|
|
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.
|
tuik-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: tuik
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Unofficial Python client for TÜİK (Turkish Statistical Institute) population and migration data
|
|
5
|
+
Project-URL: Homepage, https://github.com/ardaggec17-byte/tuik
|
|
6
|
+
Project-URL: Source, https://github.com/ardaggec17-byte/tuik
|
|
7
|
+
Project-URL: Issues, https://github.com/ardaggec17-byte/tuik/issues
|
|
8
|
+
Author: Arda Eren Canpolat
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Natural Language :: Turkish
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Requires-Dist: lxml>=4.9
|
|
23
|
+
Requires-Dist: pandas>=2.0
|
|
24
|
+
Requires-Dist: platformdirs>=3
|
|
25
|
+
Requires-Dist: requests>=2.31
|
|
26
|
+
Requires-Dist: tqdm>=4.60
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: mypy; extra == 'dev'
|
|
29
|
+
Requires-Dist: pandas-stubs; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
31
|
+
Requires-Dist: responses; extra == 'dev'
|
|
32
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
33
|
+
Requires-Dist: types-requests; extra == 'dev'
|
|
34
|
+
Requires-Dist: types-tqdm; extra == 'dev'
|
|
35
|
+
Provides-Extra: examples
|
|
36
|
+
Requires-Dist: matplotlib; extra == 'examples'
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
|
|
39
|
+
# tuik
|
|
40
|
+
|
|
41
|
+
[Türkçe](https://github.com/ardaggec17-byte/tuik/blob/main/README.tr.md) | English
|
|
42
|
+
|
|
43
|
+
Unofficial Python client for TÜİK (Turkish Statistical Institute) population and migration data.
|
|
44
|
+
|
|
45
|
+
> This is an unofficial project. It is not affiliated with, endorsed by, or connected to TÜİK (Turkish Statistical Institute).
|
|
46
|
+
|
|
47
|
+
[](https://pypi.org/project/tuik/)
|
|
48
|
+
[](https://pypi.org/project/tuik/)
|
|
49
|
+
[](https://github.com/ardaggec17-byte/tuik/actions/workflows/ci.yml)
|
|
50
|
+
[](https://github.com/ardaggec17-byte/tuik/actions/workflows/live.yml)
|
|
51
|
+
|
|
52
|
+

|
|
53
|
+
|
|
54
|
+
## Install
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install tuik
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Requires Python 3.10 or newer. Data is downloaded from TÜİK on first use; no TÜİK statistics are bundled with the package.
|
|
61
|
+
|
|
62
|
+
## Usage
|
|
63
|
+
|
|
64
|
+
### `tuik.migration()`
|
|
65
|
+
|
|
66
|
+
Province-to-province internal migration, one row per origin/destination pair per year (2008 onwards).
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
import tuik
|
|
70
|
+
|
|
71
|
+
tuik.migration(year=2024, origin="Adana").head()
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
year origin_code origin destination_code destination migrants
|
|
76
|
+
0 2024 1 Adana 2 Adıyaman 755
|
|
77
|
+
1 2024 1 Adana 3 Afyonkarahisar 252
|
|
78
|
+
2 2024 1 Adana 4 Ağrı 137
|
|
79
|
+
3 2024 1 Adana 5 Amasya 122
|
|
80
|
+
4 2024 1 Adana 6 Ankara 3684
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Use `format="matrix"` with a single `year` for an 81 x 81 origin-by-destination matrix.
|
|
84
|
+
|
|
85
|
+
### `tuik.population()`
|
|
86
|
+
|
|
87
|
+
Total, male and female population. By default only the Türkiye total; `province="all"` returns all provinces, or pass names / plate codes.
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
tuik.population().head()
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
year level province_code province total male female
|
|
95
|
+
0 1927 country <NA> Türkiye 13648270 6563879 7084391
|
|
96
|
+
1 1935 country <NA> Türkiye 16158018 7936770 8221248
|
|
97
|
+
2 1940 country <NA> Türkiye 17820950 8898912 8922038
|
|
98
|
+
3 1945 country <NA> Türkiye 18790174 9446580 9343594
|
|
99
|
+
4 1950 country <NA> Türkiye 20947188 10527085 10420103
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
tuik.population(province="all", year=2024).head()
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
year level province_code province total male female
|
|
108
|
+
0 2024 province 1 Adana 2280484 1140836 1139648
|
|
109
|
+
1 2024 province 2 Adıyaman 611037 309540 301497
|
|
110
|
+
2 2024 province 3 Afyonkarahisar 750193 375263 374930
|
|
111
|
+
3 2024 province 4 Ağrı 499801 258828 240973
|
|
112
|
+
4 2024 province 5 Amasya 342378 171766 170612
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### `tuik.population_by_age()`
|
|
116
|
+
|
|
117
|
+
Population of Türkiye by five-year age group.
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
tuik.population_by_age(year=2024).head()
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
year age_group age_min total male female
|
|
125
|
+
0 2024 0-4 0 5082386 2606763 2475623
|
|
126
|
+
1 2024 5-9 5 6385085 3274360 3110725
|
|
127
|
+
2 2024 10-14 10 6459094 3314979 3144115
|
|
128
|
+
3 2024 15-19 15 6428530 3298654 3129876
|
|
129
|
+
4 2024 20-24 20 6334629 3235130 3099499
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### `tuik.provinces()`
|
|
133
|
+
|
|
134
|
+
Static reference list of the 81 provinces (plate code, name, TÜİK upper-case spelling, NUTS codes). Province arguments elsewhere accept names (case- and Turkish-character-insensitive) or plate codes.
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
tuik.provinces().head()
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
code name name_upper nuts1 nuts2 nuts3
|
|
142
|
+
0 1 Adana ADANA TR6 TR62 TR621
|
|
143
|
+
1 2 Adıyaman ADIYAMAN TRC TRC1 TRC12
|
|
144
|
+
2 3 Afyonkarahisar AFYONKARAHİSAR TR3 TR33 TR332
|
|
145
|
+
3 4 Ağrı AĞRI TRA TRA2 TRA21
|
|
146
|
+
4 5 Amasya AMASYA TR8 TR83 TR834
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
A full walk-through, including the chart above, is in [`examples/internal_migration.ipynb`](https://github.com/ardaggec17-byte/tuik/blob/main/examples/internal_migration.ipynb) (`pip install "tuik[examples]"` for matplotlib).
|
|
150
|
+
|
|
151
|
+
## Caching
|
|
152
|
+
|
|
153
|
+
Downloaded responses are cached on disk (`platformdirs` user cache directory, e.g. `%LOCALAPPDATA%\tuik\Cache` on Windows) and reused for 7 days.
|
|
154
|
+
|
|
155
|
+
- `refresh=True` ignores the cache and downloads again.
|
|
156
|
+
- `tuik.clear_cache()` deletes all cached files.
|
|
157
|
+
- `TUIK_CACHE_DIR` overrides the cache location.
|
|
158
|
+
- The migration download takes about 1-2 minutes and shows a progress bar; set `TUIK_PROGRESS=0` to turn it off.
|
|
159
|
+
- If TÜİK cannot be reached and an expired cache exists, the old data is returned with a warning.
|
|
160
|
+
|
|
161
|
+
Every result carries provenance in `df.attrs` (`source`, `source_url`, `retrieved_at`, `tuik_version`).
|
|
162
|
+
|
|
163
|
+
## Data notes
|
|
164
|
+
|
|
165
|
+
- Before 2007 only census years are available (1927, 1935, 1940, ..., 1990, 2000); from 2007 on the data is annual. Missing years are not filled in.
|
|
166
|
+
- Provinces are historical: 62 in 1927, 73 in 1990, 81 from 2000. Old names are mapped to today's provinces (e.g. İçel to Mersin); abolished units keep TÜİK's name with an empty `province_code`.
|
|
167
|
+
- The source itself is inconsistent in places (for example the 1960 Amasya figures). The package does not correct or hide such data; it emits a `TuikDataWarning` for unexpected inconsistencies, and known exceptions are listed in the code. Structural changes in TÜİK's responses raise `TuikResponseError`.
|
|
168
|
+
- Data is downloaded from TÜİK's population portal at use time; no TÜİK statistics are bundled.
|
|
169
|
+
- Errors and warnings: `TuikError` (base), `TuikConnectionError`, `TuikResponseError`, `ProvinceNotFoundError` and `TuikDataWarning` can be imported directly from `tuik`, e.g. `from tuik import TuikResponseError`.
|
|
170
|
+
|
|
171
|
+
## Citing
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
tuik.cite() # cite the package
|
|
175
|
+
tuik.cite(df) # also credit the TÜİK source and retrieval date of a result
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
See also [`CITATION.cff`](https://github.com/ardaggec17-byte/tuik/blob/main/CITATION.cff).
|
|
179
|
+
|
|
180
|
+
## See also
|
|
181
|
+
|
|
182
|
+
For TÜİK's general catalog see [pytuik](https://pypi.org/project/pytuik/).
|
|
183
|
+
|
|
184
|
+
## License
|
|
185
|
+
|
|
186
|
+
MIT, see [LICENSE](https://github.com/ardaggec17-byte/tuik/blob/main/LICENSE).
|
tuik-0.1.0/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# tuik
|
|
2
|
+
|
|
3
|
+
[Türkçe](https://github.com/ardaggec17-byte/tuik/blob/main/README.tr.md) | English
|
|
4
|
+
|
|
5
|
+
Unofficial Python client for TÜİK (Turkish Statistical Institute) population and migration data.
|
|
6
|
+
|
|
7
|
+
> This is an unofficial project. It is not affiliated with, endorsed by, or connected to TÜİK (Turkish Statistical Institute).
|
|
8
|
+
|
|
9
|
+
[](https://pypi.org/project/tuik/)
|
|
10
|
+
[](https://pypi.org/project/tuik/)
|
|
11
|
+
[](https://github.com/ardaggec17-byte/tuik/actions/workflows/ci.yml)
|
|
12
|
+
[](https://github.com/ardaggec17-byte/tuik/actions/workflows/live.yml)
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install tuik
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Requires Python 3.10 or newer. Data is downloaded from TÜİK on first use; no TÜİK statistics are bundled with the package.
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### `tuik.migration()`
|
|
27
|
+
|
|
28
|
+
Province-to-province internal migration, one row per origin/destination pair per year (2008 onwards).
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
import tuik
|
|
32
|
+
|
|
33
|
+
tuik.migration(year=2024, origin="Adana").head()
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
year origin_code origin destination_code destination migrants
|
|
38
|
+
0 2024 1 Adana 2 Adıyaman 755
|
|
39
|
+
1 2024 1 Adana 3 Afyonkarahisar 252
|
|
40
|
+
2 2024 1 Adana 4 Ağrı 137
|
|
41
|
+
3 2024 1 Adana 5 Amasya 122
|
|
42
|
+
4 2024 1 Adana 6 Ankara 3684
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Use `format="matrix"` with a single `year` for an 81 x 81 origin-by-destination matrix.
|
|
46
|
+
|
|
47
|
+
### `tuik.population()`
|
|
48
|
+
|
|
49
|
+
Total, male and female population. By default only the Türkiye total; `province="all"` returns all provinces, or pass names / plate codes.
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
tuik.population().head()
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
year level province_code province total male female
|
|
57
|
+
0 1927 country <NA> Türkiye 13648270 6563879 7084391
|
|
58
|
+
1 1935 country <NA> Türkiye 16158018 7936770 8221248
|
|
59
|
+
2 1940 country <NA> Türkiye 17820950 8898912 8922038
|
|
60
|
+
3 1945 country <NA> Türkiye 18790174 9446580 9343594
|
|
61
|
+
4 1950 country <NA> Türkiye 20947188 10527085 10420103
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
tuik.population(province="all", year=2024).head()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
year level province_code province total male female
|
|
70
|
+
0 2024 province 1 Adana 2280484 1140836 1139648
|
|
71
|
+
1 2024 province 2 Adıyaman 611037 309540 301497
|
|
72
|
+
2 2024 province 3 Afyonkarahisar 750193 375263 374930
|
|
73
|
+
3 2024 province 4 Ağrı 499801 258828 240973
|
|
74
|
+
4 2024 province 5 Amasya 342378 171766 170612
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### `tuik.population_by_age()`
|
|
78
|
+
|
|
79
|
+
Population of Türkiye by five-year age group.
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
tuik.population_by_age(year=2024).head()
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
year age_group age_min total male female
|
|
87
|
+
0 2024 0-4 0 5082386 2606763 2475623
|
|
88
|
+
1 2024 5-9 5 6385085 3274360 3110725
|
|
89
|
+
2 2024 10-14 10 6459094 3314979 3144115
|
|
90
|
+
3 2024 15-19 15 6428530 3298654 3129876
|
|
91
|
+
4 2024 20-24 20 6334629 3235130 3099499
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### `tuik.provinces()`
|
|
95
|
+
|
|
96
|
+
Static reference list of the 81 provinces (plate code, name, TÜİK upper-case spelling, NUTS codes). Province arguments elsewhere accept names (case- and Turkish-character-insensitive) or plate codes.
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
tuik.provinces().head()
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
code name name_upper nuts1 nuts2 nuts3
|
|
104
|
+
0 1 Adana ADANA TR6 TR62 TR621
|
|
105
|
+
1 2 Adıyaman ADIYAMAN TRC TRC1 TRC12
|
|
106
|
+
2 3 Afyonkarahisar AFYONKARAHİSAR TR3 TR33 TR332
|
|
107
|
+
3 4 Ağrı AĞRI TRA TRA2 TRA21
|
|
108
|
+
4 5 Amasya AMASYA TR8 TR83 TR834
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
A full walk-through, including the chart above, is in [`examples/internal_migration.ipynb`](https://github.com/ardaggec17-byte/tuik/blob/main/examples/internal_migration.ipynb) (`pip install "tuik[examples]"` for matplotlib).
|
|
112
|
+
|
|
113
|
+
## Caching
|
|
114
|
+
|
|
115
|
+
Downloaded responses are cached on disk (`platformdirs` user cache directory, e.g. `%LOCALAPPDATA%\tuik\Cache` on Windows) and reused for 7 days.
|
|
116
|
+
|
|
117
|
+
- `refresh=True` ignores the cache and downloads again.
|
|
118
|
+
- `tuik.clear_cache()` deletes all cached files.
|
|
119
|
+
- `TUIK_CACHE_DIR` overrides the cache location.
|
|
120
|
+
- The migration download takes about 1-2 minutes and shows a progress bar; set `TUIK_PROGRESS=0` to turn it off.
|
|
121
|
+
- If TÜİK cannot be reached and an expired cache exists, the old data is returned with a warning.
|
|
122
|
+
|
|
123
|
+
Every result carries provenance in `df.attrs` (`source`, `source_url`, `retrieved_at`, `tuik_version`).
|
|
124
|
+
|
|
125
|
+
## Data notes
|
|
126
|
+
|
|
127
|
+
- Before 2007 only census years are available (1927, 1935, 1940, ..., 1990, 2000); from 2007 on the data is annual. Missing years are not filled in.
|
|
128
|
+
- Provinces are historical: 62 in 1927, 73 in 1990, 81 from 2000. Old names are mapped to today's provinces (e.g. İçel to Mersin); abolished units keep TÜİK's name with an empty `province_code`.
|
|
129
|
+
- The source itself is inconsistent in places (for example the 1960 Amasya figures). The package does not correct or hide such data; it emits a `TuikDataWarning` for unexpected inconsistencies, and known exceptions are listed in the code. Structural changes in TÜİK's responses raise `TuikResponseError`.
|
|
130
|
+
- Data is downloaded from TÜİK's population portal at use time; no TÜİK statistics are bundled.
|
|
131
|
+
- Errors and warnings: `TuikError` (base), `TuikConnectionError`, `TuikResponseError`, `ProvinceNotFoundError` and `TuikDataWarning` can be imported directly from `tuik`, e.g. `from tuik import TuikResponseError`.
|
|
132
|
+
|
|
133
|
+
## Citing
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
tuik.cite() # cite the package
|
|
137
|
+
tuik.cite(df) # also credit the TÜİK source and retrieval date of a result
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
See also [`CITATION.cff`](https://github.com/ardaggec17-byte/tuik/blob/main/CITATION.cff).
|
|
141
|
+
|
|
142
|
+
## See also
|
|
143
|
+
|
|
144
|
+
For TÜİK's general catalog see [pytuik](https://pypi.org/project/pytuik/).
|
|
145
|
+
|
|
146
|
+
## License
|
|
147
|
+
|
|
148
|
+
MIT, see [LICENSE](https://github.com/ardaggec17-byte/tuik/blob/main/LICENSE).
|
tuik-0.1.0/README.tr.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# tuik
|
|
2
|
+
|
|
3
|
+
Türkçe | [English](https://github.com/ardaggec17-byte/tuik/blob/main/README.md)
|
|
4
|
+
|
|
5
|
+
TÜİK (Türkiye İstatistik Kurumu) nüfus ve göç verileri için resmi olmayan Python istemcisi.
|
|
6
|
+
|
|
7
|
+
> Bu proje resmî değildir. TÜİK (Türkiye İstatistik Kurumu) ile ilgisi veya bağlantısı yoktur; TÜİK tarafından desteklenmemekte ya da onaylanmamaktadır.
|
|
8
|
+
|
|
9
|
+
[](https://pypi.org/project/tuik/)
|
|
10
|
+
[](https://pypi.org/project/tuik/)
|
|
11
|
+
[](https://github.com/ardaggec17-byte/tuik/actions/workflows/ci.yml)
|
|
12
|
+
[](https://github.com/ardaggec17-byte/tuik/actions/workflows/live.yml)
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
## Kurulum
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install tuik
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Python 3.10 veya üstü gerekir. Veri ilk kullanımda TÜİK'ten indirilir; pakete hiçbir TÜİK istatistiği gömülü değildir.
|
|
23
|
+
|
|
24
|
+
## Kullanım
|
|
25
|
+
|
|
26
|
+
### `tuik.migration()`
|
|
27
|
+
|
|
28
|
+
İller arası göç: her yıl için her çıkış/varış il çifti başına bir satır (2008'den itibaren).
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
import tuik
|
|
32
|
+
|
|
33
|
+
tuik.migration(year=2024, origin="Adana").head()
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
year origin_code origin destination_code destination migrants
|
|
38
|
+
0 2024 1 Adana 2 Adıyaman 755
|
|
39
|
+
1 2024 1 Adana 3 Afyonkarahisar 252
|
|
40
|
+
2 2024 1 Adana 4 Ağrı 137
|
|
41
|
+
3 2024 1 Adana 5 Amasya 122
|
|
42
|
+
4 2024 1 Adana 6 Ankara 3684
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Tek bir `year` ile birlikte `format="matrix"` kullanırsanız 81 x 81 çıkış-varış matrisi elde edersiniz.
|
|
46
|
+
|
|
47
|
+
### `tuik.population()`
|
|
48
|
+
|
|
49
|
+
Toplam, erkek ve kadın nüfus. Varsayılan olarak yalnızca Türkiye toplamı gelir; `province="all"` tüm illeri getirir, ayrıca il adı veya plaka kodu verebilirsiniz.
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
tuik.population().head()
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
year level province_code province total male female
|
|
57
|
+
0 1927 country <NA> Türkiye 13648270 6563879 7084391
|
|
58
|
+
1 1935 country <NA> Türkiye 16158018 7936770 8221248
|
|
59
|
+
2 1940 country <NA> Türkiye 17820950 8898912 8922038
|
|
60
|
+
3 1945 country <NA> Türkiye 18790174 9446580 9343594
|
|
61
|
+
4 1950 country <NA> Türkiye 20947188 10527085 10420103
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
tuik.population(province="all", year=2024).head()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
year level province_code province total male female
|
|
70
|
+
0 2024 province 1 Adana 2280484 1140836 1139648
|
|
71
|
+
1 2024 province 2 Adıyaman 611037 309540 301497
|
|
72
|
+
2 2024 province 3 Afyonkarahisar 750193 375263 374930
|
|
73
|
+
3 2024 province 4 Ağrı 499801 258828 240973
|
|
74
|
+
4 2024 province 5 Amasya 342378 171766 170612
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### `tuik.population_by_age()`
|
|
78
|
+
|
|
79
|
+
Türkiye nüfusu, beşer yıllık yaş gruplarına göre.
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
tuik.population_by_age(year=2024).head()
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
year age_group age_min total male female
|
|
87
|
+
0 2024 0-4 0 5082386 2606763 2475623
|
|
88
|
+
1 2024 5-9 5 6385085 3274360 3110725
|
|
89
|
+
2 2024 10-14 10 6459094 3314979 3144115
|
|
90
|
+
3 2024 15-19 15 6428530 3298654 3129876
|
|
91
|
+
4 2024 20-24 20 6334629 3235130 3099499
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### `tuik.provinces()`
|
|
95
|
+
|
|
96
|
+
81 ilin statik referans listesi (plaka kodu, ad, TÜİK'in büyük harfli yazımı, İBBS kodları). Diğer fonksiyonlarda il argümanı olarak ad (büyük/küçük harf ve Türkçe karakter duyarsız) veya plaka kodu verilebilir.
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
tuik.provinces().head()
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
code name name_upper nuts1 nuts2 nuts3
|
|
104
|
+
0 1 Adana ADANA TR6 TR62 TR621
|
|
105
|
+
1 2 Adıyaman ADIYAMAN TRC TRC1 TRC12
|
|
106
|
+
2 3 Afyonkarahisar AFYONKARAHİSAR TR3 TR33 TR332
|
|
107
|
+
3 4 Ağrı AĞRI TRA TRA2 TRA21
|
|
108
|
+
4 5 Amasya AMASYA TR8 TR83 TR834
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Yukarıdaki grafiği de içeren tam örnek [`examples/internal_migration.ipynb`](https://github.com/ardaggec17-byte/tuik/blob/main/examples/internal_migration.ipynb) dosyasındadır (matplotlib için `pip install "tuik[examples]"`).
|
|
112
|
+
|
|
113
|
+
## Önbellek
|
|
114
|
+
|
|
115
|
+
İndirilen yanıtlar diskte saklanır (`platformdirs` kullanıcı önbellek dizini; Windows'ta örneğin `%LOCALAPPDATA%\tuik\Cache`) ve 7 gün boyunca yeniden kullanılır.
|
|
116
|
+
|
|
117
|
+
- `refresh=True` önbelleği yok sayar ve yeniden indirir.
|
|
118
|
+
- `tuik.clear_cache()` tüm önbellek dosyalarını siler.
|
|
119
|
+
- `TUIK_CACHE_DIR` ortam değişkeni önbellek konumunu değiştirir.
|
|
120
|
+
- Göç verisinin indirilmesi yaklaşık 1-2 dakika sürer ve ilerleme çubuğu gösterir; kapatmak için `TUIK_PROGRESS=0` kullanın.
|
|
121
|
+
- TÜİK'e ulaşılamazsa ve süresi dolmuş bir önbellek varsa, eski veri uyarıyla birlikte döndürülür.
|
|
122
|
+
|
|
123
|
+
Her sonuç, kaynak bilgisini `df.attrs` içinde taşır (`source`, `source_url`, `retrieved_at`, `tuik_version`).
|
|
124
|
+
|
|
125
|
+
## Veri notları
|
|
126
|
+
|
|
127
|
+
- 2007'den önce yalnızca sayım yılları vardır (1927, 1935, 1940, ..., 1990, 2000); 2007'den itibaren veri yıllıktır. Eksik yıllar doldurulmaz.
|
|
128
|
+
- İl yapısı tarihîdir: 1927'de 62, 1990'da 73, 2000'den itibaren 81 il. Eski adlar bugünkü illerle eşlenir (örneğin İçel, Mersin olur); kaldırılmış birimler TÜİK'teki adıyla ve boş `province_code` ile tutulur.
|
|
129
|
+
- Kaynağın kendisi bazı yerlerde tutarsızdır (örneğin 1960 Amasya rakamları). Paket bu verileri düzeltmez ya da gizlemez; beklenmeyen tutarsızlıklarda `TuikDataWarning` uyarısı verir, bilinen istisnalar kodda listelenir. TÜİK yanıtlarında yapısal bir değişiklik olursa `TuikResponseError` fırlatılır.
|
|
130
|
+
- Veri, kullanım anında TÜİK'in nüfus portalından indirilir; pakete TÜİK istatistiği gömülü değildir.
|
|
131
|
+
- Hatalar ve uyarılar: `TuikError` (temel sınıf), `TuikConnectionError`, `TuikResponseError`, `ProvinceNotFoundError` ve `TuikDataWarning` doğrudan `tuik` paketinden içe aktarılabilir, örneğin `from tuik import TuikResponseError`.
|
|
132
|
+
|
|
133
|
+
## Atıf
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
tuik.cite() # paket için atıf metni üretir
|
|
137
|
+
tuik.cite(df) # ayrıca bir sonucun TÜİK kaynağını ve erişim tarihini belirtir
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Ayrıca bkz. [`CITATION.cff`](https://github.com/ardaggec17-byte/tuik/blob/main/CITATION.cff).
|
|
141
|
+
|
|
142
|
+
## Ayrıca bakınız
|
|
143
|
+
|
|
144
|
+
TÜİK'in genel kataloğuna erişim için [pytuik](https://pypi.org/project/pytuik/) paketine bakın.
|
|
145
|
+
|
|
146
|
+
## Lisans
|
|
147
|
+
|
|
148
|
+
MIT, bkz. [LICENSE](https://github.com/ardaggec17-byte/tuik/blob/main/LICENSE).
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tuik"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Unofficial Python client for TÜİK (Turkish Statistical Institute) population and migration data"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Arda Eren Canpolat" }]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
16
|
+
"Programming Language :: Python :: 3.10",
|
|
17
|
+
"Programming Language :: Python :: 3.11",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Intended Audience :: Science/Research",
|
|
22
|
+
"Topic :: Scientific/Engineering :: Information Analysis",
|
|
23
|
+
"Natural Language :: English",
|
|
24
|
+
"Natural Language :: Turkish",
|
|
25
|
+
]
|
|
26
|
+
dependencies = [
|
|
27
|
+
"pandas>=2.0",
|
|
28
|
+
"requests>=2.31",
|
|
29
|
+
"lxml>=4.9",
|
|
30
|
+
"platformdirs>=3",
|
|
31
|
+
"tqdm>=4.60",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
dev = ["pytest", "responses", "ruff", "mypy", "pandas-stubs", "types-requests", "types-tqdm"]
|
|
36
|
+
examples = ["matplotlib"]
|
|
37
|
+
|
|
38
|
+
[project.urls]
|
|
39
|
+
Homepage = "https://github.com/ardaggec17-byte/tuik"
|
|
40
|
+
Source = "https://github.com/ardaggec17-byte/tuik"
|
|
41
|
+
Issues = "https://github.com/ardaggec17-byte/tuik/issues"
|
|
42
|
+
|
|
43
|
+
[tool.hatch.version]
|
|
44
|
+
path = "src/tuik/_version.py"
|
|
45
|
+
|
|
46
|
+
[tool.hatch.build.targets.wheel]
|
|
47
|
+
packages = ["src/tuik"]
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.sdist]
|
|
50
|
+
include = ["src/tuik/**/*.py", "src/tuik/py.typed", "src/tuik/data/*.csv", "README*.md", "LICENSE"]
|
|
51
|
+
|
|
52
|
+
[tool.pytest.ini_options]
|
|
53
|
+
testpaths = ["tests"]
|
|
54
|
+
pythonpath = ["src"]
|
|
55
|
+
markers = ["live: hits real TÜİK servers"]
|
|
56
|
+
addopts = "-m 'not live'"
|
|
57
|
+
|
|
58
|
+
[tool.ruff]
|
|
59
|
+
line-length = 100
|
|
60
|
+
extend-exclude = ["docs", ".superpowers"]
|
|
61
|
+
src = ["src", "tests"]
|
|
62
|
+
|
|
63
|
+
[tool.mypy]
|
|
64
|
+
files = ["src"]
|
|
65
|
+
strict = true
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Unofficial Python client for TÜİK (Turkish Statistical Institute) data."""
|
|
2
|
+
|
|
3
|
+
from tuik import _cache
|
|
4
|
+
from tuik._version import __version__
|
|
5
|
+
from tuik.cite import cite
|
|
6
|
+
from tuik.errors import (
|
|
7
|
+
ProvinceNotFoundError,
|
|
8
|
+
TuikConnectionError,
|
|
9
|
+
TuikDataWarning,
|
|
10
|
+
TuikError,
|
|
11
|
+
TuikResponseError,
|
|
12
|
+
)
|
|
13
|
+
from tuik.migration import migration
|
|
14
|
+
from tuik.population import population, population_by_age
|
|
15
|
+
from tuik.provinces import provinces
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def clear_cache() -> None:
|
|
19
|
+
"""Delete all cached TÜİK downloads."""
|
|
20
|
+
_cache.clear()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
__all__ = [ # noqa: RUF022 - order is part of the documented public API
|
|
24
|
+
"migration",
|
|
25
|
+
"population",
|
|
26
|
+
"population_by_age",
|
|
27
|
+
"provinces",
|
|
28
|
+
"cite",
|
|
29
|
+
"clear_cache",
|
|
30
|
+
"__version__",
|
|
31
|
+
"TuikError",
|
|
32
|
+
"TuikConnectionError",
|
|
33
|
+
"TuikResponseError",
|
|
34
|
+
"ProvinceNotFoundError",
|
|
35
|
+
"TuikDataWarning",
|
|
36
|
+
]
|