PyAnzo

3.3.12 · active · verified Thu Apr 16

PyAnzo is a Python library for programmatic interaction with Anzo, a knowledge graph platform developed by Cambridge Semantics. Anzo enables the ingestion, transformation, storage, exploration, and analysis of diverse data types using open W3C standards such as Web Ontology Language (OWL), Resource Description Framework (RDF), and SPARQL. The library is currently at version 3.3.12 and receives regular, primarily patch-level, updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a connection to an Anzo server using `AnzoClient` and execute a simple SPARQL SELECT query against a specified graphmart. Ensure you set the `ANZO_HOST`, `ANZO_PORT`, `ANZO_USER`, `ANZO_PASS`, and `ANZO_GRAPH MART_URI` environment variables for a successful connection.

import os
from pyanzo import AnzoClient

ANZO_HOST = os.environ.get('ANZO_HOST', 'your_anzo_server.com')
ANZO_PORT = int(os.environ.get('ANZO_PORT', '443'))
ANZO_USER = os.environ.get('ANZO_USER', 'your_username')
ANZO_PASS = os.environ.get('ANZO_PASS', 'your_password')
ANZO_GRAPH MART_URI = os.environ.get('ANZO_GRAPH MART_URI', 'http://cambridgesemantics.com/anzo/graphmart/example')

# Basic SPARQL query example
SPARQL_QUERY = """
SELECT ?s ?p ?o WHERE {
  ?s ?p ?o .
}
LIMIT 10
"""

try:
    client = AnzoClient(ANZO_HOST, ANZO_USER, ANZO_PASS, anzo_port=ANZO_PORT)
    print(f"Successfully connected to Anzo at {ANZO_HOST}:{ANZO_PORT}")

    print(f"Querying graphmart: {ANZO_GRAPH MART_URI}")
    results = client.query_graphmart_SELECT(ANZO_GRAPH MART_URI, SPARQL_QUERY)

    print("Query Results:")
    for row in results:
        print(row)

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →