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

Overview

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

Client Demo gif

Requirements

Release Notes and Previous Versions

TerminusDB Client v10.0 works with TerminusDB v10.0 and TerminusX. Please check RELEASE_NOTES.md to find out what has changed.

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 or the import and export csv function in Scaffolding CLI tool:

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

Python client

Connect to a server

Connect to local host

from terminusdb_client import WOQLClient

client = WOQLClient("http://127.0.0.1:6363/")
client.connect()

Connect to TerminusX

check documentation for TerminusX about how to add the API token to the environment variable

from terminusdb_client import WOQLClient

team="MyTeam"
client = WOQLClient(f"https://dashboard.terminusdb.com/{team}/")
client.connect(team="MyTeam", use_token=True)

Create a database

client.create_database("MyDatabase")

Create a schema

from terminusdb_client.woqlschema import WOQLSchema, DocumentTemplate, RandomKey

my_schema = WOQLSchema()

class Pet(DocumentTemplate):
    _schema = my_schema
    name: str
    species: str
    age: int
    weight: float

my_schema.commit(client)

Create and insert doucments

my_dog = Pet(name="Honda", species="Huskey", age=3, weight=21.1)
my_cat = Pet(name="Tiger", species="Bengal cat", age=5, weight=4.5)
client.insert_document([my_dog, my_cat])

Get back all documents

print(list(client.get_all_documents()))
[{'@id': 'Pet/b5edacf854e34fe79c228a91e2af45fb', '@type': 'Pet', 'age': 5, 'name': 'Tiger', 'species': 'Bengal cat', 'weight': 4.5}, {'@id': 'Pet/cdbe3f6d49394b38b952ae315309256d', '@type': 'Pet', 'age': 3, 'name': 'Honda', 'species': 'Huskey', 'weight': 21.1}]

Get a specific document

print(list(client.query_document({"@type":"Pet", "age":5})))
[{'@id': 'Pet/145eb73966d14a1394f7cd5576d7d0b8', '@type': 'Pet', 'age': 5, 'name': 'Tiger', 'species': 'Bengal cat', 'weight': 4.5}]

Delete a database

client.delete_database("MyDatabase")

Scaffolding CLI tool

Scaffolding Demo gif

Start a project in the directory

