Quickstart - Autocomplete API

A fast hands-on introduction to the Autocomplete API

Simple Example

Let's say that we are interested in getting all schools that begin with "stanf." The Autocomplete API is the perfect tool for doing this, because it allows us to find multiple schools using just a set of input characteristics.

The list of supported inputs includes the field that we're seeking and the text that we want to complete. In this example, we'll use the following parameters:

Input Parameters

Parameter NameParameter Value
fieldschool
textstanf
size10
prettyTrue

Using this information, we can now query the Autocomplete API to find schools beginning with "stanf":

import json

# See https://github.com/peopledatalabs/peopledatalabs-python
from peopledatalabs import PDLPY

# Create a client, specifying an API key
client = PDLPY(
    api_key="YOUR API KEY",
)

params = {
    "field": "school",
    "text": "stanf",
    "size": 10,
    "pretty": True
}

json_response = client.autocomplete(**params).json()

print(json_response)
curl -X GET -G \
  'https://api.peopledatalabs.com/v5/autocomplete'\
  -H 'X-Api-Key: xxxx' \
  --data-urlencode 'field=school'\
  --data-urlencode 'text=stanf'\
  --data-urlencode 'size=10'
// See https://github.com/peopledatalabs/peopledatalabs-js
import PDLJS from 'peopledatalabs';

const PDLJSClient = new PDLJS({ apiKey: "YOUR API KEY" });

const params = {
    "field": "school",
    "text": "stanf",
    "dize": 10,
    "pretty": true
}

PDLJSClient.autocomplete(params).then((data) => {
    console.log(data);
}).catch((error) => {
    console.log(error);
});
# See https://github.com/peopledatalabs/peopledatalabs-ruby
require 'peopledatalabs'

Peopledatalabs.api_key = 'YOUR API KEY'

response = Peopledatalabs::Autocomplete.retrieve(field: "school", text: "stanf", size: 10, pretty: true)

puts response
import requests, json

API_KEY = # ENTER YOUR API KEY

pdl_url = "https://api.peopledatalabs.com/v5/autocomplete"

params = {
    "api_key": API_KEY,
    "field": "school",
    "text": "stanf",
    "size": 10,
    "pretty": True
}

json_response = requests.get(pdl_url,  params=params).json()
print(json_response)

The response for this request will be structured as:

{
  "data": [
    {
      "name": "stanford university",
      "count": 434677,
      "meta": {
        "website": "stanford.edu",
        "location_name": "stanford, california, united states",
        "id": "1W561qgHMjuYX4YWF1sIrQ_0"
      }
    },
    ...
  ],
    "fields": [
    "education.school.name"
  ],
  "status": 200
}

and we can see the full response here:

Full Response (click to toggle):
{
  "data": [
    {
      "name": "stanford university",
      "count": 434677,
      "meta": {
        "website": "stanford.edu",
        "location_name": "stanford, california, united states",
        "id": "1W561qgHMjuYX4YWF1sIrQ_0"
      }
    },
    {
      "name": "stanford university graduate school of business",
      "count": 44080,
      "meta": {
        "website": "gsb.stanford.edu",
        "location_name": "stanford, california, united states",
        "id": "HSBJxyTEjoUZ0HB0QMYNhg_0"
      }
    },
    {
      "name": "stanford law school",
      "count": 10425,
      "meta": {
        "website": "law.stanford.edu",
        "location_name": "stanford, california, united states",
        "id": "7oB8xssxBNsgj55NVNgX8w_0"
      }
    },
    {
      "name": "stanford university school of medicine",
      "count": 9788,
      "meta": {
        "website": "med.stanford.edu",
        "location_name": "palo alto, california, united states",
        "id": "Bx27PJ2pdlcuFt305W0--g_0"
      }
    },
    {
      "name": "stanford continuing studies",
      "count": 5248,
      "meta": {
        "website": "continuingstudies.stanford.edu",
        "location_name": "stanford, california, united states",
        "id": "Ij6aIDqpy2vcAEvsy84d7A_0"
      }
    },
    {
      "name": "stanford university graduate school of education",
      "count": 1943,
      "meta": {
        "website": "ed.stanford.edu",
        "location_name": "stanford, california, united states",
        "id": "7memxNXEkFjKfVFzugGARw_0"
      }
    },
    {
      "name": "stanford university school of engineering",
      "count": 1557,
      "meta": {
        "website": "engineering.stanford.edu",
        "location_name": "stanford, california, united states",
        "id": "EmDZlGWe-NO97qziNWDZlQ_0"
      }
    },
    {
      "name": "stanford graduate school of business executive education",
      "count": 1197,
      "meta": {
        "website": null,
        "location_name": "united states",
        "id": "gAhTlHvSnTzbG9v8GIBzHg_0"
      }
    },
    {
      "name": "stanfield secondary school",
      "count": 326,
      "meta": {
        "website": "stanfield.k12.or.us",
        "location_name": "stanfield, oregon, united states",
        "id": "eeSTd4RdDZx8blKM9CsHdw_0"
      }
    },
    {
      "name": "stanford online high school",
      "count": 325,
      "meta": {
        "website": "ohs.stanford.edu",
        "location_name": "stanford, california, united states",
        "id": "dZ7tnAE3--3kiSjm6xauSQ_0"
      }
    }
  ],
  "fields": [
    "education.school.name"
  ],
  "status": 200
}

Did this page help you?