The DataGarden Models SDK

In order to support the Datagarden data models, we provide a Datagarden Models Python SDK. In this SDK all data models used in the Datagarden are provided as Pydantic datamodels. If you choose to work directly with the API you will get the data in JSON format. You can then use the DataGarden Models SDK to get additional model specific functionality on the Datamodels which are not available when working with the JSON data.

Next to the Datagarden Models SDK we also provide a Datagarden SDK. This used the Datagarden Models SDK under the hood and direclty works with the API to provide you with datagarden data in datagarden models format. Using the DataGarden SDK is the easiest way to get started with the Datagarden data. See The Datagarden SDK for more details.

The Datagarden Models SDK is fully documented on ReadTheDocs. Read all about the SDK in the documentation.

A quick example

The SDK allows you to easily retrieve Economics data for a country from the Datagarden.

			# retrieve economics data for germany
  >>> from datagarden_models import DatagardenModels
  >>> economics_model = DatagardenModels.ECONOMICS
  >>>
  >>> url = "https://www.the-datagarden.io/country/netherlands/regional_data/"
  >>> 
  >>> headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer <access_token>'}
  >>> payload = [{"model": "economics"}]
  >>> 
  >>> response = requests.request("POST", url, headers=headers, payload=payload)
  >>> response_data = response.json()
  >>> economics_data = response_data["data_by_region"][0]["data_objects_for_region"][0]["data"]
  >>> economics_data_as_data_model = economics_model(**economics_data)
  >>> # now you have access to all the methods and attributes of the economics data model
  >>> gdp = economics_data_as_data_model.gdp # returns gdp as Pydantic model
  >>> public_spending = economics_data_as_data_model.public_spending # returns public spending as Pydantic model
  >>> and so on...
			
		

As the initial response can contain many economic data models for the netherlands or subregions of the netherlands, and for different sources and time periods it is a bit of work to get to the actual data model out of the json. See regional data response documentation for more details on how the response is structured.