Skip to main content

Python client for Terminus DB

Project description

TerminusDB Client Python

Discord online Discourse topics Follow on Twitter

Development status ⚙️

Build Status Documentation Status codecov last commit number of contributors

Python Package status 📦

PyPI version shields.io PyPI pyversions GitHub license PyPI download month

Python version of the TerminusDB client - for TerminusDB API and WOQLpy

Demo gif

Requirements

Release Notes and Previous Versions

Please check RELEASE_NOTES.md to find out what has changed.

These previous version(s) works with these version(s) of TerminusDB:

  • 0.1.5 - works with TerminusDB server / console v2.0.4
  • 0.2.2 - works with TerminusDB server / console v2.0.5
  • 0.3.1 - works with TerminusDB server / console v3.0.0 to console v3.0.6
  • 0.4.0 - works with TerminusDB server / console v3.0.7
  • 0.5.0 - works with TerminusDB server / console v4.0.0
  • 0.6.1 - works with TerminusDB server / console v4.2.0

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

  1. Clone this repository git clone https://github.com/terminusdb/terminusdb-client-python.git

  2. Install all development dependencies using pipenv

$ make init
  1. (a) To run test files only
$ pytest terminusdb_client/tests
  1. (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

  1. Clone this repository git clone https://github.com/terminusdb/terminusdb-client-python.git

  2. Install all development dependencies

$ make init
  1. Change directory to docs
$ cd docs/
  1. Build with Sphinx
$ make html

The output files are under docs/build/html, open index.html in your browser to inspect.

Report Issues

If you encounter any issues, please report them with your os and environment setup, the version that you are using and a simple reproducible case.

If you have other questions, you can ask in our community forum or Discord server.

Community

Come visit us on our discord server or our forum. We are also on twitter

Contribute

It will be nice, if you open an issue first so that we can know what is going on, then, fork this repo and push in your ideas. Do not forget to add some test(s) of what value you adding.

Please check CONTRIBUTING.md for more information.

Licence

Apache License (Version 2.0)

Copyright (c) 2019

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

terminusdb-client-1.1.0.tar.gz (81.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page