DataChile API

DataChile has a data API, which delivers the info to build the charts and generate the texts site-wide.

First Steps

DataChile uses Mondrian-REST, which is a server side software component that allows creation of HTTP APIs for accessing a database by specifying the logical structure of the information.

To use the DataChile API, it is necessary to know some concepts that will facilitate its use, which we will be explain then.

Cube

A cube is a collection of dimensions and measures.

In DataChile, each dataset is grouped in a cube. The design of the API query language is centered around 3 operations: Drilldown, Cut and Measure. To exemplify the concepts, exports dataset - which represents Chile's exports - will be used as a reference.

Drilldown

Some previous definitions:
  • A member is a point within a dimension determined by a particular set of attribute values. The gender hierarchy has the two members 'Male' and 'Female'. 'Concepcion', 'Bio-Bio' and 'Chile' are all members of the geography hierarchy.
  • A level is a collection of members which have the same distance from the root of the hierarchy.
  • A hierarchy is a set of members organized into a structure for convenient analysis. For example, the geography hierarchy consists of the city, region, and country. The hierarchy allows you to form intermediate sub-totals: the sub-total for a region is the sum of the sub-totals of all of the cities in that region.
  • A dimension is a collection of hierarchies which discriminate on the same fact table attribute (say, the day that a sale occurred).

A drilldown allows to move from one level of detail to the next. The drilldown structure for queries in the cube is [Dimension].[Hierarchy].[Level]

Measure

Scalar variable associated with a particular fact in the cube data.

Cut

Allows the user to specify a filter, which effectively restricts the cube in which the aggregations are performed. Cutting the exports cube along the [Region] .[8] member in the Geography dimension, will only consider cells by Bio-Bio. Multiple cuts can be specified in a single query.

Syntax

URL BASE https://chilecube.datachile.io
GET /cubes/{{cube_name}}/dimensions/{{dimension_name}}/levels/{{level_name}}/members

For a particular cube, get the members belonging to a certain level in a dimension.

GET /cubes/{{cube_name}}/aggregate

The single entry point for aggregation operations in Mondrian-REST is /aggregate, which accepts the described parameters then.

ParameterTypeDescription
drilldown[]stringFor create a drilldown, you must considerate: Dimension, Hierarchy, Level. [Dimension].[Hierarchy].[Level]
measures[]stringdocumentation_api.descriptions.measures[]
cut[]stringYou must concatenate drilldown where you need to make the cut with specific Level ID member. [Dimension].[Hierarchy].[Level].&[member_id]1
nonemptybooleanReturns the set of tuples that are not empty from a specified set, based on the cross product of the specified set with a second set.
distinctbooleanEvaluates a specified set, removes duplicate tuples from the set, and returns the resulting set.
parentsbooleanIf depth level is higher than 1, get ID and name from parent levels.
sparsebooleanCheck if a certain tuple is NOT in the aggregation, this is not included in the resulting table.
1. If the query is made directly in URL, it must be replaced & by %26 to avoid problems of cutting parsing.

Field List

CubeDrilldownsMeasures
mortality[Date].[Date].[Year][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Age Range].[Age Range DEIS].[Age Group][Age Range].[Age Range DEIS].[Age Range]

Number of deaths

Rate Comuna

Rate Region

Rate Country

tax_data[Date].[Date].[Year][Tax Geography].[Geography].[Region][Tax Geography].[Geography].[Comuna][ISICrev4].[ISICrev4].[Level 1][ISICrev4].[ISICrev4].[Level 2][ISICrev4].[ISICrev4].[Level 3][ISICrev4].[ISICrev4].[Level 4]

Output

Labour

Labour Cost

Investment

Intermediates

Value Added

Production per worker

Value added per worker

Output RCA

internet_access[Geography].[Geography].[Region][Zone].[Zone].[Zone][Internet Plan].[Binary Survey Response].[Binary Survey Response][Home Access].[Binary Survey Response].[Binary Survey Response][Desktop Access].[Binary Survey Response].[Binary Survey Response][Laptop Access].[Binary Survey Response].[Binary Survey Response][Tablet Access].[Binary Survey Response].[Binary Survey Response][Cellphone Access].[Binary Survey Response].[Binary Survey Response][Games or Consoles Access].[Binary Survey Response].[Binary Survey Response][TV Access].[Binary Survey Response].[Binary Survey Response][Date].[Date].[Year]

Number of records

Expansion factor

population_estimate[Date].[Date].[Year][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Sex].[Sex].[Sex][Age Range].[Age Range].[Age Range]

