-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_reference.html
303 lines (283 loc) · 22.2 KB
/
api_reference.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="./">
<head>
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>API Reference — pyworldatlas 0.0.8 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=80d5e7a1" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=19f00094" />
<link rel="shortcut icon" href="_static/python.ico"/>
<!--[if lt IE 9]>
<script src="_static/js/html5shiv.min.js"></script>
<![endif]-->
<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=53b53b71"></script>
<script src="_static/doctools.js?v=9a2dae69"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Country Data" href="country_data.html" />
<link rel="prev" title="Getting Started" href="getting_started.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html" class="icon icon-home">
pyworldatlas
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="getting_started.html">Getting Started</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">API Reference</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#classes-and-methods">Classes and Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="#atlas-class">Atlas Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="#get-country-profile">get_country_profile</a></li>
<li class="toctree-l2"><a class="reference internal" href="#get-countries-wip">get_countries (WIP)</a></li>
<li class="toctree-l2"><a class="reference internal" href="#get-progress">get_progress</a></li>
<li class="toctree-l2"><a class="reference internal" href="#error-handling">Error Handling</a></li>
<li class="toctree-l2"><a class="reference internal" href="#countrynotfounderror">CountryNotFoundError</a></li>
<li class="toctree-l2"><a class="reference internal" href="#additional-features">Additional Features</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="country_data.html">Country Data</a></li>
<li class="toctree-l1"><a class="reference internal" href="database_download.html">Database Download</a></li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="contributing.html">Contributing</a></li>
<li class="toctree-l1"><a class="reference internal" href="roadmap.html">Roadmap</a></li>
<li class="toctree-l1"><a class="reference internal" href="changelog.html">Changelog</a></li>
<li class="toctree-l1"><a class="reference internal" href="license.html">License</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">pyworldatlas</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item active">API Reference</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/api_reference.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<section id="api-reference">
<h1>API Reference<a class="headerlink" href="#api-reference" title="Link to this heading"></a></h1>
<p>This section provides a detailed overview of the available methods and their usage in <strong>pyworldatlas</strong>. Each method is designed to retrieve specific data about countries, with simple and intuitive interfaces.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Throughout the examples, we will assume <strong>pyworldatlas</strong> has been imported as <cite>pwa</cite>.</p>
</div>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">pyworldatlas</span> <span class="k">as</span> <span class="nn">pwa</span>
<span class="n">atlas</span> <span class="o">=</span> <span class="n">pwa</span><span class="o">.</span><span class="n">Atlas</span><span class="p">()</span>
</pre></div>
</div>
<section id="classes-and-methods">
<h2>Classes and Methods<a class="headerlink" href="#classes-and-methods" title="Link to this heading"></a></h2>
</section>
<section id="atlas-class">
<h2>Atlas Class<a class="headerlink" href="#atlas-class" title="Link to this heading"></a></h2>
<p>The <strong>Atlas</strong> class is the main interface for accessing country data. It provides several methods to retrieve specific country profiles, lists of countries, and other data.</p>
</section>
<section id="get-country-profile">
<h2>get_country_profile<a class="headerlink" href="#get-country-profile" title="Link to this heading"></a></h2>
<p>Fetches detailed profile information for a specific country.</p>
<p><strong>Parameters</strong>:
- <strong>name</strong> (<em>str</em>) – The name or ISO 3166 Alpha-2 code of the country.</p>
<p><strong>Returns</strong>:
- <strong>dict</strong> – A dictionary containing detailed information about the country’s official names, capital, largest city, area, population, government, and more.</p>
<p><strong>Example</strong>:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">profile</span> <span class="o">=</span> <span class="n">atlas</span><span class="o">.</span><span class="n">get_country_profile</span><span class="p">(</span><span class="s2">"Algeria"</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">profile</span><span class="p">)</span>
</pre></div>
</div>
<p><strong>Example Output</strong>:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="s2">"capital"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"name"</span><span class="p">:</span> <span class="s2">"Algiers"</span><span class="p">,</span>
<span class="s2">"coordinates_degree_east"</span><span class="p">:</span> <span class="mf">3.13</span><span class="p">,</span>
<span class="s2">"coordinates_degree_north"</span><span class="p">:</span> <span class="mf">36.42</span><span class="p">,</span>
<span class="s2">"is_largest_city"</span><span class="p">:</span> <span class="kc">True</span>
<span class="p">},</span>
<span class="s2">"area"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"total_km2_including_disputed_territories"</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
<span class="s2">"total_km2_internationally_recognized"</span><span class="p">:</span> <span class="mf">2381741.0</span><span class="p">,</span>
<span class="s2">"water_percentage"</span><span class="p">:</span> <span class="mf">1.1</span>
<span class="p">},</span>
<span class="s2">"driving_side"</span><span class="p">:</span> <span class="s2">"Right"</span><span class="p">,</span>
<span class="s2">"calling_code"</span><span class="p">:</span> <span class="s2">"+213"</span><span class="p">,</span>
<span class="s2">"iso_3166_code"</span><span class="p">:</span> <span class="s2">"DZ"</span><span class="p">,</span>
<span class="s2">"internet_tld"</span><span class="p">:</span> <span class="s2">".dz"</span><span class="p">,</span>
<span class="s2">"population"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"total"</span><span class="p">:</span> <span class="mi">44700000</span><span class="p">,</span>
<span class="s2">"density_km2"</span><span class="p">:</span> <span class="mf">17.7</span><span class="p">,</span>
<span class="s2">"date_year"</span><span class="p">:</span> <span class="mi">2021</span>
<span class="p">},</span>
<span class="s2">"gini_index"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"value"</span><span class="p">:</span> <span class="mf">27.6</span><span class="p">,</span>
<span class="s2">"year"</span><span class="p">:</span> <span class="mi">2011</span>
<span class="p">},</span>
<span class="s2">"gdp"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"ppp_trillions"</span><span class="p">:</span> <span class="mf">0.684649</span><span class="p">,</span>
<span class="s2">"ppp_per_capita"</span><span class="p">:</span> <span class="s2">"15,765"</span><span class="p">,</span>
<span class="s2">"nominal_total_trillions"</span><span class="p">:</span> <span class="mf">0.183687</span><span class="p">,</span>
<span class="s2">"nominal_per_capita"</span><span class="p">:</span> <span class="s2">"4,229"</span><span class="p">,</span>
<span class="s2">"ppp_gdp_year"</span><span class="p">:</span> <span class="mi">2019</span><span class="p">,</span>
<span class="s2">"nominal_gdp_year"</span><span class="p">:</span> <span class="mi">2019</span>
<span class="p">},</span>
<span class="s2">"government"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"president"</span><span class="p">:</span> <span class="s2">"Abdelmadjid Tebboune"</span><span class="p">,</span>
<span class="s2">"prime_minister"</span><span class="p">:</span> <span class="s2">"Nadir Larbaoui"</span><span class="p">,</span>
<span class="s2">"declaration_of_state_sovereignty"</span><span class="p">:</span> <span class="s2">"1962-07-05"</span><span class="p">,</span>
<span class="s2">"other_leader_title"</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
<span class="s2">"other_leader"</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
<span class="s2">"government_type"</span><span class="p">:</span> <span class="s2">"Unitary semi-presidential constitutional republic"</span><span class="p">,</span>
<span class="s2">"president_assumed_office"</span><span class="p">:</span> <span class="s2">"2019-12-19"</span><span class="p">,</span>
<span class="s2">"prime_minister_assumed_office"</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
<span class="s2">"other_leader_assumed_office"</span><span class="p">:</span> <span class="kc">None</span>
<span class="p">},</span>
<span class="s2">"official_names"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"English"</span><span class="p">:</span> <span class="s2">"People's Democratic Republic of Algeria"</span><span class="p">,</span>
<span class="s2">"Arabic"</span><span class="p">:</span> <span class="s2">"الجمهورية الجزائرية الديمقراطية الشعبية"</span><span class="p">,</span>
<span class="s2">"French"</span><span class="p">:</span> <span class="s2">"République algérienne démocratique et populaire"</span><span class="p">,</span>
<span class="s2">"Berber"</span><span class="p">:</span> <span class="s2">"ⵜⴰⴳⴷⵓⴷⴰ ⵜⴰⵎⴳⴷⴰⵢⵜ ⵜⴰⵖⵔⴼⴰⵏⵜ ⵜⴰⴷⵣⴰⵢⵔⵉⵢⵜ"</span>
<span class="p">},</span>
<span class="s2">"anthem"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"English"</span><span class="p">:</span> <span class="s2">"We Pledge"</span>
<span class="p">},</span>
<span class="s2">"motto"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"Arabic"</span><span class="p">:</span> <span class="s2">"بالشّعب وللشّعب"</span><span class="p">,</span>
<span class="s2">"English"</span><span class="p">:</span> <span class="s2">"By the people and for the people"</span>
<span class="p">},</span>
<span class="s2">"religion"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"Islam"</span><span class="p">:</span> <span class="mf">99.0</span><span class="p">,</span>
<span class="s2">"Others"</span><span class="p">:</span> <span class="mf">1.0</span>
<span class="p">},</span>
<span class="s2">"ethnic_groups"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"Arab-Berber"</span><span class="p">:</span> <span class="mf">99.0</span><span class="p">,</span>
<span class="s2">"Others"</span><span class="p">:</span> <span class="mf">1.0</span>
<span class="p">},</span>
<span class="s2">"languages"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"official_languages"</span><span class="p">:</span> <span class="p">[</span><span class="s2">"Arabic"</span><span class="p">,</span> <span class="s2">"Berber"</span><span class="p">],</span>
<span class="s2">"recognized_languages"</span><span class="p">:</span> <span class="p">[</span><span class="s2">"French"</span><span class="p">,</span> <span class="s2">"Algerian Arabic (Darja)"</span><span class="p">,</span> <span class="s2">"Kabyle"</span><span class="p">]</span>
<span class="p">},</span>
<span class="s2">"currency"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"name"</span><span class="p">:</span> <span class="s2">"Dinar"</span><span class="p">,</span>
<span class="s2">"symbol"</span><span class="p">:</span> <span class="s2">"دج"</span><span class="p">,</span>
<span class="s2">"iso_code"</span><span class="p">:</span> <span class="s2">"DA"</span>
<span class="p">},</span>
<span class="s2">"continent"</span><span class="p">:</span> <span class="p">[</span><span class="s2">"Africa"</span><span class="p">],</span>
<span class="s2">"timezones"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"UTC+1"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"DST"</span><span class="p">:</span> <span class="mi">0</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
</section>
<section id="get-countries-wip">
<h2>get_countries (WIP)<a class="headerlink" href="#get-countries-wip" title="Link to this heading"></a></h2>
<p>Fetches a list of countries, optionally filtered by continents or population/GDP ranges.</p>
<p><strong>Parameters:</strong></p>
<ul class="simple">
<li><p><strong>continents</strong> (<em>list of str, optional</em>) – The continents to filter by (e.g., <code class="docutils literal notranslate"><span class="pre">["Asia",</span> <span class="pre">"Europe"]</span></code>).</p></li>
<li><p><strong>min_population</strong> (<em>float, optional</em>) – The minimum population to filter by.</p></li>
<li><p><strong>max_population</strong> (<em>float, optional</em>) – The maximum population to filter by.</p></li>
<li><p><strong>min_gdp</strong> (<em>float, optional</em>) – The minimum GDP to filter by.</p></li>
<li><p><strong>max_gdp</strong> (<em>float, optional</em>) – The maximum GDP to filter by.</p></li>
</ul>
<p><strong>Returns</strong>:</p>
<ul class="simple">
<li><p><strong>list of str</strong> – A list of country names that match the criteria.</p></li>
</ul>
<p><strong>Example</strong>:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">countries</span> <span class="o">=</span> <span class="n">atlas</span><span class="o">.</span><span class="n">get_countries</span><span class="p">(</span><span class="n">continents</span><span class="o">=</span><span class="p">[</span><span class="s2">"Europe"</span><span class="p">],</span> <span class="n">min_population</span><span class="o">=</span><span class="mi">1000000</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">countries</span><span class="p">)</span>
</pre></div>
</div>
<p><strong>Example Output</strong>:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">[</span><span class="s1">'France'</span><span class="p">,</span> <span class="s1">'Germany'</span><span class="p">,</span> <span class="s1">'Italy'</span><span class="p">,</span> <span class="s1">'Spain'</span><span class="p">]</span>
</pre></div>
</div>
</section>
<section id="get-progress">
<h2>get_progress<a class="headerlink" href="#get-progress" title="Link to this heading"></a></h2>
<p>Returns the percentage of data that the package currently contains.</p>
<p><strong>Returns</strong>:
- <strong>float</strong> – The percentage of the dataset that is complete.</p>
<p><strong>Example</strong>:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">progress</span> <span class="o">=</span> <span class="n">atlas</span><span class="o">.</span><span class="n">get_progress</span><span class="p">()</span>
</pre></div>
</div>
<p><strong>Example Output</strong>:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="s2">"Current data size: 3, Total data size: 285, Progress: 1.1%"</span>
</pre></div>
</div>
</section>
<section id="error-handling">
<h2>Error Handling<a class="headerlink" href="#error-handling" title="Link to this heading"></a></h2>
<p><strong>pyworldatlas</strong> provides custom exceptions to help identify and handle errors efficiently.</p>
</section>
<section id="countrynotfounderror">
<h2>CountryNotFoundError<a class="headerlink" href="#countrynotfounderror" title="Link to this heading"></a></h2>
<p>Raised when a country is not found in the dataset.</p>
<p><strong>Example</strong>:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="p">:</span>
<span class="n">profile</span> <span class="o">=</span> <span class="n">atlas</span><span class="o">.</span><span class="n">get_country_profile</span><span class="p">(</span><span class="s2">"Nonexistentland"</span><span class="p">)</span>
<span class="k">except</span> <span class="n">pwa</span><span class="o">.</span><span class="n">Atlas</span><span class="o">.</span><span class="n">CountryNotFoundError</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Country not found."</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="additional-features">
<h2>Additional Features<a class="headerlink" href="#additional-features" title="Link to this heading"></a></h2>
<p><strong>pyworldatlas</strong> is continually evolving. Refer to the <a class="reference external" href="roadmap.html">Roadmap</a> for upcoming features and improvements.</p>
</section>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="getting_started.html" class="btn btn-neutral float-left" title="Getting Started" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="country_data.html" class="btn btn-neutral float-right" title="Country Data" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
<div role="contentinfo">
<p>© Copyright 2024, Jorge Caridad.</p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>