the-datagarden 0.1.0__tar.gz → 1.2.3__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- the_datagarden-1.2.3/PKG-INFO +253 -0
- the_datagarden-1.2.3/README.rst +214 -0
- the_datagarden-1.2.3/pyproject.toml +84 -0
- the_datagarden-1.2.3/src/the_datagarden/__init__.py +8 -0
- the_datagarden-1.2.3/src/the_datagarden/abc/__init__.py +3 -0
- the_datagarden-1.2.3/src/the_datagarden/abc/api.py +19 -0
- the_datagarden-1.2.3/src/the_datagarden/abc/authentication.py +42 -0
- the_datagarden-1.2.3/src/the_datagarden/api/__init__.py +5 -0
- the_datagarden-1.2.3/src/the_datagarden/api/authentication/__init__.py +112 -0
- the_datagarden-1.2.3/src/the_datagarden/api/authentication/credentials/__init__.py +120 -0
- the_datagarden-1.2.3/src/the_datagarden/api/authentication/environment/__init__.py +13 -0
- the_datagarden-1.2.3/src/the_datagarden/api/authentication/settings.py +54 -0
- the_datagarden-1.2.3/src/the_datagarden/api/base/__init__.py +215 -0
- the_datagarden-1.2.3/src/the_datagarden/api/regions/__init__.py +4 -0
- the_datagarden-1.2.3/src/the_datagarden/api/regions/base/__init__.py +108 -0
- the_datagarden-1.2.3/src/the_datagarden/api/regions/base/settings.py +19 -0
- the_datagarden-1.2.3/src/the_datagarden/api/regions/continent.py +9 -0
- the_datagarden-1.2.3/src/the_datagarden/api/regions/country.py +9 -0
- the_datagarden-1.2.3/src/the_datagarden/models/__init__.py +9 -0
- the_datagarden-1.2.3/src/the_datagarden/models/geojson.py +179 -0
- the_datagarden-1.2.3/src/the_datagarden/models/regional_data.py +411 -0
- the_datagarden-1.2.3/src/the_datagarden/version.py +1 -0
- the_datagarden-1.2.3/src/the_datagarden.egg-info/PKG-INFO +253 -0
- the_datagarden-1.2.3/src/the_datagarden.egg-info/SOURCES.txt +30 -0
- the_datagarden-1.2.3/src/the_datagarden.egg-info/requires.txt +8 -0
- the_datagarden-0.1.0/PKG-INFO +0 -17
- the_datagarden-0.1.0/README.md +0 -0
- the_datagarden-0.1.0/pyproject.toml +0 -70
- the_datagarden-0.1.0/src/the_datagarden/__init__.py +0 -0
- the_datagarden-0.1.0/src/the_datagarden.egg-info/PKG-INFO +0 -17
- the_datagarden-0.1.0/src/the_datagarden.egg-info/SOURCES.txt +0 -12
- the_datagarden-0.1.0/src/the_datagarden.egg-info/requires.txt +0 -2
- {the_datagarden-0.1.0 → the_datagarden-1.2.3}/setup.cfg +0 -0
- {the_datagarden-0.1.0 → the_datagarden-1.2.3}/src/the_datagarden/cli.py +0 -0
- {the_datagarden-0.1.0 → the_datagarden-1.2.3}/src/the_datagarden.egg-info/dependency_links.txt +0 -0
- {the_datagarden-0.1.0 → the_datagarden-1.2.3}/src/the_datagarden.egg-info/entry_points.txt +0 -0
- {the_datagarden-0.1.0 → the_datagarden-1.2.3}/src/the_datagarden.egg-info/top_level.txt +0 -0
- {the_datagarden-0.1.0 → the_datagarden-1.2.3}/tests/test_cli.py +0 -0
- {the_datagarden-0.1.0 → the_datagarden-1.2.3}/tests/test_the_datagarden_imports.py +0 -0
@@ -0,0 +1,253 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: the-datagarden
|
3
|
+
Version: 1.2.3
|
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/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. 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.
|
@@ -0,0 +1,214 @@
|
|
1
|
+
==================
|
2
|
+
the-datagarden SDK
|
3
|
+
==================
|
4
|
+
|
5
|
+
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,
|
6
|
+
as well as public data related to these regions. All data from The-DataGarden API is stored in normalized datamodels like ``Demographics``, ``Health``
|
7
|
+
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
|
8
|
+
api's from the sources.
|
9
|
+
|
10
|
+
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
|
11
|
+
geosjon Feature collections, making geographic visualisation easy.
|
12
|
+
|
13
|
+
|
14
|
+
The-DataGarden SDK main use case
|
15
|
+
--------------------------------
|
16
|
+
The SDK is designed to make it easy to access and work with the DataGarden data. After initializing the SDK you simply
|
17
|
+
retrieve data for a specific continent, country or subregion by calling the appropriate datamodel.
|
18
|
+
|
19
|
+
.. code-block:: python
|
20
|
+
|
21
|
+
# initialize a country object and retrieve the demographics attribute
|
22
|
+
>>> nl = the_datagarden_api.netherlands # or nl = the_datagarden_api.NL
|
23
|
+
>>> nl_demographics = nl.demographics()
|
24
|
+
TheDataGardenRegionalDataModel : Demographics : (count=5)
|
25
|
+
|
26
|
+
In this example the `nl_demographics` object holds 5 records. Each record contains demographic data for the Netherlands for a specific
|
27
|
+
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.
|
28
|
+
|
29
|
+
.. code-block:: python
|
30
|
+
|
31
|
+
# convert demographics data to a polars dataframe
|
32
|
+
>>> dataframe = nl_demographics.full_model_to_polars()
|
33
|
+
>>> print(dataframe["period", "source_name", "data_model_name", "population.total", "population.total_male", "population.total_female"])
|
34
|
+
|
35
|
+
.. code-block:: text
|
36
|
+
|
37
|
+
┌───────────────┬────────────┬─────────────────┬──────────────────┬───────────────────────┬─────────────────────────┐
|
38
|
+
│ period ┆ source_name┆ data_model_name ┆ population.total ┆ population.total_male ┆ population.total_female │
|
39
|
+
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
|
40
|
+
│ str ┆ str ┆ str ┆ f64 ┆ f64 ┆ f64 │
|
41
|
+
╞═══════════════╪════════════╪═════════════════╪══════════════════╪═══════════════════════╪═════════════════════════╡
|
42
|
+
│ 2022-01-01T0Z ┆ Eurostat ┆ Demographics ┆ null ┆ 8.745468e6 ┆ 8.845204e6 │
|
43
|
+
│ 2022-01-01T0Z ┆ United Nat ┆ Demographics ┆ 1.7789347e7 ┆ 8.890013e6 ┆ 9.014408e6 │
|
44
|
+
│ 2023-01-01T0Z ┆ Eurostat ┆ Demographics ┆ null ┆ 8.850309e6 ┆ 8.960982e6 │
|
45
|
+
│ 2023-01-01T0Z ┆ United Nat ┆ Demographics ┆ 1.8019495e7 ┆ 8.986255e6 ┆ 9.106269e6 │
|
46
|
+
│ 2024-01-01T0Z ┆ United Nat ┆ Demographics ┆ 1.8165554e7 ┆ 9.055978e6 ┆ 9.172763e6 │
|
47
|
+
└───────────────┴────────────┴─────────────────┴──────────────────┴───────────────────────┴─────────────────────────┘
|
48
|
+
|
49
|
+
The demographics model holds lots of submodels and attributes. In this example only a limited number of attributes are listed
|
50
|
+
as the dataframe is way too large to display. For all models and their details see the model data documentation at
|
51
|
+
`The DataGarden Data Documentation <https://www.the-datagarden.io/data-docs>`_.
|
52
|
+
|
53
|
+
Getting started with the SDK
|
54
|
+
----------------------------
|
55
|
+
You can start using the SDK out of the box by simply instatiating the TheDataGardenAPI object:
|
56
|
+
|
57
|
+
.. code-block:: python
|
58
|
+
|
59
|
+
# Starting with the datagarden API
|
60
|
+
>>> from the-datagarden import TheDataGardenAPI
|
61
|
+
>>> the_datagarden_api = TheDataGardenAPI()
|
62
|
+
|
63
|
+
.. code-block:: console
|
64
|
+
|
65
|
+
Welcome to The Data Garden API.
|
66
|
+
|
67
|
+
You can start using the API with an account from The-Datagarden.io.
|
68
|
+
Please provide your credentials or create a new account.
|
69
|
+
Check www.the-datagarden.io for more information.
|
70
|
+
|
71
|
+
Do you want to (1) create a new account or (2) provide existing credentials? Enter 1 or 2:
|
72
|
+
|
73
|
+
|
74
|
+
simply select 1 to create a new account.
|
75
|
+
|
76
|
+
.. code-block:: console
|
77
|
+
|
78
|
+
Enrolling in The Data Garden API...
|
79
|
+
|
80
|
+
Enter your email: <your-email>
|
81
|
+
Enter your password: <your-password>
|
82
|
+
Confirm your password: <your-password>
|
83
|
+
|
84
|
+
Successfully enrolled in The Data Garden API.
|
85
|
+
Initializing : TheDatagardenEnvironment
|
86
|
+
At: https://www.the-datagarden.io/
|
87
|
+
|
88
|
+
If you already have an account at the-datagarden.io, you can either select option 2 or directly provide your credentials
|
89
|
+
when creating the TheDataGardenAPI object:
|
90
|
+
|
91
|
+
.. code-block:: python
|
92
|
+
|
93
|
+
# Retrieve a country object from the datagarden API
|
94
|
+
>>> from the-datagarden import TheDataGardenAPI
|
95
|
+
>>> the_datagarden_api = TheDataGardenAPI(email='your-email@example.com', password='your-password')
|
96
|
+
|
97
|
+
.. code-block:: console
|
98
|
+
|
99
|
+
Initializing : TheDatagardenEnvironment
|
100
|
+
At: https://www.the-datagarden.io/
|
101
|
+
|
102
|
+
A 3rd way to initialize the SDK is adding your credentials to the ``.env`` file.
|
103
|
+
|
104
|
+
|
105
|
+
Getting your first data from The-DataGarden API
|
106
|
+
-----------------------------------------------
|
107
|
+
Now that you have initialized the SDK, you can start retrieving data from The-DataGarden API.
|
108
|
+
For example, you can retrieve the demographics data for the Netherlands:
|
109
|
+
|
110
|
+
.. code-block:: python
|
111
|
+
|
112
|
+
# initialize a country object and retrieve the demographics attribute
|
113
|
+
>>> nl = the_datagarden_api.netherlands
|
114
|
+
>>> nl_demographics = nl.demographics
|
115
|
+
TheDataGardenRegionalDataModel : Demographics : (count=0)
|
116
|
+
|
117
|
+
This creates a country object ``nl`` for the Netherlands, which serves as your gateway to all Netherlands-related
|
118
|
+
data and its regional subdivisions.
|
119
|
+
|
120
|
+
In this getting started section we will work with a demographics object retrieved from the `nl` country object.
|
121
|
+
As shown in the example, the ``nl_demographics`` object can be retrieved by simply calling the `demographics`
|
122
|
+
attribute on the `nl` country object
|
123
|
+
|
124
|
+
The `nl_demographics` object starts empty (count=0). To populate it with data, simply call it as a function:
|
125
|
+
|
126
|
+
.. code-block:: python
|
127
|
+
|
128
|
+
# Calling the demographics attribute will populate it with demographics data from the API
|
129
|
+
>>> nl_demographics()
|
130
|
+
>>> nl_demographics
|
131
|
+
TheDataGardenRegionalDataModel : Demographics : (count=5)
|
132
|
+
|
133
|
+
When called without parameters, the API returns data using default settings, which in this case yields 5 records.
|
134
|
+
You can customize your data retrieval by specifying parameters such as time periods, period types, and data sources.
|
135
|
+
|
136
|
+
|
137
|
+
The DataGarden Regional DataModel
|
138
|
+
---------------------------------
|
139
|
+
When you retrieve data like ``nl_demographics``, you're working with a ``TheDataGardenRegionalDataModel`` object. This object acts as a container that holds:
|
140
|
+
|
141
|
+
1. A collection of ``TheDataGardenRegionalDataRecord`` objects
|
142
|
+
2. Metadata about the records (region, time period, data source, etc.)
|
143
|
+
|
144
|
+
You can easily transform this data into pandas or polars DataFrames for analysis. Here's an example showing population data for the Netherlands:
|
145
|
+
|
146
|
+
.. code-block:: python
|
147
|
+
|
148
|
+
>>> nl = the_datagarden_api.netherlands
|
149
|
+
>>> nl_demographics = nl.demographics(period_from="2010-01-01", source="united nations")
|
150
|
+
>>> # Convert to DataFrame, mapping 'population.total' to column name 'pop_count'
|
151
|
+
>>> df = nl_demographics.to_polars({"pop_count": "population.total"}) # or to_pandas(...)
|
152
|
+
>>> df["name", "source_name", "period", "data_model_name", "total"] # for readability only a limited number of columns are displayed
|
153
|
+
┌─────────────┬────────────────┬─────────────────┬─────────────────┬─────────────┐
|
154
|
+
│ name ┆ source_name ┆ period ┆ data_model_name ┆ pop_count │
|
155
|
+
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
|
156
|
+
│ str ┆ str ┆ str ┆ str ┆ f64 │
|
157
|
+
╞═════════════╪════════════════╪═════════════════╪═════════════════╪═════════════╡
|
158
|
+
│ Netherlands ┆ United Nations ┆ 2010-01-010:00Z ┆ Demographics ┆ 1.6729801e7 │
|
159
|
+
│ Netherlands ┆ United Nations ┆ 2011-01-010:00Z ┆ Demographics ┆ 1.6812669e7 │
|
160
|
+
│ … ┆ … ┆ … ┆ … ┆ … │
|
161
|
+
│ Netherlands ┆ United Nations ┆ 2023-01-010:00Z ┆ Demographics ┆ 1.8019495e7 │
|
162
|
+
│ Netherlands ┆ United Nations ┆ 2024-01-010:00Z ┆ Demographics ┆ 1.8165554e7 │
|
163
|
+
└─────────────┴────────────────┴─────────────────┴─────────────────┴─────────────┘
|
164
|
+
|
165
|
+
Each time you call the ``nl_demographics`` object with different parameters,
|
166
|
+
new demographic records for the specified subregions, periods, and/or sources are added to the existing ``nl_demographics`` object.
|
167
|
+
After you've gathered all the records you need, you can convert the entire collection into a dataframe for further analysis.
|
168
|
+
|
169
|
+
|
170
|
+
Retrieving GeoJSON data
|
171
|
+
-----------------------
|
172
|
+
Retrieving the GeoJSON for the Netherlands and its provinces is straightforward as well:
|
173
|
+
|
174
|
+
.. code-block:: python
|
175
|
+
|
176
|
+
>>> nl_geojson = nl.geojsons()
|
177
|
+
>>> nl_geojson
|
178
|
+
TheDataGardenRegionGeoJSONModel : GeoJSON : (count=1)
|
179
|
+
>>> nl_geojson(region_level=2) # Retrieve GeoJSON for 2nd regional level (provinces)
|
180
|
+
TheDataGardenRegionGeoJSONModel : GeoJSON : (count=13) # 12 provinces + 1 country
|
181
|
+
>>> df = nl_geojson.to_polars()
|
182
|
+
>>> df["name", "region_type", "local_region_code", "region_level", "feature"]
|
183
|
+
┌───────────────┬─────────────┬───────────────┬──────────────┬────────────────────────┐
|
184
|
+
│ name ┆ region_type ┆ local_region_c┆ region_level ┆ feature │
|
185
|
+
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
|
186
|
+
│ str ┆ str ┆ str ┆ i64 ┆ struct[3] │
|
187
|
+
╞═══════════════╪═════════════╪═══════════════╪══════════════╪════════════════════════╡
|
188
|
+
│ Netherlands ┆ country ┆ 528 ┆ 0 ┆ {"Feature",{"Netherland│
|
189
|
+
│ Drenthe ┆ province ┆ NL13 ┆ 2 ┆ {"Feature",{"Drenthe",2│
|
190
|
+
│ … ┆ … ┆ … ┆ … ┆ … │
|
191
|
+
│ Zuid-Holland ┆ province ┆ NL33 ┆ 2 ┆ {"Feature",{"Zuid-Holla│
|
192
|
+
└───────────────┴─────────────┴───────────────┴──────────────┴────────────────────────┘
|
193
|
+
|
194
|
+
For readability, the output only a limited number of dataframe columns are displayed.
|
195
|
+
Attributes in both the demographics and geojson dataframes are available to connect the geojson to
|
196
|
+
the demographics data. This allows you quickly make data sets that contain both demographics and geojson data
|
197
|
+
for further analysis or visualisation in map applications.
|
198
|
+
|
199
|
+
|
200
|
+
Read more
|
201
|
+
---------
|
202
|
+
|
203
|
+
* `The DataGarden Website <https://www.the-datagarden.io>`_
|
204
|
+
* `API Documentation <https://www.the-datagarden.io/api-docs>`_
|
205
|
+
* `The Datagarden Models <https://www.the-datagarden.io/data-docs>`_
|
206
|
+
* `GitHub Repository <https://github.com/MaartendeRuyter/dg-the-datagarden>`_
|
207
|
+
|
208
|
+
|
209
|
+
Access to The DataGarden API
|
210
|
+
----------------------------
|
211
|
+
To use the DataGarden SDK, you need access to the The DataGarden API. Simply register for free at https://www.the-datagarden.io
|
212
|
+
and you will have an inital free access account to the API with access to country and continent data.
|
213
|
+
|
214
|
+
Visit https://www.the-datagarden.io to register for free.
|
@@ -0,0 +1,84 @@
|
|
1
|
+
[project]
|
2
|
+
name = "the-datagarden"
|
3
|
+
version = "1.2.3"
|
4
|
+
description = "Public data made easy."
|
5
|
+
readme = "README.rst"
|
6
|
+
requires-python = ">=3.10"
|
7
|
+
license = { text = "MIT" } # Specifies the MIT license
|
8
|
+
authors = [
|
9
|
+
{ name = "Maarten de Ruyter", email = "info@the-datagarden.io" }
|
10
|
+
]
|
11
|
+
dependencies = [
|
12
|
+
"click>=8.1.7",
|
13
|
+
"pandas>=2.2.3",
|
14
|
+
"polars>=1.15.0",
|
15
|
+
"pydantic>=2.9.2",
|
16
|
+
"pyjwt>=2.10.0",
|
17
|
+
"python-decouple>=3.8",
|
18
|
+
"requests>=2.32.3",
|
19
|
+
"the-datagarden-models>=1.6.3",
|
20
|
+
]
|
21
|
+
classifiers = [
|
22
|
+
"Programming Language :: Python :: 3",
|
23
|
+
"Programming Language :: Python :: 3.10",
|
24
|
+
"Programming Language :: Python :: 3.11",
|
25
|
+
"Programming Language :: Python :: 3.12",
|
26
|
+
"Programming Language :: Python :: 3.13",
|
27
|
+
"License :: OSI Approved :: MIT License",
|
28
|
+
"Operating System :: OS Independent",
|
29
|
+
"Development Status :: 4 - Beta",
|
30
|
+
"Intended Audience :: Developers",
|
31
|
+
"Intended Audience :: Financial and Insurance Industry",
|
32
|
+
"Intended Audience :: Science/Research",
|
33
|
+
"Intended Audience :: Healthcare Industry",
|
34
|
+
"Topic :: Scientific/Engineering :: GIS",
|
35
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
36
|
+
"Topic :: Scientific/Engineering :: Information Analysis",
|
37
|
+
"Topic :: Scientific/Engineering :: Visualization",
|
38
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
39
|
+
"Topic :: Utilities",
|
40
|
+
|
41
|
+
]
|
42
|
+
|
43
|
+
[dependency-groups]
|
44
|
+
dev = [
|
45
|
+
"mypy>=1.13.0",
|
46
|
+
"pre-commit>=4.0.1",
|
47
|
+
"pytest>=8.3.3",
|
48
|
+
"ruff>=0.7.4",
|
49
|
+
"sphinx>=8.1.3",
|
50
|
+
"types-requests>=2.32.0.20241016",
|
51
|
+
]
|
52
|
+
|
53
|
+
[project.scripts]
|
54
|
+
the-datagarden = "the_datagarden.cli:main"
|
55
|
+
|
56
|
+
[project.urls]
|
57
|
+
"Read the Docs" = "https://dg-the-datagarden.readthedocs.io/en/stable/"
|
58
|
+
"The-DataGarden" = "https://www.the-datagarden.io/"
|
59
|
+
"API documentation" = "https://www.the-datagarden.io/api-docs"
|
60
|
+
"Source" = "https://github.com/the-datagarden/the-datagarden"
|
61
|
+
|
62
|
+
|
63
|
+
[tool.ruff]
|
64
|
+
line-length = 110
|
65
|
+
|
66
|
+
[tool.ruff.lint]
|
67
|
+
select = [
|
68
|
+
"C", # mccabe rules
|
69
|
+
"F", # pyflakes rules
|
70
|
+
"E", # pycodestyle error rules
|
71
|
+
"W", # pycodestyle warning rules
|
72
|
+
"B", # flake8-bugbear rules
|
73
|
+
"I", # isort rules
|
74
|
+
]
|
75
|
+
ignore = [
|
76
|
+
"C901", # max-complexity-10
|
77
|
+
]
|
78
|
+
|
79
|
+
[tool.ruff.format]
|
80
|
+
indent-style = "space"
|
81
|
+
quote-style = "double"
|
82
|
+
|
83
|
+
[tool.mypy]
|
84
|
+
ignore_missing_imports = true
|
@@ -0,0 +1,8 @@
|
|
1
|
+
from .api.authentication.environment import TheDatagardenLocalEnvironment
|
2
|
+
from .api.base import TheDataGardenAPI, TheDatagardenProductionEnvironment
|
3
|
+
|
4
|
+
__all__ = [
|
5
|
+
"TheDataGardenAPI",
|
6
|
+
"TheDatagardenProductionEnvironment",
|
7
|
+
"TheDatagardenLocalEnvironment",
|
8
|
+
]
|
@@ -0,0 +1,19 @@
|
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
|
3
|
+
from requests import Response
|
4
|
+
|
5
|
+
from the_datagarden.abc.authentication import DatagardenEnvironment
|
6
|
+
|
7
|
+
|
8
|
+
class BaseApi(ABC):
|
9
|
+
@abstractmethod
|
10
|
+
def __init__(self, environment: type[DatagardenEnvironment] | None = None): ...
|
11
|
+
|
12
|
+
@abstractmethod
|
13
|
+
def retrieve_from_api(
|
14
|
+
self,
|
15
|
+
url_extension: str,
|
16
|
+
method: str = "GET",
|
17
|
+
payload: dict | None = None,
|
18
|
+
params: dict | None = None,
|
19
|
+
) -> Response | None: ...
|
@@ -0,0 +1,42 @@
|
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
from typing import TypedDict
|
3
|
+
|
4
|
+
|
5
|
+
class TheDatagardenCredentialsDict(TypedDict):
|
6
|
+
email: str
|
7
|
+
password: str
|
8
|
+
|
9
|
+
|
10
|
+
class BaseDataGardenCredentials(ABC):
|
11
|
+
"""Protocol for the datagarden credentials"""
|
12
|
+
|
13
|
+
@classmethod
|
14
|
+
@abstractmethod
|
15
|
+
def credentials(
|
16
|
+
cls, the_datagarden_api_url: str, email: str | None = None, password: str | None = None
|
17
|
+
) -> TheDatagardenCredentialsDict: ...
|
18
|
+
|
19
|
+
|
20
|
+
class DatagardenEnvironment(ABC):
|
21
|
+
"""Protocol for the datagarden environment"""
|
22
|
+
|
23
|
+
CREDENTIALS: type[BaseDataGardenCredentials]
|
24
|
+
THE_DATAGARDEN_URL: str
|
25
|
+
ECHO_INIT: bool = True
|
26
|
+
|
27
|
+
def __init__(self):
|
28
|
+
if self.ECHO_INIT:
|
29
|
+
print("Initializing :", self.__class__.__name__)
|
30
|
+
print("At :", self.the_datagarden_url)
|
31
|
+
|
32
|
+
def credentials(
|
33
|
+
self, email: str | None = None, password: str | None = None
|
34
|
+
) -> TheDatagardenCredentialsDict:
|
35
|
+
return self.CREDENTIALS.credentials(self.the_datagarden_url, email, password)
|
36
|
+
|
37
|
+
@property
|
38
|
+
def the_datagarden_url(self) -> str:
|
39
|
+
url = self.THE_DATAGARDEN_URL
|
40
|
+
if url[-1] != "/":
|
41
|
+
return url + "/"
|
42
|
+
return url
|