Number of records

Population

Population Rank

Population Rank Decile

Population Rank Total

census_population[Geography].[Geography].[Region][Geography].[Geography].[Comuna][Zone].[Zone].[Zone][Sex].[Sex].[Sex][Aboriginal People].[Aboriginal People].[Aboriginal People Group][Aboriginal People].[Aboriginal People].[Aboriginal People Subgroup][Aboriginal People].[Aboriginal People].[Aboriginal People][Children Born Alive].[Children Born Alive].[Children Born Alive][Highest Level Approved].[Highest Level Approved].[Highest Level Approved][Arrival To Chile].[Arrival To Chile].[Year Range][Arrival To Chile].[Arrival To Chile].[Year Of Arrival To Chile][Formal Education].[Formal Education].[Formal Education][Residence Comuna 5 Years Ago].[Residence Comuna 5 Years Ago].[Residence Comuna 5 Years Ago][Habitual Residence].[Habitual Residence].[Habitual Residence][Children Currently Alive].[Children Currently Alive].[Children Currently Alive][Economic Activity].[Economic Activity].[Economic Activity][Birth Country].[Birth Country].[Birth Country][Birth Comuna].[Birth Comuna].[Birth Comuna][Birth Place].[Birth Place].[Birth Place][Residence Comuna].[Residence Comuna].[Residence Comuna][Residence Country].[Residence Country].[Residence Country][Residence Country 5 Years Ago].[Residence Country 5 Years Ago].[Residence Country 5 Years Ago][Residence 5 Years Ago].[Residence 5 Years Ago].[Residence 5 Years Ago][Highest Course Approved].[Highest Course Approved].[Highest Course Approved][Calculated Age Range].[Calculated Age Range].[Age Range][Calculated Age Range].[Calculated Age Range].[Age][Native People].[Native People].[Native People]

People

% People

junaeb_vulnerability[Date].[Date].[Year][Administration].[Administration].[Administration][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Institution].[Institution].[Administration][Institution].[Institution].[Institution][Zone].[Zone].[Zone][Priority].[Priority].[Priority]

Count

mds_abandonment_rate[Geography].[Geography].[Region][Geography].[Geography].[Comuna][Year].[Year].[Year][Education Level].[Education Level].[Education Level][Promotion Status].[Promotion Status].[Promotion Status]

Number of Students

Abandonment Percentage

casen_banking[Date].[Date].[Year][Date].[Date].[Month][Date].[Date].[Day][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Debit Card].[Binary Survey Response].[Binary Survey Response][Bank Credit Card].[Binary Survey Response].[Binary Survey Response][Store Credit Card].[Binary Survey Response].[Binary Survey Response][Checks].[Binary Survey Response].[Binary Survey Response][Credit Line].[Binary Survey Response].[Binary Survey Response]

Number of records

Expansion Factor Region

Expansion Factor Comuna

Expansion Factor

education_sned[Date].[Date].[Year][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Institutions].[Institution].[Administration][Institutions].[Institution].[Institution][Cluster].[Cluster].[Stage 1a][Cluster].[Cluster].[Stage 1b][Cluster].[Cluster].[Stage 2][Administration].[Administration].[Administration][Subsidized 100%].[Subsidized 100%].[Subsidized 100%][Subsidized 60%].[Subsidized 60%].[Subsidized 60%]

Number of records

Avg efectiveness

Avg overcoming

Avg initiative

Avg integration

Avg improvement

Avg fairness

Avg sned_score

education_enrollment[Date].[Date].[Year][Date].[Date].[Month][Date].[Date].[Day][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Sex].[Sex].[Sex][Zone].[Zone].[Zone][Administration].[Administration].[Administration][Institutions].[Institution].[Institution][Teachings].[Teaching].[Teaching]

Number of records

Average Age

imports[Date].[Date].[Year][Origin Country].[Country].[Continent][Origin Country].[Country].[Country][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Import HS].[HS].[HS0][Import HS].[HS].[HS2][Import HS].[HS].[HS4][Country].[Country].[Continent][Country].[Country].[Country]

CIF US

Geo Rank Across Time

immigration[Date].[Date].[Year][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Origin Country].[Country].[Continent][Origin Country].[Country].[Country][Sex].[Sex].[Sex][Education].[Education].[Education][Activity].[Activity].[Activity][Visa Type].[Visa Type].[Visa Type][Calculated Age Range].[Calculated Age Range].[Age Range]

Number of visas

Average Age