$terminusdb startproject
Please enter a project name (this will also be the database name): mydb
Please enter a endpoint location (press enter to use localhost default) [http://127.0.0.1:6363/]:
config.json and schema.py created, please customize them to start your project.

Import a CSV named grades.csv

$terminusdb importcsv grades.csv --na=error
0it [00:00, ?it/s]
Schema object Grades created with grades.csv inserted into database.
schema.py is updated with mydb schema.
1it [00:00,  1.00it/s]
Records in grades.csv inserted as type Grades into database with Lexical ids.

Get documents with query

terminusdb alldocs --type Grades -q grade="B-"
[{'@id': 'Grades/Android_Electric_087-65-4321_42.0_23.0_36.0_45.0_47.0_B-', '@type': 'Grades', 'final': 47.0, 'first_name': 'Electric', 'grade': 'B-', 'last_name': 'Android', 'ssn': '087-65-4321', 'test1': 42.0, 'test2': 23.0, 'test3': 36.0, 'test4': 45.0}, {'@id': 'Grades/Elephant_Ima_456-71-9012_45.0_1.0_78.0_88.0_77.0_B-', '@type': 'Grades', 'final': 77.0, 'first_name': 'Ima', 'grade': 'B-', 'last_name': 'Elephant', 'ssn': '456-71-9012', 'test1': 45.0, 'test2': 1.0, 'test3': 78.0, 'test4': 88.0}, {'@id': 'Grades/Franklin_Benny_234-56-2890_50.0_1.0_90.0_80.0_90.0_B-', '@type': 'Grades', 'final': 90.0, 'first_name': 'Benny', 'grade': 'B-', 'last_name': 'Franklin', 'ssn': '234-56-2890', 'test1': 50.0, 'test2': 1.0, 'test3': 90.0, 'test4': 80.0}]

Delete the database

$terminusdb deletedb
Do you want to delete 'mydb'? WARNING: This opertation is non-reversible. [y/N]: y
mydb deleted.

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

Owner
TerminusDB
Build Data Products
TerminusDB
Anomaly detection on SQL data warehouses and databases

With CueObserve, you can run anomaly detection on data in your SQL data warehouses and databases. Getting Started Install via Docker docker run -p 300

Cuebook 171 Dec 18, 2022
sync/async MongoDB ODM, yes.

μMongo: sync/async ODM μMongo is a Python MongoDB ODM. It inception comes from two needs: the lack of async ODM and the difficulty to do document (un)

Scille 428 Dec 29, 2022
MySQL database connector for Python (with Python 3 support)

mysqlclient This project is a fork of MySQLdb1. This project adds Python 3 support and fixed many bugs. PyPI: https://pypi.org/project/mysqlclient/ Gi

PyMySQL 2.2k Dec 25, 2022
MariaDB connector using python and flask

MariaDB connector using python and flask This should work with flask and to be deployed on docker. Setting up stuff 1. Docker build and run docker bui

Bayangmbe Mounmo 1 Jan 11, 2022
A collection of awesome sqlite tools, scripts, books, etc

Awesome Series @ Planet Open Data World (Countries, Cities, Codes, ...) • Football (Clubs, Players, Stadiums, ...) • SQLite (Tools, Books, Schemas, ..

Planet Open Data 205 Dec 16, 2022
Use SQL query in a jupyter notebook!

SQL-query Use SQL query in a jupyter notebook! The table I used can be found on UN Data. Or you can just click the link and download the file undata_s

Chuqin 2 Oct 05, 2022
A Relational Database Management System for a miniature version of Twitter written in MySQL with CLI in python.

Mini-Twitter-Database This was done as a database design course project at Amirkabir university of technology. This is a relational database managemen

Ali 12 Nov 23, 2022
Python Wrapper For sqlite3 and aiosqlite

Python Wrapper For sqlite3 and aiosqlite

6 May 30, 2022
Async ORM based on PyPika

PyPika-ORM - ORM for PyPika SQL Query Builder The package gives you ORM for PyPika with asycio support for a range of databases (SQLite, PostgreSQL, M

Kirill Klenov 7 Jun 04, 2022
High level Python client for Elasticsearch

Elasticsearch DSL Elasticsearch DSL is a high-level library whose aim is to help with writing and running queries against Elasticsearch. It is built o

elastic 3.6k Jan 03, 2023
Making it easy to query APIs via SQL

Shillelagh Shillelagh (ʃɪˈleɪlɪ) is an implementation of the Python DB API 2.0 based on SQLite (using the APSW library): from shillelagh.backends.apsw

Beto Dealmeida 207 Dec 30, 2022
SAP HANA Connector in pure Python

SAP HANA Database Client for Python Important Notice This public repository is read-only and no longer maintained. The active maintained alternative i

SAP Archive 299 Nov 20, 2022
SQL for Humans™

Records: SQL for Humans™ Records is a very simple, but powerful, library for making raw SQL queries to most relational databases. Just write SQL. No b

Ken Reitz 6.9k Jan 03, 2023
Python client for InfluxDB

InfluxDB-Python InfluxDB-Python is a client for interacting with InfluxDB. Development of this library is maintained by: Github ID URL @aviau (https:/

InfluxData 1.6k Dec 24, 2022
A wrapper for SQLite and MySQL, Most of the queries wrapped into commands for ease.

Before you proceed, make sure you know Some real SQL, before looking at the code, otherwise you probably won't understand anything. Installation pip i

Refined 4 Jul 30, 2022
Create a database, insert data and easily select it with Sqlite

sqliteBasics create a database, insert data and easily select it with Sqlite Watch on YouTube a step by step tutorial explaining this code: https://yo

Mariya 27 Dec 27, 2022
Example Python codes that works with MySQL and Excel files (.xlsx)

Python x MySQL x Excel by Zinglecode Example Python codes that do the processes between MySQL database and Excel spreadsheet files. YouTube videos MyS

Potchara Puttawanchai 1 Feb 07, 2022
Redis Python Client - The Python interface to the Redis key-value store.

redis-py The Python interface to the Redis key-value store. Installation | Contributing | Getting Started | Connecting To Redis Installation redis-py

Redis 11k Jan 08, 2023
Databank is an easy-to-use Python library for making raw SQL queries in a multi-threaded environment.

Databank Databank is an easy-to-use Python library for making raw SQL queries in a multi-threaded environment. No ORM, no frills. Thread-safe. Only ra

snapADDY GmbH 4 Apr 04, 2022
The JavaScript Database, for Node.js, nw.js, electron and the browser

The JavaScript Database Embedded persistent or in memory database for Node.js, nw.js, Electron and browsers, 100% JavaScript, no binary dependency. AP

Louis Chatriot 13.2k Jan 02, 2023