PyAnzo is a library for interacting with Anzo
Project description
PyAnzo
*******************************************************************************
* Copyright (c) 2019 - 2022 Cambridge Semantics Incorporated.
* All rights reserved.
*
* Contributors:
* Cambridge Semantics Incorporated
*******************************************************************************
PyAnzo is a python library for interacting with an Anzo server. PyAnzo faciliates quick iteration and building functionality outside of Anzo as quickly as possible.
The design of this library is centered around an AnzoClient class, with which users can invoke actions on an Anzo server and retrieve information.
For more information, see the documentation.
Note: Developers should also refer to CONTRIBUTING.md.
Small Examples
Query a Graphmart
from pyanzo import AnzoClient
# Instantiate the anzo client
anzo_client = AnzoClient(server="10.100.0.26", port="443", username="user", password="password")
query = "SELECT * WHERE { ?s ?p ?o } LIMIT 10",
graphmart = "urn://graphmart_uri"
query_result = anzo_client.query_graphmart(graphmart, query_string=query)
interesting_rows = [r for r in query_result.as_table_results().as_list() if "interesting" in r]
print(interesting_rows)
Query the Anzo Journal
from pyanzo import AnzoClient
anzo_client = AnzoClient(server="10.100.0.26", port="443", username="user", password="password")
jrnl_query = """
PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT ?s WHERE {
?s dc:title 'Graphmart'
}
LIMIT 10
"""
jrnl_query_result = anzo_client.query_journal(jrnl_query)
print(f"These instances are titled 'Graphmart': {jrnl_query_result.as_table_results().as_list()}")
Query a Linked Dataset
from pyanzo import AnzoClient
anzo_client = AnzoClient(server="10.100.0.26", port="443", username="user", password="password")
query = "SELECT * WHERE { ?s ?p ?o } LIMIT 10"
lds_uri = "http://cambridgesemantics.com/LinkedDataset/1234"
lds_query_result = anzo_client.query_lds(lds, query_string=query)
print(lds_query_result.as_table_results())
Setup
# cd to root of repo
# Install dependencies
pip install -U -r requirements.txt
# Install PyAnzo
pip install -U -e .
# Uninstall
pip uninstall pyanzo
Test one of the examples:
cd examples
python3 query_results_to_pandas.py
Security
By default, PyAnzo uses HTTPS. This means that the anzo client needs to be configured with the HTTPS port, which is typically 443 or 8443 (as opposed to 80 or 8080).
Further, Because Anzo is initially configured with self-signed certs, verification of the host is turned off. As a result, you'll see a warning printed to the screen:
/Users/anzo/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
This warning is expected and can be suppressed by adding this to your code:
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
History
Version 2.0.0
Released November 10, 2020
- Support the anzoclient get endpoint to get the contents of a named graph with
AnzoClient.get
- Support CONSTRUCT queries where the GRAPH is not specified
- Add the option to indicate named graphs and data layers to target in AnzoClient.query_journal and AnzoClient.query_graphmart
- Support using a cookie to authenticate
- Update
AnzoClient.execute_semantic_service
to take a QuadStore as input. It previously look a list of dictionaries in an Anzo-JSON schema. - Support update queries against the Anzo system journal
- Add utilities to make QuadStore easier to use
Version 1.0.0
Released September 28, 2020
- Support the anzoclient call endpoint to execute a semantic service with
AnzoClient.execute_semantic_service
- Support querying a graphmart
- Support querying the system journal
- Support querying a linked dataset
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.