Python 3 min read

Google Knowledge Graph API in Python: Legacy Parsing and Migration

For an existing Google Knowledge Graph Search API integration, parse the legacy JSON-LD response explicitly.

(Updated: ) • 426 words

For an existing Google Knowledge Graph Search API integration, parse the legacy JSON-LD response explicitly. For a new project, assess Google’s current Enterprise Knowledge Graph guidance first. The legacy endpoint and the Cloud migration are different integration contracts; changing the URL alone does not migrate the client.

Identify the API before copying a Python example

Google’s legacy API overview directs new users toward Enterprise Knowledge Graph and cautions against a production-critical dependency on the legacy service. The legacy response contains individual matching entities; it is not an export of an interconnected knowledge graph.

The legacy request uses an API key. A Cloud migration has different authentication, identifiers and response details. Google’s migration documentation removes resultScore from the new contract. Keep the two parsers and credential configurations distinct.

Legacy integration Migration review
API-key authorization Review Cloud credentials and IAM separately
itemListElement entries Verify the selected Cloud edition and response contract
Legacy entity identifier Map the Cloud identifier and retained identifiers
resultScore Do not require a score removed from the Cloud response

Parse an owned legacy-response fixture

def legacy_entities(payload):
    rows = payload.get('itemListElement', [])
    if not isinstance(rows, list):
        raise ValueError('Expected itemListElement array')
    entities = []
    for item in rows:
        if not isinstance(item, dict) or not isinstance(item.get('result'), dict):
            continue
        result = item['result']
        entities.append({'id': result.get('@id'), 'name': result.get('name'),
                         'types': result.get('@type', []),
                         'score': item.get('resultScore')})
    return entities

fixture = {"itemListElement": [{"result": {"@id": "kg:/m/example",
    "name": "Fixture Entity", "@type": ["Organization"]}, "resultScore": 7.0}]}
assert legacy_entities(fixture)[0]["name"] == "Fixture Entity"
assert legacy_entities({}) == []

This example was tested with synthetic valid, empty and missing-field cases. The score is a legacy matching field, not a calibrated probability, an SEO ranking or a promise of a Knowledge Panel.

Make the migration decision explicit

Entity lookup is separate from a Google SERP request. Use the Google Search API tutorial when the task is to retrieve web result positions and URLs.

  • Inventory callers that depend on the old identifier, resultScore or API-key flow.
  • Read the current Cloud edition, authentication and response documentation before implementing a replacement.
  • Retain fixtures for empty results and missing optional fields.
  • Check actual project quota and service terms; do not rely on an unverified quota copied from a blog.

Reference documentation: developers.google.com — /knowledge-graph; developers.google.com — /knowledge-graph/reference/rest/v1; docs.cloud.google.com — /enterprise-knowledge-graph/docs/migrate.

Tags:

Python Google API Knowledge Graph Entity Extraction Semantic Web AI Developers
SearchCans Team

SearchCans Team

SERP API & Reader API Experts

The SearchCans engineering team builds high-performance search APIs serving developers worldwide. We share practical tutorials, best practices, and insights on SERP data, web scraping, RAG pipelines, and AI integration.

Ready to build with SearchCans?

Test SERP API and Reader API with 100 free credits. No credit card required.