the-datagarden 1.2.1__py3-none-any.whl → 1.2.4__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- the_datagarden/api/authentication/settings.py +2 -0
- the_datagarden/api/base/__init__.py +11 -1
- the_datagarden-1.2.4.dist-info/METADATA +253 -0
- {the_datagarden-1.2.1.dist-info → the_datagarden-1.2.4.dist-info}/RECORD +7 -7
- the_datagarden-1.2.1.dist-info/METADATA +0 -137
- {the_datagarden-1.2.1.dist-info → the_datagarden-1.2.4.dist-info}/WHEEL +0 -0
- {the_datagarden-1.2.1.dist-info → the_datagarden-1.2.4.dist-info}/entry_points.txt +0 -0
- {the_datagarden-1.2.1.dist-info → the_datagarden-1.2.4.dist-info}/top_level.txt +0 -0
@@ -26,6 +26,7 @@ from the_datagarden.abc.authentication import DatagardenEnvironment
|
|
26
26
|
from the_datagarden.api.authentication import AccessToken
|
27
27
|
from the_datagarden.api.authentication.environment import TheDatagardenProductionEnvironment
|
28
28
|
from the_datagarden.api.authentication.settings import (
|
29
|
+
DEFAULT_HEADER,
|
29
30
|
SHOW_REQ_DETAIL,
|
30
31
|
DynamicEndpointCategories,
|
31
32
|
URLExtension,
|
@@ -49,8 +50,17 @@ class BaseDataGardenAPI(BaseApi):
|
|
49
50
|
password: str | None = None,
|
50
51
|
):
|
51
52
|
self._environment = environment or TheDatagardenProductionEnvironment
|
52
|
-
self._tokens = self.ACCESS_TOKEN(self._environment, email, password)
|
53
53
|
self._base_url = self._environment().the_datagarden_url
|
54
|
+
self._api_status = self._check_pulse()
|
55
|
+
self._tokens = self.ACCESS_TOKEN(self._environment, email, password)
|
56
|
+
|
57
|
+
def _check_pulse(self) -> bool:
|
58
|
+
url = self._generate_url(URLExtension.PULSE)
|
59
|
+
response = requests.request(method="GET", url=url, headers=DEFAULT_HEADER.copy())
|
60
|
+
|
61
|
+
if response.status_code == 200:
|
62
|
+
return True
|
63
|
+
return False
|
54
64
|
|
55
65
|
def _generate_url(self, url_extension: str) -> str:
|
56
66
|
url = self._base_url + url_extension
|
@@ -0,0 +1,253 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: the-datagarden
|
3
|
+
Version: 1.2.4
|
4
|
+
Summary: Public data made easy.
|
5
|
+
Author-email: Maarten de Ruyter <info@the-datagarden.io>
|
6
|
+
License: MIT
|
7
|
+
Project-URL: Read the Docs, https://dg-the-datagarden.readthedocs.io/en/stable/
|
8
|
+
Project-URL: The-DataGarden, https://www.the-datagarden.io/
|
9
|
+
Project-URL: API documentation, https://www.the-datagarden.io/api-docs
|
10
|
+
Project-URL: Source, https://github.com/OlivettaDataGarden/dg-the-datagarden
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
17
|
+
Classifier: Operating System :: OS Independent
|
18
|
+
Classifier: Development Status :: 4 - Beta
|
19
|
+
Classifier: Intended Audience :: Developers
|
20
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
21
|
+
Classifier: Intended Audience :: Science/Research
|
22
|
+
Classifier: Intended Audience :: Healthcare Industry
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
26
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
27
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
28
|
+
Classifier: Topic :: Utilities
|
29
|
+
Requires-Python: >=3.10
|
30
|
+
Description-Content-Type: text/x-rst
|
31
|
+
Requires-Dist: click>=8.1.7
|
32
|
+
Requires-Dist: pandas>=2.2.3
|
33
|
+
Requires-Dist: polars>=1.15.0
|
34
|
+
Requires-Dist: pydantic>=2.9.2
|
35
|
+
Requires-Dist: pyjwt>=2.10.0
|
36
|
+
Requires-Dist: python-decouple>=3.8
|
37
|
+
Requires-Dist: requests>=2.32.3
|
38
|
+
Requires-Dist: the-datagarden-models>=1.6.3
|
39
|
+
|
40
|
+
==================
|
41
|
+
the-datagarden SDK
|
42
|
+
==================
|
43
|
+
|
44
|
+
The-datagarden package is a Python SDK built on top of The-DataGarden API. The SDK provides easy access to continent and country regional hierarchies,
|
45
|
+
as well as public data related to these regions. All data from The-DataGarden API is stored in normalized datamodels like ``Demographics``, ``Health``
|
46
|
+
or ``Economics``. This allows you as a data professional to create value from this data without having to worry about the (varying) data structure and
|
47
|
+
api's from the sources.
|
48
|
+
|
49
|
+
Additionally, The-DataGarden API also provides country and regional GeoJSONs. The SDK makes is easy for you to combine public data abd you own data and merge them into
|
50
|
+
geosjon Feature collections, making geographic visualisation easy.
|
51
|
+
|
52
|
+
|
53
|
+
The-DataGarden SDK main use case
|
54
|
+
--------------------------------
|
55
|
+
The SDK is designed to make it easy to access and work with the DataGarden data. After initializing the SDK you simply
|
56
|
+
retrieve data for a specific continent, country or subregion by calling the appropriate datamodel.
|
57
|
+
|
58
|
+
.. code-block:: python
|
59
|
+
|
60
|
+
# initialize a country object and retrieve the demographics attribute
|
61
|
+
>>> nl = the_datagarden_api.netherlands # or nl = the_datagarden_api.NL
|
62
|
+
>>> nl_demographics = nl.demographics()
|
63
|
+
TheDataGardenRegionalDataModel : Demographics : (count=5)
|
64
|
+
|
65
|
+
In this example the `nl_demographics` object holds 5 records. Each record contains demographic data for the Netherlands for a specific
|
66
|
+
period and period type combination. The data can be made accessible in a tabular format by converting the object to a pandas or polars dataframe.
|
67
|
+
|
68
|
+
.. code-block:: python
|
69
|
+
|
70
|
+
# convert demographics data to a polars dataframe
|
71
|
+
>>> dataframe = nl_demographics.full_model_to_polars()
|
72
|
+
>>> print(dataframe["period", "source_name", "data_model_name", "population.total", "population.total_male", "population.total_female"])
|
73
|
+
|
74
|
+
.. code-block:: text
|
75
|
+
|
76
|
+
┌───────────────┬────────────┬─────────────────┬──────────────────┬───────────────────────┬─────────────────────────┐
|
77
|
+
│ period ┆ source_name┆ data_model_name ┆ population.total ┆ population.total_male ┆ population.total_female │
|
78
|
+
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
|
79
|
+
│ str ┆ str ┆ str ┆ f64 ┆ f64 ┆ f64 │
|
80
|
+
╞═══════════════╪════════════╪═════════════════╪══════════════════╪═══════════════════════╪═════════════════════════╡
|
81
|
+
│ 2022-01-01T0Z ┆ Eurostat ┆ Demographics ┆ null ┆ 8.745468e6 ┆ 8.845204e6 │
|
82
|
+
│ 2022-01-01T0Z ┆ United Nat ┆ Demographics ┆ 1.7789347e7 ┆ 8.890013e6 ┆ 9.014408e6 │
|
83
|
+
│ 2023-01-01T0Z ┆ Eurostat ┆ Demographics ┆ null ┆ 8.850309e6 ┆ 8.960982e6 │
|
84
|
+
│ 2023-01-01T0Z ┆ United Nat ┆ Demographics ┆ 1.8019495e7 ┆ 8.986255e6 ┆ 9.106269e6 │
|
85
|
+
│ 2024-01-01T0Z ┆ United Nat ┆ Demographics ┆ 1.8165554e7 ┆ 9.055978e6 ┆ 9.172763e6 │
|
86
|
+
└───────────────┴────────────┴─────────────────┴──────────────────┴───────────────────────┴─────────────────────────┘
|
87
|
+
|
88
|
+
The demographics model holds lots of submodels and attributes. In this example only a limited number of attributes are listed
|
89
|
+
as the dataframe is way too large to display. For all models and their details see the model data documentation at
|
90
|
+
`The DataGarden Data Documentation <https://www.the-datagarden.io/data-docs>`_.
|
91
|
+
|
92
|
+
Getting started with the SDK
|
93
|
+
----------------------------
|
94
|
+
You can start using the SDK out of the box by simply instatiating the TheDataGardenAPI object:
|
95
|
+
|
96
|
+
.. code-block:: python
|
97
|
+
|
98
|
+
# Starting with the datagarden API
|
99
|
+
>>> from the-datagarden import TheDataGardenAPI
|
100
|
+
>>> the_datagarden_api = TheDataGardenAPI()
|
101
|
+
|
102
|
+
.. code-block:: console
|
103
|
+
|
104
|
+
Welcome to The Data Garden API.
|
105
|
+
|
106
|
+
You can start using the API with an account from The-Datagarden.io.
|
107
|
+
Please provide your credentials or create a new account.
|
108
|
+
Check www.the-datagarden.io for more information.
|
109
|
+
|
110
|
+
Do you want to (1) create a new account or (2) provide existing credentials? Enter 1 or 2:
|
111
|
+
|
112
|
+
|
113
|
+
simply select 1 to create a new account.
|
114
|
+
|
115
|
+
.. code-block:: console
|
116
|
+
|
117
|
+
Enrolling in The Data Garden API...
|
118
|
+
|
119
|
+
Enter your email: <your-email>
|
120
|
+
Enter your password: <your-password>
|
121
|
+
Confirm your password: <your-password>
|
122
|
+
|
123
|
+
Successfully enrolled in The Data Garden API.
|
124
|
+
Initializing : TheDatagardenEnvironment
|
125
|
+
At: https://www.the-datagarden.io/
|
126
|
+
|
127
|
+
If you already have an account at the-datagarden.io, you can either select option 2 or directly provide your credentials
|
128
|
+
when creating the TheDataGardenAPI object:
|
129
|
+
|
130
|
+
.. code-block:: python
|
131
|
+
|
132
|
+
# Retrieve a country object from the datagarden API
|
133
|
+
>>> from the-datagarden import TheDataGardenAPI
|
134
|
+
>>> the_datagarden_api = TheDataGardenAPI(email='your-email@example.com', password='your-password')
|
135
|
+
|
136
|
+
.. code-block:: console
|
137
|
+
|
138
|
+
Initializing : TheDatagardenEnvironment
|
139
|
+
At: https://www.the-datagarden.io/
|
140
|
+
|
141
|
+
A 3rd way to initialize the SDK is adding your credentials to the ``.env`` file.
|
142
|
+
|
143
|
+
|
144
|
+
Getting your first data from The-DataGarden API
|
145
|
+
-----------------------------------------------
|
146
|
+
Now that you have initialized the SDK, you can start retrieving data from The-DataGarden API.
|
147
|
+
For example, you can retrieve the demographics data for the Netherlands:
|
148
|
+
|
149
|
+
.. code-block:: python
|
150
|
+
|
151
|
+
# initialize a country object and retrieve the demographics attribute
|
152
|
+
>>> nl = the_datagarden_api.netherlands
|
153
|
+
>>> nl_demographics = nl.demographics
|
154
|
+
TheDataGardenRegionalDataModel : Demographics : (count=0)
|
155
|
+
|
156
|
+
This creates a country object ``nl`` for the Netherlands, which serves as your gateway to all Netherlands-related
|
157
|
+
data and its regional subdivisions.
|
158
|
+
|
159
|
+
In this getting started section we will work with a demographics object retrieved from the `nl` country object.
|
160
|
+
As shown in the example, the ``nl_demographics`` object can be retrieved by simply calling the `demographics`
|
161
|
+
attribute on the `nl` country object
|
162
|
+
|
163
|
+
The `nl_demographics` object starts empty (count=0). To populate it with data, simply call it as a function:
|
164
|
+
|
165
|
+
.. code-block:: python
|
166
|
+
|
167
|
+
# Calling the demographics attribute will populate it with demographics data from the API
|
168
|
+
>>> nl_demographics()
|
169
|
+
>>> nl_demographics
|
170
|
+
TheDataGardenRegionalDataModel : Demographics : (count=5)
|
171
|
+
|
172
|
+
When called without parameters, the API returns data using default settings, which in this case yields 5 records.
|
173
|
+
You can customize your data retrieval by specifying parameters such as time periods, period types, and data sources.
|
174
|
+
|
175
|
+
|
176
|
+
The DataGarden Regional DataModel
|
177
|
+
---------------------------------
|
178
|
+
When you retrieve data like ``nl_demographics``, you're working with a ``TheDataGardenRegionalDataModel`` object. This object acts as a container that holds:
|
179
|
+
|
180
|
+
1. A collection of ``TheDataGardenRegionalDataRecord`` objects
|
181
|
+
2. Metadata about the records (region, time period, data source, etc.)
|
182
|
+
|
183
|
+
You can easily transform this data into pandas or polars DataFrames for analysis. Here's an example showing population data for the Netherlands:
|
184
|
+
|
185
|
+
.. code-block:: python
|
186
|
+
|
187
|
+
>>> nl = the_datagarden_api.netherlands
|
188
|
+
>>> nl_demographics = nl.demographics(period_from="2010-01-01", source="united nations")
|
189
|
+
>>> # Convert to DataFrame, mapping 'population.total' to column name 'pop_count'
|
190
|
+
>>> df = nl_demographics.to_polars({"pop_count": "population.total"}) # or to_pandas(...)
|
191
|
+
>>> df["name", "source_name", "period", "data_model_name", "total"] # for readability only a limited number of columns are displayed
|
192
|
+
┌─────────────┬────────────────┬─────────────────┬─────────────────┬─────────────┐
|
193
|
+
│ name ┆ source_name ┆ period ┆ data_model_name ┆ pop_count │
|
194
|
+
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
|
195
|
+
│ str ┆ str ┆ str ┆ str ┆ f64 │
|
196
|
+
╞═════════════╪════════════════╪═════════════════╪═════════════════╪═════════════╡
|
197
|
+
│ Netherlands ┆ United Nations ┆ 2010-01-010:00Z ┆ Demographics ┆ 1.6729801e7 │
|
198
|
+
│ Netherlands ┆ United Nations ┆ 2011-01-010:00Z ┆ Demographics ┆ 1.6812669e7 │
|
199
|
+
│ … ┆ … ┆ … ┆ … ┆ … │
|
200
|
+
│ Netherlands ┆ United Nations ┆ 2023-01-010:00Z ┆ Demographics ┆ 1.8019495e7 │
|
201
|
+
│ Netherlands ┆ United Nations ┆ 2024-01-010:00Z ┆ Demographics ┆ 1.8165554e7 │
|
202
|
+
└─────────────┴────────────────┴─────────────────┴─────────────────┴─────────────┘
|
203
|
+
|
204
|
+
Each time you call the ``nl_demographics`` object with different parameters,
|
205
|
+
new demographic records for the specified subregions, periods, and/or sources are added to the existing ``nl_demographics`` object.
|
206
|
+
After you've gathered all the records you need, you can convert the entire collection into a dataframe for further analysis.
|
207
|
+
|
208
|
+
|
209
|
+
Retrieving GeoJSON data
|
210
|
+
-----------------------
|
211
|
+
Retrieving the GeoJSON for the Netherlands and its provinces is straightforward as well:
|
212
|
+
|
213
|
+
.. code-block:: python
|
214
|
+
|
215
|
+
>>> nl_geojson = nl.geojsons()
|
216
|
+
>>> nl_geojson
|
217
|
+
TheDataGardenRegionGeoJSONModel : GeoJSON : (count=1)
|
218
|
+
>>> nl_geojson(region_level=2) # Retrieve GeoJSON for 2nd regional level (provinces)
|
219
|
+
TheDataGardenRegionGeoJSONModel : GeoJSON : (count=13) # 12 provinces + 1 country
|
220
|
+
>>> df = nl_geojson.to_polars()
|
221
|
+
>>> df["name", "region_type", "local_region_code", "region_level", "feature"]
|
222
|
+
┌───────────────┬─────────────┬───────────────┬──────────────┬────────────────────────┐
|
223
|
+
│ name ┆ region_type ┆ local_region_c┆ region_level ┆ feature │
|
224
|
+
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
|
225
|
+
│ str ┆ str ┆ str ┆ i64 ┆ struct[3] │
|
226
|
+
╞═══════════════╪═════════════╪═══════════════╪══════════════╪════════════════════════╡
|
227
|
+
│ Netherlands ┆ country ┆ 528 ┆ 0 ┆ {"Feature",{"Netherland│
|
228
|
+
│ Drenthe ┆ province ┆ NL13 ┆ 2 ┆ {"Feature",{"Drenthe",2│
|
229
|
+
│ … ┆ … ┆ … ┆ … ┆ … │
|
230
|
+
│ Zuid-Holland ┆ province ┆ NL33 ┆ 2 ┆ {"Feature",{"Zuid-Holla│
|
231
|
+
└───────────────┴─────────────┴───────────────┴──────────────┴────────────────────────┘
|
232
|
+
|
233
|
+
For readability, the output only a limited number of dataframe columns are displayed.
|
234
|
+
Attributes in both the demographics and geojson dataframes are available to connect the geojson to
|
235
|
+
the demographics data. This allows you quickly make data sets that contain both demographics and geojson data
|
236
|
+
for further analysis or visualisation in map applications.
|
237
|
+
|
238
|
+
|
239
|
+
Read more
|
240
|
+
---------
|
241
|
+
|
242
|
+
* `The DataGarden Website <https://www.the-datagarden.io>`_
|
243
|
+
* `API Documentation <https://www.the-datagarden.io/api-docs>`_
|
244
|
+
* `The Datagarden Models <https://www.the-datagarden.io/data-docs>`_
|
245
|
+
* `GitHub Repository <https://github.com/MaartendeRuyter/dg-the-datagarden>`_
|
246
|
+
|
247
|
+
|
248
|
+
Access to The DataGarden API
|
249
|
+
----------------------------
|
250
|
+
To use the DataGarden SDK, you need access to the The DataGarden API. Simply register for free at https://www.the-datagarden.io
|
251
|
+
and you will have an inital free access account to the API with access to country and continent data.
|
252
|
+
|
253
|
+
Visit https://www.the-datagarden.io to register for free.
|
@@ -6,10 +6,10 @@ the_datagarden/abc/api.py,sha256=RC3PTjrea9asrUfm9XD-AWIcQnhTUyZsBlc8e8leT08,484
|
|
6
6
|
the_datagarden/abc/authentication.py,sha256=6UJVMAlorMCTjvFMFQLwC_Zx6wyENXQekHHgaLZaouk,1174
|
7
7
|
the_datagarden/api/__init__.py,sha256=tUT1s1J3U5fX6edISvchO-rO0zZ5nJFcG4YUAG0Kwc4,235
|
8
8
|
the_datagarden/api/authentication/__init__.py,sha256=JN20Cpjfes9nFBlDLcojJJyyt_W7_78DoQAdAA9tQW0,3715
|
9
|
-
the_datagarden/api/authentication/settings.py,sha256=
|
9
|
+
the_datagarden/api/authentication/settings.py,sha256=uXu544RPhX7m0EyzTH1ANhEr8JhFFyA0h9ks3uTvGMI,1618
|
10
10
|
the_datagarden/api/authentication/credentials/__init__.py,sha256=OXlnUaZ6w-1VIHmCEDKQ7uMZuzKtroeQT_rCl2M0FB8,4806
|
11
11
|
the_datagarden/api/authentication/environment/__init__.py,sha256=9EWOWvinW6C4UAzrPIAI8CqxAM9GErXbo9sKMu5AcH8,426
|
12
|
-
the_datagarden/api/base/__init__.py,sha256=
|
12
|
+
the_datagarden/api/base/__init__.py,sha256=8RYikWdbcJVT52Fn8dxrqvjyxs79R5ZqG-p3YrhGps8,8498
|
13
13
|
the_datagarden/api/regions/__init__.py,sha256=oO533d7dn6CEUZQWGGIUBZvpxvJXRDtdZgNUt3rXg4E,98
|
14
14
|
the_datagarden/api/regions/continent.py,sha256=iCsjCvG39bV4zS-4Nj4mvszo1jmKPLWofobByV9G1cg,204
|
15
15
|
the_datagarden/api/regions/country.py,sha256=Uibm8KvvLSa6DGuHz20IW-G08DC7ggIEkx-OYkQMICA,194
|
@@ -18,8 +18,8 @@ the_datagarden/api/regions/base/settings.py,sha256=KuUR4r-Iro4ZQpQZjssvRoe7_OJ_L
|
|
18
18
|
the_datagarden/models/__init__.py,sha256=UoBC9iK6VfHuW92PeGUteUWAqB0M3qoHDvNBPiNgfhQ,305
|
19
19
|
the_datagarden/models/geojson.py,sha256=74uvrI7YSGgu8ohAMvohKLu6fUkILDT0nZ9l3O4xpis,6340
|
20
20
|
the_datagarden/models/regional_data.py,sha256=zhk6iRYRlzirgxp1k6J9ftt0mAFqWrTH4M3TPiRfR88,16566
|
21
|
-
the_datagarden-1.2.
|
22
|
-
the_datagarden-1.2.
|
23
|
-
the_datagarden-1.2.
|
24
|
-
the_datagarden-1.2.
|
25
|
-
the_datagarden-1.2.
|
21
|
+
the_datagarden-1.2.4.dist-info/METADATA,sha256=XCYu_lwcOPUahp409Iozk4I0XXwWFdqI4efxigf0ZUE,15336
|
22
|
+
the_datagarden-1.2.4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
23
|
+
the_datagarden-1.2.4.dist-info/entry_points.txt,sha256=R40-UiUsDqy6RfBSnkOCj98Ed0bfvseJPpClXxqVVAM,59
|
24
|
+
the_datagarden-1.2.4.dist-info/top_level.txt,sha256=S0Wn3mYX0nrwGIqeqWE5vAc3ASTK13E-F_9eTOQu8hs,15
|
25
|
+
the_datagarden-1.2.4.dist-info/RECORD,,
|
@@ -1,137 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: the-datagarden
|
3
|
-
Version: 1.2.1
|
4
|
-
Summary: Public data made easy.
|
5
|
-
Author-email: Maarten de Ruyter <info@the-datagarden.io>
|
6
|
-
License: MIT
|
7
|
-
Project-URL: Read the Docs, https://the-datagarden.readthedocs.io/
|
8
|
-
Project-URL: The-DataGarden, https://www.the-datagarden.io/
|
9
|
-
Project-URL: API documentation, https://api.the-datagarden.io/api-docs
|
10
|
-
Project-URL: Source, https://github.com/the-datagarden/the-datagarden
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
12
|
-
Classifier: Programming Language :: Python :: 3.10
|
13
|
-
Classifier: Programming Language :: Python :: 3.11
|
14
|
-
Classifier: Programming Language :: Python :: 3.12
|
15
|
-
Classifier: Programming Language :: Python :: 3.13
|
16
|
-
Classifier: License :: OSI Approved :: MIT License
|
17
|
-
Classifier: Operating System :: OS Independent
|
18
|
-
Classifier: Development Status :: 4 - Beta
|
19
|
-
Classifier: Intended Audience :: Developers
|
20
|
-
Classifier: Intended Audience :: Financial and Insurance Industry
|
21
|
-
Classifier: Intended Audience :: Science/Research
|
22
|
-
Classifier: Intended Audience :: Healthcare Industry
|
23
|
-
Classifier: Topic :: Scientific/Engineering :: GIS
|
24
|
-
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
25
|
-
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
26
|
-
Classifier: Topic :: Scientific/Engineering :: Visualization
|
27
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
28
|
-
Classifier: Topic :: Utilities
|
29
|
-
Requires-Python: >=3.10
|
30
|
-
Description-Content-Type: text/x-rst
|
31
|
-
Requires-Dist: click>=8.1.7
|
32
|
-
Requires-Dist: pandas>=2.2.3
|
33
|
-
Requires-Dist: polars>=1.15.0
|
34
|
-
Requires-Dist: pydantic>=2.9.2
|
35
|
-
Requires-Dist: pyjwt>=2.10.0
|
36
|
-
Requires-Dist: python-decouple>=3.8
|
37
|
-
Requires-Dist: requests>=2.32.3
|
38
|
-
Requires-Dist: the-datagarden-models>=1.6.3
|
39
|
-
|
40
|
-
==================
|
41
|
-
the-datagarden SDK
|
42
|
-
==================
|
43
|
-
|
44
|
-
The-datagarden package is a Python SDK built on top of The-DataGarden API. It provides easy access to continent and country regional hierarchies, as well as public data related to these regions. Additionally, you can retrieve regional GeoJSONs using the SDK. It simplifies the process of converting regional data into DataFrames and/or GeoJSON Feature collections, enabling developers to build upon this data effortlessly.
|
45
|
-
|
46
|
-
A quick example
|
47
|
-
---------------
|
48
|
-
If you have a user account at the-datagarden.io, you can start using the SDK right away:
|
49
|
-
|
50
|
-
.. code-block:: python
|
51
|
-
|
52
|
-
# Retrieve a country object from the datagarden API
|
53
|
-
>>> from the-datagarden import TheDataGardenAPI
|
54
|
-
>>> the_datagarden_api = TheDataGardenAPI(email='your-email@example.com', password='your-password')
|
55
|
-
>>> nl = the_datagarden_api.netherlands()
|
56
|
-
>>> nl_demographics = nl.demographics(from_period="2010-01-01", source="united nations")
|
57
|
-
>>> nl_demographics
|
58
|
-
TheDataGardenRegionalDataModel : Demographics : (count=15)
|
59
|
-
|
60
|
-
this returns a `TheDataGardenRegionalDataModel` containimg the demographics data in this case 15 records.
|
61
|
-
Each of those records will contain a Demographics object for the region for the specified period.
|
62
|
-
|
63
|
-
To work with this data, you can convert it to a pandas or polars dataframe and select the data from the demographics
|
64
|
-
data model you need.
|
65
|
-
|
66
|
-
.. code-block:: python
|
67
|
-
|
68
|
-
>>> df = nl_demographics.to_polars({"pop_count": "population.total"}) # or to_pandas(...)
|
69
|
-
>>> df["name", "source_name", "period", "data_model_name", "total"]
|
70
|
-
┌─────────────┬────────────────┬─────────────────┬─────────────────┬─────────────┐
|
71
|
-
│ name ┆ source_name ┆ period ┆ data_model_name ┆ pop_count │
|
72
|
-
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
|
73
|
-
│ str ┆ str ┆ str ┆ str ┆ f64 │
|
74
|
-
╞═════════════╪════════════════╪═════════════════╪═════════════════╪═════════════╡
|
75
|
-
│ Netherlands ┆ United Nations ┆ 2010-01-010:00Z ┆ Demographics ┆ 1.6729801e7 │
|
76
|
-
│ Netherlands ┆ United Nations ┆ 2011-01-010:00Z ┆ Demographics ┆ 1.6812669e7 │
|
77
|
-
│ Netherlands ┆ United Nations ┆ 2012-01-010:00Z ┆ Demographics ┆ 1.6889445e7 │
|
78
|
-
│ Netherlands ┆ United Nations ┆ 2013-01-010:00Z ┆ Demographics ┆ 1.6940942e7 │
|
79
|
-
│ Netherlands ┆ United Nations ┆ 2014-01-010:00Z ┆ Demographics ┆ 1.6993184e7 │
|
80
|
-
│ … ┆ … ┆ … ┆ … ┆ … │
|
81
|
-
│ Netherlands ┆ United Nations ┆ 2020-01-010:00Z ┆ Demographics ┆ 1.7601682e7 │
|
82
|
-
│ Netherlands ┆ United Nations ┆ 2021-01-010:00Z ┆ Demographics ┆ 1.767178e7 │
|
83
|
-
│ Netherlands ┆ United Nations ┆ 2022-01-010:00Z ┆ Demographics ┆ 1.7789347e7 │
|
84
|
-
│ Netherlands ┆ United Nations ┆ 2023-01-010:00Z ┆ Demographics ┆ 1.8019495e7 │
|
85
|
-
│ Netherlands ┆ United Nations ┆ 2024-01-010:00Z ┆ Demographics ┆ null │
|
86
|
-
└─────────────┴────────────────┴─────────────────┴─────────────────┴─────────────┘
|
87
|
-
|
88
|
-
|
89
|
-
Retrieving the GeoJSON for the Netherlands and its provinces is straightforward as well:
|
90
|
-
|
91
|
-
.. code-block:: python
|
92
|
-
|
93
|
-
>>> nl_geojson = nl.geojsons()
|
94
|
-
>>> nl_geojson
|
95
|
-
TheDataGardenRegionGeoJSONModel : GeoJSON : (count=1)
|
96
|
-
>>> nl_geojson(region_level=2) # Retrieve GeoJSON for 2nd regional level (provinces)
|
97
|
-
TheDataGardenRegionGeoJSONModel : GeoJSON : (count=13) # 12 provinces + 1 country
|
98
|
-
>>> df = nl_geojson.to_polars()
|
99
|
-
>>> df["name", "region_type", "local_region_code", "region_level", "feature"]
|
100
|
-
┌───────────────┬─────────────┬───────────────┬──────────────┬────────────────────────┐
|
101
|
-
│ name ┆ region_type ┆ local_region_c┆ region_level ┆ feature │
|
102
|
-
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
|
103
|
-
│ str ┆ str ┆ str ┆ i64 ┆ struct[3] │
|
104
|
-
╞═══════════════╪═════════════╪═══════════════╪══════════════╪════════════════════════╡
|
105
|
-
│ Netherlands ┆ country ┆ 528 ┆ 0 ┆ {"Feature",{"Netherland│
|
106
|
-
│ Drenthe ┆ province ┆ NL13 ┆ 2 ┆ {"Feature",{"Drenthe",2│
|
107
|
-
│ Flevoland ┆ province ┆ NL23 ┆ 2 ┆ {"Feature",{"Flevoland"│
|
108
|
-
│ Friesland ┆ province ┆ NL12 ┆ 2 ┆ {"Feature",{"Friesland"│
|
109
|
-
│ Gelderland ┆ province ┆ NL22 ┆ 2 ┆ {"Feature",{"Gelderland│
|
110
|
-
│ … ┆ … ┆ … ┆ … ┆ … │
|
111
|
-
│ Noord-Holland ┆ province ┆ NL32 ┆ 2 ┆ {"Feature",{"Noord-Holl│
|
112
|
-
│ Overijssel ┆ province ┆ NL21 ┆ 2 ┆ {"Feature",{"Overijssel│
|
113
|
-
│ Utrecht ┆ province ┆ NL31 ┆ 2 ┆ {"Feature",{"Utrecht",2│
|
114
|
-
│ Zeeland ┆ province ┆ NL34 ┆ 2 ┆ {"Feature",{"Zeeland",2│
|
115
|
-
│ Zuid-Holland ┆ province ┆ NL33 ┆ 2 ┆ {"Feature",{"Zuid-Holla│
|
116
|
-
└───────────────┴─────────────┴───────────────┴──────────────┴────────────────────────┘
|
117
|
-
|
118
|
-
For readability, the output only a limited number of dataframe columns are displayed.
|
119
|
-
Attributes in both the demographics and geojson dataframes are available to connect the geojson to
|
120
|
-
the demographics data. This allows you quickly make data sets that contain both demographics and geojson data
|
121
|
-
for further analysis or visualisation in map applications.
|
122
|
-
|
123
|
-
|
124
|
-
Read more
|
125
|
-
---------
|
126
|
-
|
127
|
-
* `The DataGarden Website <https://www.the-datagarden.io>`_
|
128
|
-
* `API Documentation <https://www.the-datagarden.io/api-docs>`_
|
129
|
-
* `The Datagarden Models <https://www.the-datagarden.io/data-docs>`_
|
130
|
-
* `GitHub Repository <https://github.com/MaartendeRuyter/dg-the-datagarden>`_
|
131
|
-
|
132
|
-
Access to The DataGarden API
|
133
|
-
----------------------------
|
134
|
-
To use the DataGarden SDK, you need access to the The DataGarden API. Simply register for free at https://www.the-datagarden.io
|
135
|
-
and you will have an inital free access account to the API with access to country and continent data.
|
136
|
-
|
137
|
-
Visit https://www.the-datagarden.io for to register for free.
|
File without changes
|
File without changes
|
File without changes
|