nesi_income[Date].[Date].[Year][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Sex].[Sex].[Sex][Age Range].[Age Range].[Age Range][ISCO].[ISCO].[ISCO][ICSE].[ICSE].[ICSE][ISCED].[ISCED].[ISCED][Occupation Length].[Occupation Length].[Occupation Length][Workday].[Workday].[Workday][Income Range].[Income Range].[Income Range]

Income

Expansion Factor

Median Income

Weighted Income

Weighted Median Income Rank

Weighted Median Income Decile

Weighted Median Income Total

imports_old[Date].[Date].[Year][Date].[Date].[Month][Date].[Date].[Day][Origin Country].[Country].[Continent][Origin Country].[Country].[Country][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Import HS].[HS].[HS0][Import HS].[HS].[HS2][Import HS].[HS].[HS4][Country].[Country].[Continent][Country].[Country].[Country]

CIF US

Geo Rank Across Time

life_expectancy[Date].[Date].[Year][Geography].[Geography].[Region][Sex].[Sex].[Sex]

Number of records

Life Expectancy AVG

Mortality rate per 100 inhabitants AVG

casen_household[Date].[Date].[Year][Date].[Date].[Month][Date].[Date].[Day][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Zone Id].[Zone Id].[Zone Id][Household Type].[Household Type].[Household Type][Walls Material].[Walls Material].[Walls Material][Floor Material].[Floor Material].[Floor Material][Ceiling Material].[Ceiling Material].[Ceiling Material][Households In Land].[Households In Land].[Households In Land][Land Using].[Land Using].[Land Using][Household Sq Meters].[Household Sq Meters].[Household Sq Meters][Household Using].[Household Using].[Household Using][Family Member Owner].[Family Member Owner].[Family Member Owner][Family Member Owner 2].[Family Member Owner 2].[Family Member Owner 2][Subsidy Or Program].[Subsidy Or Program].[Subsidy or Program][Credit].[Credit].[Credit][Paying Credit].[Paying Credit].[Paying Credit][Water Source].[Water Source].[Water Source][Water Distribution].[Water Distribution].[Water Distribution][Waste Disposal].[Waste Disposal].[Waste Disposal][Electricity].[Electricity].[Electricity][Rooms].[Rooms].[Rooms][Bathrooms].[Bathrooms].[Bathrooms][Families In Household].[Families In Household].[Families In Household][Reason To Share].[Reason To Share].[Reason To Share][Cooking Energy Source].[Energy Source Survey Response].[Energy Source Survey Response][Heating Energy Source].[Energy Source Survey Response].[Energy Source Survey Response][Hot Water Energy Source].[Energy Source Survey Response].[Energy Source Survey Response][Less Than 8 Blocks Public Transport].[Binary Survey Response].[Binary Survey Response][Less Than 20 Blocks Educational Center].[Binary Survey Response].[Binary Survey Response][Less Than 20 Blocks Health Center].[Binary Survey Response].[Binary Survey Response][Less Than 20 Blocks Market].[Binary Survey Response].[Binary Survey Response][Less Than 20 Blocks Atm].[Binary Survey Response].[Binary Survey Response][Less Than 20 Blocks Sports Center].[Binary Survey Response].[Binary Survey Response][Less Than 20 Blocks Green Areas].[Binary Survey Response].[Binary Survey Response][Less Than 20 Blocks Community Equipment].[Binary Survey Response].[Binary Survey Response][Less Than 20 Blocks Pharmacy].[Binary Survey Response].[Binary Survey Response][Affected By Acoustic Contamination].[Frequency Survey Response].[Frequency Survey Response][Affected By Air Contamination].[Frequency Survey Response].[Frequency Survey Response][Affected By River Or Lake Contamination].[Frequency Survey Response].[Frequency Survey Response][Affected By Public Water Source Contamination].[Frequency Survey Response].[Frequency Survey Response][Affected By Graffitis Or Advertising].[Frequency Survey Response].[Frequency Survey Response][Affected By Accumulation Of Trash Public Areas].[Frequency Survey Response].[Frequency Survey Response][Affected By Animal Or Insect Plague].[Frequency Survey Response].[Frequency Survey Response]

Number of records

Expansion Factor Region

Expansion Factor Comuna

Expansion Factor

exports[Date].[Date].[Year][Destination Country].[Country].[Continent][Destination Country].[Country].[Country][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Export HS].[HS].[HS0][Export HS].[HS].[HS2][Export HS].[HS].[HS4][Country].[Country].[Continent][Country].[Country].[Country]

