TerminusDB Client Python
Python version of the TerminusDB client - for TerminusDB API and WOQLpy
Requirements
Installation
- TerminusDB Client can be downloaded form PyPI using pip:
python -m pip install terminusdb-client
This only includes the core Python Client (WOQLClient) and WOQLQuery.
If you want to use woqlDataframe:
python -m pip install terminusdb-client[dataframe]
if you are installing form zsh
you have to quote the argument like this:
python -m pip install 'terminusdb-client[dataframe]'
- Install from source:
python -m pip install git+https://github.com/terminusdb/terminusdb-client-python.git
Usage
>>> from terminusdb_client import WOQLQuery, WOQLClient
>>> client = WOQLClient(server_url = "https://127.0.0.1:6363")
>>> client.connect(key="root", account="admin", user="admin")
>>> client.create_database("university", accountid="admin", label="University Graph", description="graph connect
")
{'@type': 'api:DbCreateResponse', 'api:status': 'api:success'}
>>> client.get_database("university", account="admin")
{'label': 'University Graph', 'comment': 'graph connecting students with their courses in the university', 'id':
'university', 'organization': 'admin'}
>>> WOQLQuery().doctype("scm:student").property("scm:name", "xsd:string").execute(client, "student schema created.")
{'@type': 'api:WoqlResponse', 'api:status': 'api:success', 'api:variable_names': [], 'bindings': [{}], 'deletes'
: 0, 'inserts': 5, 'transaction_retry_count': 0}
>>> WOQLQuery().insert("stu001", "scm:student").property("scm:name", "Alice").execute(client, "Adding Alice.")
{'@type': 'api:WoqlResponse', 'api:status': 'api:success', 'api:variable_names': [], 'bindings': [{}], 'deletes': 0, 'inserts': 2, 'transaction_retry_count': 0}
>>> WOQLQuery().insert("stu002", "scm:student").property("scm:name", "Bob").execute(client, "Adding Bob.")
{'@type': 'api:WoqlResponse', 'api:status': 'api:success', 'api:variable_names': [], 'bindings': [{}], 'deletes': 0, 'inserts': 2, 'transaction_retry_count': 0}
>>> client.query(WOQLQuery().star())
{'@type': 'api:WoqlResponse', 'api:status': 'api:success', 'api:variable_names': ['Subject', 'Predicate', 'Object'], 'bindings': [{'Object': 'terminusdb:///schema#student', 'Predicate': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'Subject': 'terminusdb:///data/stu001'}, {'Object': {'@type': 'http://www.w3.org/2001/XMLSchema#string', '@value': 'Alice'}, 'Predicate': 'terminusdb:///schema#name', 'Subject': 'terminusdb:///data/stu001'}, {'Object': 'terminusdb:///schema#student', 'Predicate': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'Subject': 'terminusdb:///data/stu002'}, {'Object': {'@type': 'http://www.w3.org/2001/XMLSchema#string', '@value': 'Bob'}, 'Predicate': 'terminusdb:///schema#name', 'Subject': 'terminusdb:///data/stu002'}], 'deletes': 0, 'inserts': 0, 'transaction_retry_count': 0}
Please check the full Documentation for more information.
Tutorials
There is a list of examples that uses the Python client in our tutorial repo. As a start, we would recommend having a look at create TerminusDB graph with Python client using Jupyter notebook
Testing
-
Clone this repository
git clone https://github.com/terminusdb/terminusdb-client-python.git
-
Install all development dependencies using pipenv
$ make init
- (a) To run test files only
$ pytest terminusdb_client/tests
- (b) To run full test
$ tox -e test
Documentation
Visit our TerminusDB Documentation for the full explanation of using TerminusDB.
Documentation specifically on the latest version of the Python Client can be found here.
Generating Documentation Locally using Sphinx
-
Clone this repository
git clone https://github.com/terminusdb/terminusdb-client-python.git
-
Install all development dependencies
$ make init
- Change directory to docs
$ cd docs/
- Build with Sphinx
$ make html
The output files are under docs/build/html
, open index.html
in your browser to inspect.