Is there a free API to get the population of every country ?
I've searched on the World Bank Open Data but I didn't find the API for it.
Is there a free API to get the population of every country ?
I've searched on the World Bank Open Data but I didn't find the API for it.
Yes, the World Bank offers an API access for free, and you can retrieve this kind of data quite easily. The API documentation is available here: https://datahelpdesk.worldbank.org/knowledgebase/topics/125589
In the "API Basic Call Structures" section, they give a very simple example of how to get the population of all countries in the year 2000, in XML format:
http://api.worldbank.org/v2/country/all/indicator/SP.POP.TOTL?date=2000.
Don't forget to follow their recommendations when using the API: https://datahelpdesk.worldbank.org/knowledgebase/articles/902064-development-best-practices
Countries API (FREE):
both do not need Authentication.
Austrian non-profit population.io has an API link on its homepage but I haven't signed up for it and thus not used it.
You can also get country population data from a SPARQL query to Wikidata:
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX schema: <http://schema.org/>
SELECT ?country ?countryQ ?countryLabel ?popDate (MAX(?population) as ?maxPop)
WHERE {
?country wdt:P31 wd:Q3624078;
wdt:P30 wd:Q46.
OPTIONAL { ?country p:P1082 ?popStmt.
?popStmt ps:P1082 ?population.
?popStmt pq:P585 ?popDate.
}
BIND (xsd:integer(REPLACE(STR(?country), "http://www.wikidata.org/entity/Q", "" )) as ?countryQ)
FILTER(?countryQ < 2000)
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?country ?countryQ ?countryLabel ?popDate
ORDER BY ASC(?countryQ) ASC( ?countryLabel)
LIMIT 10
Try this query, e.g. comment out the FILTER clause or change the LIMIT