FOB US

Geo Rank

Geo Rank Across Time

HS Rank

HS Rank Decile

HS Rank Total

Exports for year (sum_c_p_xcp)

Exports RCA

disabilities[Date].[Date].[Year][Geography].[Geography].[Region][Sex].[Sex].[Sex][Disability Grade].[Disability Grade].[Disability Grade]

Number of records

Expansion Factor Region

education_performance_new[Year].[Year].[Year][Institution].[Institution].[Administration][Institution].[Institution].[Institution][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Sex].[Sex].[Sex][Administration].[Administration].[Administration]

Number of records

Average PSU

Average NEM

election_participation[Date].[Date].[Year][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Election Type].[Election Type].[Election Type]

Number of records

Electors

Votes

Participation

casen_health_system[Date].[Date].[Year][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Health System].[Health System].[Health System Group][Health System].[Health System].[Health System]

Number of records

Expansion Factor Region

Expansion Factor Comuna

Expansion Factor

election_results_update[Date].[Date].[Year][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Election Type].[Election Type].[Election Type][Party].[Party].[Partido][Candidates].[Candidates].[Candidate][Coalition].[Coalition].[Coalition][Elected].[Elected].[Elected]

Number of records

Votes

rd_survey[Date].[Date].[Year][Date].[Date].[Month][Date].[Date].[Day][Headquarters Country].[Country].[Continent][Headquarters Country].[Country].[Country][ISICrev4].[ISICrev4].[Level 1][Business Type].[Business Type].[Business Type][Ownership Type].[Ownership Type].[Ownership Type]

sales

exports

Total Spending

gasto_region_15

gasto_region_1

gasto_region_2

gasto_region_3

gasto_region_4

gasto_region_5

gasto_region_6

gasto_region_7

gasto_region_8

gasto_region_9

gasto_region_14

gasto_region_10

gasto_region_11

gasto_region_12

gasto_region_13

staff_region_15

staff_region_1

staff_region_2

staff_region_3

staff_region_4

staff_region_5

staff_region_6

staff_region_7

staff_region_8

staff_region_9

staff_region_14

staff_region_10

staff_region_11

staff_region_12

staff_region_13

emergency_care[Date].[Date].[Year][Date].[Date].[Quarter][Date].[Date].[Month][Date].[Date].[Week][Geography].[Geography].[Region][Emergency].[Emergency].[Action-L1][Emergency].[Emergency].[Cause-L2][Emergency].[Emergency].[Name-L3][Age].[Age].[Age]

Total

health_access[Date].[Date].[Year][Geography].[Geography].[Region]

Number of records

Primary Healthcare SUM

Specialized Healthcare SUM

Urgency Healthcare SUM

Primary Healthcare AVG

Specialized Healthcare AVG

Urgency Healthcare AVG

Dental Discharges Per 100 inhabitants AVG

census_housing[Geography].[Geography].[Region][Geography].[Geography].[Comuna][Zone].[Zone].[Zone][Housing Type].[Housing Type].[Housing Type][Housing Occupation].[Housing Occupation].[Housing Occupation][Walls Material].[Walls Material].[Walls Material][Ceiling Material].[Ceiling Material].[Ceiling Material][Floor Material].[Floor Material].[Floor Material][Rooms].[Rooms].[Rooms][Water Source].[Water Source].[Water Source]

Housing Units

Household

People

education_employability[Careers].[Careers].[Career Group][Careers].[Careers].[Career][Higher Institutions].[Higher Institutions].[Higher Institution Group][Higher Institutions].[Higher Institutions].[Higher Institution Subgroup][Higher Institutions].[Higher Institutions].[Higher Institution][Accreditations].[Accreditations].[Accreditation][Avg Income 4th year].[Avg Income 4th year].[Avg Income 4th year]

Number of records

Avg subsidized

Avg Retention 1st year

Avg Duration in semesters

Avg employability 1st year

Avg anual payment 2016

Sum anual payment 2016

psu[Date].[Date].[Year][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Sex].[Sex].[Sex][Calculated PSU Bucket].[Calculated PSU Bucket].[Bucket]

Number of records

Avg language test

Avg math test

PSU AVG individual

PSU Average

PSU Rank

PSU Rank Decile

PSU Rank Total

mortality_under_one[Date].[Date].[Year][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Age Range].[Age Range DEIS].[Age Group][Age Range].[Age Range DEIS].[Age Range]

Number of deaths

Rate Comuna

Rate Region

Rate Country

mortality_one_to_ten[Date].[Date].[Year][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Sex].[Sex].[Sex][Age Range].[Age Range DEIS].[Age Group][Age Range].[Age Range DEIS].[Age Range]

Number of deaths

Rate Comuna

Rate Region

Rate Country

death_causes[Date].[Date].[Year][Geography].[Geography].[Region][Sex].[Sex].[Sex][CIE 10].[CIE 10].[CIE 10]

Number of records

Casualities Count AVG

Casualities Count SUM

Casualities rate per 100 inhabitants

crimes[Date].[Date].[Year][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Crime].[Crime].[Crime Group][Crime].[Crime].[Crime]

Number of records

Cases

nene_quarter[Date].[Date].[Year][Date].[Date].[Moving Quarter][ISIC CAENES].[ISIC CAENES].[ISIC CAENES][Occupational Situation].[Occupational Situation].[Occupational Situation][General Economic Condition].[General Economic Condition].[General Economic Condition][Geography].[Geography].[Region][Sex].[Sex].[Sex][Age Range].[Age Range].[Age Range][ISCED].[ISCED].[ISCED][ICSE].[ICSE].[ICSE][ISCO].[ISCO].[ISCO]

Number of records

Expansion factor

Number of records Decile

Expansion Factor Decile

education_performance[Date].[Date].[Year][Date].[Date].[Month][Date].[Date].[Day][Geography].[Geography].[Region][Geography].[Geography].[Comuna][Sex].[Sex].[Sex][Zone].[Zone].[Zone][Administration].[Administration].[Administration][Institutions].[Institution].[Institution][Teachings].[Teaching].[Teaching]

Number of records

Average Score Average (?)

This data is provided by https://chilecube.datachile.io/cubes

Data call example

The next examples show how are builded the queries, using drilldowns, cuts and measures. Here you can see URL aspect and JSON returned related with the question: What number of people are in every health insurance at Concepcion?

Query

Output


    {
      "axes": [
        {
          "members": [
            {
              "name": "Expansion Factor Comuna",
              "full_name": "[Measures].[Expansion Factor Comuna]",
              "caption": "Expansion Factor Comuna",
              "key": "Expansion Factor Comuna",
              ...
            }
          ]
        },
        {
          "members": [
            {
              "name": "FONASA",
              "full_name": "[Health System].[FONASA]",
              "caption": "FONASA",
              "key": 1,
              ...
            },
            {
              "name": "Isapre",
              "full_name": "[Health System].[Isapre]",
              "caption": "Isapre",
              "key": 3,
              ...
            }
            ...
          ]
        }
      ],
      "axis_dimensions": [
        {
          "name": "Measures",
          "caption": "Measures",
          "type": "measures",
          "level": "MeasuresLevel",
          "level_depth": 0
        },
        {
          "name": "Health System",
          "caption": "Health System",
          "type": "standard",
          "level": "Health System Group",
          "level_depth": 1
        }
      ],
      "values": [
        [ 1130724.0 ],
        [ 62378.0 ],
        [ 255801.0 ],
        [ 81866.0 ]
      ]
    }
                

Complex Combinations

These criteria can be combined to define robust queries. Here are a few examples.

Select values of Valparaiso (ID 5) and Coquimbo (ID 4) regions.

For generate cuts for more than an ID, every cut must be separately by , within {}.

Get imports from every county in Chile between 2013 and 2015.

drilldown[]: [Origin Country].[Country].[Country]
drilldown[]: [Geography].[Geography].[Comuna]
drilldown[]: [Date].[Date].[Year]
measures[]: CIF US
cut[]: {[Date].[Date].[Year].&[2013], [Date].[Date].[Year].&[2014], [Date].[Date].[Year].&[2015]}

For generate cuts for more than an ID, every cut must be separately by , within {}.

Client for Javascript/Typescript

https://github.com/Datawheel/mondrian-rest-client

Client for Python

To encourage the use of the DataChile API, we have enabled in Python a pip module that allows to interact with the cubes.

For to install, you can use pip: pip install datachile


    from datachile import ChileCube

    client = ChileCube()

    query = client.get(
        "exports",
        {
            "drilldowns": [
                ["Date", "Year"],
                ["Destination Country", "Country", "Country"]
            ],
            "measures": ["FOB US"],
            "cuts": [
                {
                    "drilldown": ["Date", "Year"],
                    "values": [2012, 2013, 2014]
                }
            ],
            "parents": True
        }
    )

    print(query)
            

More information in https://github.com/datachile/datachile-python-client/