The official TerminusDB Python client library for data science and backend applications. Integrate graph database capabilities into your Python workflows.
Connect to a Terminus server at the given URI with an API key.
Parameters
team
str
Name of the team, default to be "admin"
db
optional, str
Name of the database connected
remote_auth
optional, dict
Remote Auth setting
key
optional, str
API key for connecting, default to be "root"
user
optional, str
Name of the user, default to be "admin"
use_token
bool
Use token to connect. If both `jwt_token` and `api_token` is not provided (None), then it will use the ENV variable TERMINUSDB_ACCESS_TOKEN to connect as the API token
jwt_token
optional, str
The Bearer JWT token to connect. Default to be None.
Create a TerminusDB database by posting
a terminus:Database document to the Terminus Server.
Parameters
dbid
str
Unique identifier of the database.
team
str, optional
ID of the Team in which to create the DB (defaults to 'admin')
label
str, optional
Database name.
description
str, optional
Database description.
prefixes
dict, optional
Optional dict containing ``"@base"`` and ``"@schema"`` keys.
@base (str)
IRI to use when ``doc:`` prefixes are expanded. Defaults to ``terminusdb:///data``.
@schema (str)
IRI to use when ``scm:`` prefixes are expanded. Defaults to ``terminusdb:///schema``.
include_schema
bool
If ``True``, a main schema graph will be created, otherwise only a main instance graph will be created.
Graph type, either GraphType.INSTANCE or GraphType.SCHEMA.
skip
int
The starting posiion of the returning results, default to be 0
count
int or None
The maximum number of returned result, if None (default) it will return all of the avalible result.
as_list
bool
If the result returned as list rather than an iterator.
get_data_version
bool
If the version of the document(s) should be obtained. If True, the method return the result and the version as a tuple.
kwargs
Additional boolean flags for retriving. Currently avaliable: "prefixed", "unfold"
Returns
iterable
Stream of dictionaries
get_available_roles()
Get the available roles for the current authenticated user
Returns
dict or None if failed
get_class_frame(class_name)
Get the frame of the class of class_name. Provide information about all the avaliable properties of that class.
Parameters
class_name
str
Name of the class
Returns
dict
Dictionary containing information
get_commit_history(max_history)
Get the whole commit history.
Commit history - Commit id, author of the commit, commit message and the commit time, in the current branch from the current commit, ordered backwards in time, will be returned in a dictionary in the follow format:
```
{ "commit_id":
{ "author": "commit_author",
"message": "commit_message",
"timestamp: <datetime object of the timestamp>"
}
}
```
Parameters
max_history
int, optional
maximum number of commit that would return, counting backwards from your current commit. Default is set to 500. It needs to be nop-negative, if input is 0 it will still give the last commit.
Returns
list
get_database()
Returns metadata (id, organization, label, comment) about the requested database
Parameters
----------
dbid : str
The id of the database
team : str
The organization of the database (default self.team)
Returns
dict
get_databases()
Returns a list of database metadata records for all databases the user has access to
Graph type, either GraphType.INSTANCE or GraphType.SCHEMA.
full_replace
bool
If True then the whole graph will be replaced. WARNING: you should also supply the context object as the first element in the list of documents if using this option.
commit_msg
str
Commit message.
last_data_version
str
Last version before the update, used to check if the document has been changed unknowingly
compress
str or int
If it is an integer, size of the data larger than this (in bytes) will be compress with gzip in the request (assume encoding as UTF-8, 0 = always compress). If it is `never` it will never compress the data.
raw_json
bool
Update as raw json
Returns
list
list of ids of the inseted docuemnts
insert_triples(graph_type, content, commit_msg)
Inserts into the specified graph with the triples encoded in turtle format.
Parameters
graph_type
GraphType
Graph type, either GraphType.INSTANCE or GraphType.SCHEMA.
content
Valid set of triples in Turtle or Trig format.
commit_msg
str
Commit message.
list_databases()
Returns a list of database ids for all databases the user has access to
Returns
list of dicts
log()
Get commit history of a database
Parameters
----------
team : str, optional
The team from which the database is. Defaults to the class property.
db : str, optional
The database. Defaults to the class property.
start : int, optional
Commit index to start from. Defaults to 0.
count : int, optional
Amount of commits to get. Defaults to -1 which gets all.
Returns
list
List of the following commit objects:
```
{
"@id":"InitialCommit/hpl18q42dbnab4vzq8me4bg1xn8p2a0",
"@type":"InitialCommit",
"author":"system",
"identifier":"hpl18q42dbnab4vzq8me4bg1xn8p2a0",
"message":"create initial schema",
"schema":"layer_data:Layer_4234adfe377fa9563a17ad764ac37f5dcb14de13668ea725ef0748248229a91b",
"timestamp":1660919664.9129035
}
```
ok()
Check whether the TerminusDB server is still OK.
Status is not OK when this function returns false
or throws an exception (mostly ConnectTimeout)
Returns
bool
optimize(path)
Optimize the specified path.
Parameters
path
string
Path to optimize, for instance admin/database/_meta for the repo graph.
Example: Python
>>> client = Client("http://127.0.0.1:6363/")>>> client.optimize('admin/database')# optimise database branch (here main)>>> client.optimize('admin/database/_meta')# optimise the repository graph (actually creates a squashed flat layer)>>> client.optimize('admin/database/local/_commits')# commit graph is optimised
patch(before, patch)
Apply the patch object to the before object and return an after object. Note that this change does not commit changes to the graph.
Graph type, either GraphType.INSTANCE or GraphType.SCHEMA.
commit_msg
str
Commit message.
last_data_version
str
Last version before the update, used to check if the document has been changed unknowingly
compress
str or int
If it is an integer, size of the data larger than this (in bytes) will be compress with gzip in the request (assume encoding as UTF-8, 0 = always compress). If it is `never` it will never compress the data.
create
bool
Create the document if it does not yet exist.
raw_json
bool
Update as raw json
reset(commit, soft, use_path)
Reset the current branch HEAD to the specified commit path. If `soft` is not True, it will be a hard reset, meaning reset to that commit in the backend and newer commit will be wipped out. If `soft` is True, the client will only reference to that commit and can be reset to the newest commit when done.
Parameters
commit
string
Commit id or path to the commit (if use_path is True), for instance '234980523ffaf93' or 'admin/database/local/commit/234980523ffaf93'. If not provided, it will reset to the newest commit (useful when need to go back after a soft reset).
soft
bool
Flag indicating if the reset if soft, that is referencing to a previous commit instead of resetting to a previous commit in the backend and wipping newer commits.
use_path
bool
Wheather or not the commit given is an id or path. Default using id and use_path is False.
Updates the specified document(s). Add the document if not existed.
Parameters
document
dict or list of dict
Document(s) to be updated.
graph_type
GraphType
Graph type, either GraphType.INSTANCE or GraphType.SCHEMA.
commit_msg
str
Commit message.
last_data_version
str
Last version before the update, used to check if the document has been changed unknowingly
compress
str or int
If it is an integer, size of the data larger than this (in bytes) will be compress with gzip in the request (assume encoding as UTF-8, 0 = always compress). If it is `never` it will never compress the data.
Creates a logical AND with the argument passed, for WOQLQueries.
Parameters
other
WOQLQuery object
—
Returns
WOQLQuery object
query object that can be chained and/or execute
__and__(other)
Creates a logical AND with the argument passed, for WOQLQueries.
Parameters
other
WOQLQuery object
—
Returns
WOQLQuery object
query object that can be chained and/or execute
__init__(query: dict, graph: str)
defines the internal functions of the woql query object - the language API is defined in WOQLQuery
Parameters
query: dict
json-ld query for initialisation
graph: str
graph that this query is appled to, default to be schema/main
__invert__(other)
Creates a logical Not with the argument passed, for WOQLQueries.
Parameters
other
WOQLQuery object
—
Returns
WOQLQuery object
query object that can be chained and/or execute
__or__(other)
Creates a logical OR with the argument passed, for WOQLQueries.
Parameters
other
WOQLQuery object
—
Returns
WOQLQuery object
query object that can be chained and/or execute
_add_partial(s, p, o, g)
Adds the query based on action given in builder context.
Parameters
s
str
target subject
p
str
target predicate
o
str
target object
g
str
graphIRI
Returns
WOQLQuery object
query object that can be chained and/or execute
_add_sub_query()
Internal library function which adds a subquery and sets the cursor
_arop()
Wraps arithmetic operators in the appropriate json-ld
_asv()
Wraps the elements of an AS variable in the appropriate json-ld
_clean_arithmetic_value()
Transforms whatever is passed in as the object of a triple into the appropriate json-ld form (variable, literal or id)
_clean_data_value()
Transforms whatever is passed in as the object of a triple into the appropriate json-ld form (variable, literal or id)
_clean_graph()
Transforms a graph filter by doing nothing
_clean_node_value()
Transforms whatever is passed in as the object of a triple into the appropriate json-ld form (variable, literal or id)
_clean_object()
Transforms whatever is passed in as the object of a triple into the appropriate json-ld form (variable, literal or id)
_clean_predicate()
Transforms whatever is passed in as the predicate (id or variable) into the appropriate json-ld form
_clean_subject()
Transforms whatever is passed in as the subject into the appropriate json-ld for variable or id
_coerce_to_dict()
Transforms a object representation of a query into a dictionary object if needs be
_compile_path_pattern()
Turns a textual path pattern into a JSON-LD description
_contains_update_check()
Does this query contain an update
_data_list()
takes input that can be either a string (variable name)
or an array - each element of the array is a member of the list
_data_value_list()
DEPRECATED: Dead code - never called anywhere in the codebase.
_expand_variable(varname, always)
Transforms strings that start with v: into variable json-ld structures
Parameters
varname
str
will be transformed if it starts with 'v:'
always
bool
if True it will be transformed no matter it starts with 'v:' or not. Default to be False
_find_last_property(json)
Finds the last woql property that has a subject in it and returns the json for that
used for triplebuilder to chain further calls - when they may be inside ands or ors or subqueries
Parameters
json
dict
dictionary that representing the query in josn-ld
_find_last_subject(json)
Finds the last woql element that has a subject in it and returns the json for that
used for triplebuilder to chain further calls - when they may be inside ands or ors or subqueries
Parameters
json
dict
dictionary that representing the query in josn-ld
_get_object(s: str, p: str)
Function to get the object for the given subject and predicate.
Parameters
s: str
Subject of the object
p: str
Predicate of the object
Returns
WOQLQuery object
query object that can be chained and/or execute
_jlt()
Wraps the passed value in a json-ld literal carriage
_json()
converts back and forward from json
if the argument is present, the current query is set to it,
if the argument is not present, the current json version of this query is returned
_same_entry(a, b)
A function to check the given two objects, which can be of different types (str, dict), are equal or not.
When both the passed objects are dicts, deep comparison is done to check for the equality.
Parameters
a
str or dict
—
b
str or dict
—
Returns
bool
_string_matches_object(s, obj)
A function to check if the given string is present in the passed dict or not.
Parameters
s
str
—
obj
dict
—
Returns
bool
_updated()
Called to inidicate that this query will cause an update to the DB
_value_list()
takes input that can be either a string (variable name)
or an array - each element of the array is a member of the list
Adds quads according to the pattern [subject, predicate, object, graph]
Parameters
subject
str
Subject
predicate
str
Predicate
object_or_literal
str
Object or Literal
graph
str
Graph
Returns
WOQLQuery object
query object that can be chained and/or execute
add_triple(subject, predicate, object_or_literal)
Adds triples according to the the pattern [subject, predicate, object]
Parameters
subject
str
Subject
predicate
str
Predicate
object_or_literal
str
Object or Literal
Returns
WOQLQuery object
query object that can be chained and/or execute
Example: Python
This example adds a triple for a comment predicate and a certain value to the document identified by doc:X:>>> update = WOQLQuery().add_triple("doc:X","comment","my comment")>>> qry = WOQLQuery().when(True, update)>>> client.update(qry.json(),'MyDatabaseId')
added_quad(sub, pre, obj, gra, opt)
Creates a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Object, Graph) added to the current commit.
Parameters
sub
str
Subject
pre
str
Predicate
obj
str
Object
gra
str
Graph
opt
bool
weather or not this quad is optional, default to be False
Returns
WOQLQuery object
query object that can be chained and/or execute
added_triple(sub, pred, obj, opt)
Creates a triple pattern matching rule for the triple [S, P, O] (Subject, Predicate, Object) added to the current commit.
Parameters
sub
str
Subject
pred
str
Predicate
obj
str
Object
opt
bool
weather or not this triple is optional, default to be False
Returns
WOQLQuery object
query object that can be chained and/or execute
all(subj, pred, obj, graph)
Calls the star method and returns the result of the same.
Parameters
subj
str, optional
target subject
pred
str, optional
target predicate
obj
str, optional
target object
graph
str
graphIRI
Returns
WOQLQuery object
query object that can be chained and/or execute
boolean(input_bool)
Transforms the given bool object into the proper json-ld form
Changes the type of va to type and saves the return in vb
Parameters
val
str
original variable
user_type
str
type to be changed
result: str
save the return variable
literal_type: str, optional
literal type of`val`, can be used to treat `val` as a literal rather than an object or variable in the WOQL query.
If literal type is "owl:Thing" or "node", `val` will be treated as object in the graph
Returns
WOQLQuery object
query object that can be chained and/or execute
collect(template, into, query)
Collects all solutions of a sub-query into a list.
Parameters
template
str or list
A variable or list of variables specifying what to collect from each solution
Adds a text comment to a query - can also be used to wrap any part of a query to turn it off
Parameters
comment
str
text comment
Returns
—
-------
—
WOQLQuery object
query object that can be chained and/or execute
concat(concat_list, result)
Concatenates the list of variables into a string and saves the result in v
Parameters
concat_list
list
list of variables to concatenate
result
str
saves the results
Returns
WOQLQuery object
query object that can be chained and/or execute
count(result, query)
Counds the number of solutions in the given query
Parameters
result
A variable or non-negative integer with the count
—
query
The query from which to count the number of results
—
Returns
WOQLQuery object
query object that can be chained and/or executed
date(input_obj)
Transforms the given date object into the proper json-ld form
Parameters
input_obj
str
the given input date object or a date string format YYYY-MM-DD
Returns
dict
date_duration(start, end, duration)
Tri-directional duration arithmetic for dates and dateTimes.
Given any two of start, end, and duration, computes the third.
Uses EOM preservation: last day of month maps to last day of target month.
Accepts xsd:date or xsd:dateTime for start/end, xsd:duration for duration.
Parameters
start
str or dict
the start date or dateTime
end
str or dict
the end date or dateTime
duration
str or dict
the xsd:duration between start and end
Returns
WOQLQuery object
query object that can be chained and/or execute
datetime(input_obj)
Transforms the given datetime object into the proper json-ld form
Parameters
input_obj
str
the given input dateTime object or a datetime string format YYYY-MM-DDThh-mm-ssZ
Returns
dict
day_after(date, next_date)
Computes the calendar day after the given date. Bidirectional.
Parameters
date
str or dict
the input date
next_date
str or dict
the next calendar day
Returns
WOQLQuery object
query object that can be chained and/or execute
day_before(date, previous)
Computes the calendar day before the given date. Bidirectional.
Deletes any triples that match the rule [subject, predicate, object]
Parameters
subject
str
Subject
predicate
str
Predicate
object_or_literal
str
Object or Literal
Returns
WOQLQuery object
query object that can be chained and/or execute
distinct(args)
Ensures that the solutions for the variables [V1...Vn] are distinct
Parameters
args
The variables to make distinct with the final argument being a query.
Returns
WOQLQuery object
query object that can be chained and/or execute
div(args)
Division - integer division - args are divided left to right
Parameters
args
int or float
numbers for division
Returns
WOQLQuery
query object that can be chained and/or execute
divide(args)
Divides numbers N1...Nn by each other left, to right precedence
Parameters
args
int or float
numbers to be divided
Returns
WOQLQuery object
query object that can be chained and/or execute
dot(dictionary, field, value)
Iterates through a list and returns a value for each member
Parameters
dictionary
a WOQL dictionary or variable representing a dictionary
field
str
a string representing the field or key to access the dictionary
value
a WOQL value representing the result
Returns
WOQLQuery object
query object that can be chained and/or execute
eq()
Matches if a is equal to b
Parameters
----------
left : str
object in the graph
right : str
object in the graph
Returns
-------
WOQLQuery object
query object that can be chained and/or execute
eval(arith, res)
Evaluates the Arithmetic Expression Arith and copies the output to variable V
Executes the query using the passed client to connect to a server
Parameters
client: Client object
client that provide connection to the database for the query to execute.
commit_msg: str
optional, commit message for this query. Recommended for query that carrries an update.
file_dict:
File dictionary to be associated with post name => filename, for multipart POST
exp(first, second)
Raises A to the power of B
Parameters
first
int or float
base number
second
int or float
power of
Returns
WOQLQuery object
query object that can be chained and/or execute
file(fpath, opts)
Provides details of a file source in a JSON format that includes a URL property
Parameters
fpath
dict or str
file data source in a JSON format or file path
opts
input options
optional
Returns
WOQLQuery object
query object that can be chained and/or execute
floor(user_input)
The floor function of a real number x denotes the greatest integer less than or equal to x.
Parameters
user_input
int or float
number whose floor needs to be calculated
Returns
WOQLQuery object
query object that can be chained and/or execute
from_dict()
Set a query from a dictionary that represents the query in JSON-LD format.
from_json()
Set a query from a JSON-LD json string
get()
Takes an as structure
graph()
Used to specify that the rest of the query should use the graph g in calls to add_quad, quad, etc
Parameters
----------
g : str
target graph
Returns
-------
WOQLQuery object
query object that can be chained and/or execute
greater(left, right)
Compares the value of v1 against v2 and returns true if v1 is greater than v2
Groups the results of groupquery together by the list of variables group_vars, using the variable template as a grouping and saves the result into variable output.
Parameters
group_vars
list or str or Var object
list of variables to group
template
dict or list or str
template of data to group with free variable(s)
output
str, optional
output variable
groupquery
dict, optional
—
Returns
WOQLQuery object
query object that can be chained and/or execute
gte()
Compares two values using greater-than-or-equal ordering.
Parameters
----------
left : str or number
the greater or equal value
right : str or number
the lesser or equal value
Returns
-------
WOQLQuery object
query object that can be chained and/or execute
idgen(prefix, input_var_list, output_var)
Generates an ID for a node as a function of the passed VariableList with a specific prefix (URL base). If the values of the passed variables are the same, the output will be the same
Parameters
prefix
str
prefix for the id
input_var_list
str or list
variable to generate id for
output_var
str
the variable to hold the id
Returns
WOQLQuery object
query object that can be chained and/or execute
idgen_random(prefix, uri)
Generates a unique ID with cryptographically secure random suffix.
Parameters
prefix
str
A prefix for the IDs to be generated (e.g. "Person/")
uri
str
Variable name or output target for the generated ID
Returns
WOQLQuery object
query object that can be chained and/or executed
immediately(query)
Immediately runs side-effects without backtracking
Parameters
query
WOQLQuery object, optional
—
Returns
WOQLQuery object
query object that can be chained and/or executed
in_range(value, start, end)
Tests whether a value falls within a half-open range [start, end).
Succeeds if start <= value < end.
Relates an xdd:dateTimeInterval to its start endpoint and precise xsd:duration.
Parameters
start
str or dict
inclusive start date or dateTime
duration
str or dict
the xsd:duration between start and end
interval_val
str or dict
the xdd:dateTimeInterval value
Returns
WOQLQuery object
query object that can be chained and/or execute
into(graph_descriptor, query)
Sets the current output graph for writing output to.
Parameters
graph_descriptor
str
output graph
query
WOQLQuery object, optional
—
Returns
WOQLQuery object
query object that can be chained and/or execute
isa(element, of_type)
Matches if element is a member of a certain type, according to the current state of the DB
Parameters
element
str
element to be checked
of_type
str
type to be checked
Returns
bool
iso_week(date, year, week)
Computes the ISO 8601 week-numbering year and week number for a date.
Accepts xsd:date or xsd:dateTime. Date must be ground.
The ISO year may differ from the calendar year at year boundaries.
Parameters
date
str or dict
the input date or dateTime
year
str or int
the ISO week-numbering year
week
str or int
the ISO week number (1-53)
Returns
WOQLQuery object
query object that can be chained and/or execute
join(user_input, glue, output)
Joins a list variable together (input) into a string variable (output) by glueing the strings together with glue
Parameters
user_input
list
a list of variables
glue
str
jioining character(s)
output
str
variable that sotres output
Returns
WOQLQuery object
query object that can be chained and/or execute
length(var_list, var_len)
Length
Calculates the length of a list
Parameters
var_list
list
list of elements
var_len
num
number of eleemnts
Returns
WOQLQuery object
query object that can be chained and/or execute
less(left, right)
Compares the value of v1 against v2 and returns true if v1 is less than v2
Parameters
left
str or number
first variable to compare
right
str or number
second variable to compare
Returns
WOQLQuery object
query object that can be chained and/or execute
lib()
Returns the WOQL library instance for RDFList operations and other library functions.
Matches left string to right string with a distance
Parameters
left
str
first string to compare
right
str
second string to compare
dist
str
Hamming distance between left and right
Returns
—
-------
—
WOQLQuery object
query object that can be chained and/or execute
limit(limit, query)
Specifies that only the first Number of rows will be returned
Parameters
limit
int
number of maximum results returned
query
WOQLQuery object, optional
—
Returns
WOQLQuery object
query object that can be chained and/or execute
list_to_set(input_list, result_set)
Converts a list to a set (removes duplicates and sorts)
Parameters
input_list
str or list
Input list or variable
result_set
str
Variable to store the resulting set
Returns
WOQLQuery object
query object that can be chained and/or execute
load_vocabulary()
Queries the schema graph and loads all the ids found there as vocabulary that can be used without prefixes
ignoring blank node ids
localize(param_spec)
Build a localized scope for variables to prevent leaking local variables to outer scope.
Parameters
param_spec
dict
Object mapping parameter names to values (or None for local vars)
Returns
tuple
(localized_fn, v) where localized_fn wraps queries and v contains unique vars
lower(left, right)
Changes a string to lower-case - input is in u, output in l
Parameters
left
str
input string
right
str
stores output
Returns
WOQLQuery object
query object that can be chained and/or execute
lte()
Compares two values using less-than-or-equal ordering.
Parameters
----------
left : str or number
the lesser or equal value
right : str or number
the greater or equal value
Returns
-------
WOQLQuery object
query object that can be chained and/or execute
member(member, mem_list)
Iterates through a list and returns a value for each member
Parameters
member
str
a WOQL variable representing an element of the list
mem_list
str
a WOQL list variable
Returns
WOQLQuery object
query object that can be chained and/or execute
minus(args)
Adds numbers N1...Nn together
Parameters
args
int or float
numbers to add together
Returns
WOQLQuery object
query object that can be chained and/or execute
month_end_date(year_month, date)
Computes the last day of the month for a given xsd:gYearMonth.
Handles leap years correctly.
Parameters
year_month
str or dict
a gYearMonth value (e.g. 2024-02) or variable
date
str or dict
the resulting xsd:date or variable
Returns
WOQLQuery object
query object that can be chained and/or execute
month_end_dates(date, start, end)
Generator: produces every last-of-month date in [start, end).
Parameters
date
str
variable for the generated last-of-month date
start
str or dict
the inclusive start date
end
str or dict
the exclusive end date
Returns
WOQLQuery object
query object that can be chained and/or execute
month_start_date(year_month, date)
Computes the first day of the month for a given xsd:gYearMonth.
Parameters
year_month
str or dict
a gYearMonth value (e.g. 2024-01) or variable
date
str or dict
the resulting xsd:date or variable
Returns
WOQLQuery object
query object that can be chained and/or execute
month_start_dates(date, start, end)
Generator: produces every first-of-month date in [start, end).
Parameters
date
str
variable for the generated first-of-month date
start
str or dict
the inclusive start date
end
str or dict
the exclusive end date
Returns
WOQLQuery object
query object that can be chained and/or execute
once(query)
Obtains only one result from subquery
Parameters
query
WOQLQuery object, optional
—
Returns
WOQLQuery object
query object that can be chained and/or executed
opt(query)
The Query in the Optional argument is specified as optional
Parameters
query
WOQLQuery object
—
Returns
WOQLQuery object
query object that can be chained and/or execute
order_by(gvarlist, query)
Orders the results by the list of variables including in gvarlist, asc_or_desc is a WOQL.asc or WOQ.desc list of variables
Parameters
gvarlist
list or dict of WOQLQuery().asc or WOQLQuery().desc objects
—
query
WOQLQuery object, optional
—
Returns
WOQLQuery object
query object that can be chained and/or execute
pad(user_input, pad, length, output)
Pads out the string input to be exactly len long by appending the pad character pad to form output
Parameters
user_input
str
input string
pad
str
padding character(s)
length
int
length to pad
output
str
stores output
Returns
WOQLQuery object
query object that can be chained and/or execute
path(subject, pattern, obj, path: str)
Create a path object constructed by the rules specified with pattern.
Parameters
subject
str
a woql subject, the node that the path started
pattern
str
a pattern which specified the edges the path is consisted of.
It uses pattern construction syntax such as:
* '(scm:edge1, scm:edge2)+' for repeated pattern,
* 'scm:edge1|scm:edge2' for 'or' pattern,
* '<scm:edge' for reverse pattern, and
* '(scm:edge1)[n,m] for pattern between n and m times'
obj
str
a woql object, the node that the path ended
path: str
output variable
Returns
WOQLQuery object
query object that can be chained and/or execute
plus(args)
Adds numbers N1...Nn together
Parameters
args
int or float
numbers to add together
Returns
WOQLQuery object
query object that can be chained and/or execute
post(fpath, opts)
Specifies a file to be posted as part of the request for processing.
Parameters
fpath
str or dict
file path/identifier or dict with file details
opts
dict, optional
additional options for file processing
Returns
WOQLQuery object
query object that can be chained and/or execute
put()
Takes an array of variables, an optional array of column names
quad(sub, pre, obj, gra, opt)
Creates a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Object, Graph)
Parameters
sub
str
Subject
pre
str
Predicate
obj
str
Object
gra
str
Graph
opt
bool
weather or not this quad is optional, default to be False
Returns
WOQLQuery object
query object that can be chained and/or execute
quad_next(sub, pred, obj, next_val, graph)
Finds the next object value with an explicit graph selector.
Parameters
sub
str
Subject, has to be a node (URI) or variable
pred
str
Predicate, can be variable (prefix with "v:") or node
obj
str
Object value or variable
next_val
object
Next object value or variable
graph
str
Graph resource identifier (e.g. 'instance' or 'schema')
Returns
WOQLQuery object
query object that can be chained and/or execute
quad_previous(sub, pred, obj, prev_val, graph)
Finds the previous object value with an explicit graph selector.
Parameters
sub
str
Subject, has to be a node (URI) or variable
pred
str
Predicate, can be variable (prefix with "v:") or node
obj
str
Object value or variable
prev_val
object
Previous object value or variable
graph
str
Graph resource identifier (e.g. 'instance' or 'schema')
Returns
WOQLQuery object
query object that can be chained and/or execute
quad_slice(sub, pred, obj, low, high, graph)
Creates a triple pattern matching rule for [S, P, O, G] with a half-open
value range [low, high) on the object and an explicit graph selector.
Parameters
sub
str
Subject, has to be a node (URI) or variable
pred
str
Predicate, can be variable (prefix with "v:") or node
obj
str
Object, can be variable or node or value
low
object
The inclusive lower bound as a typed value
high
object
The exclusive upper bound as a typed value
graph
str
Graph resource identifier (e.g. 'instance' or 'schema')
Returns
WOQLQuery object
query object that can be chained and/or execute
quad_slice_rev(sub, pred, obj, low, high, graph)
Creates a triple pattern matching rule for [S, P, O, G] with a half-open
value range [low, high) on the object in reverse order, with an explicit
graph selector.
Parameters
sub
str
Subject, has to be a node (URI) or variable
pred
str
Predicate, can be variable (prefix with "v:") or node
obj
str
Object, can be variable or node or value
low
object
The inclusive lower bound as a typed value
high
object
The exclusive upper bound as a typed value
graph
str
Graph resource identifier (e.g. 'instance' or 'schema')
Returns
WOQLQuery object
query object that can be chained and/or execute
random_idgen(prefix, uri)
Generates a unique ID with cryptographically secure random suffix (alias for idgen_random).
Parameters
prefix
str
A prefix for the IDs to be generated (e.g. "Person/")
uri
str
Variable name or output target for the generated ID
Returns
WOQLQuery object
query object that can be chained and/or executed
range_max(input_list, result)
Find the maximum value in a list using the standard ordering.
Parameters
input_list
list or str or dict
the list of values to search
result
str or dict
variable or value for the maximum
Returns
WOQLQuery object
query object that can be chained and/or execute
range_min(input_list, result)
Find the minimum value in a list using the standard ordering.
Regular Expression Call
pattern is a regex pattern (.*) using normal regular expression syntax, the only unusual thing is that special characters have to be escaped twice, s is the string to be matched and m is a list of matches:
e.g. WOQLQuery().regexp("(.).*", "hello", ["v:All", "v:Sub"])
Parameters
pattern
str
regex pattern
reg_str
str
string to be matched
reg_list
str or list or dict
store list of matches
Returns
WOQLQuery object
query object that can be chained and/or execute
remote(uri, opts)
Provides details of a remote data source in a JSON format that includes a URL property
Parameters
uri
str
remote data source
opts
input options
optional
Returns
WOQLQuery object
query object that can be chained and/or execute
removed_quad(sub, pre, obj, gra, opt)
Creates a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Object, Graph) added to the current commit.
Parameters
sub
str
Subject
pre
str
Predicate
obj
str
Object
gra
str
Graph
opt
bool
weather or not this quad is optional, default to be False
Returns
WOQLQuery object
query object that can be chained and/or execute
removed_triple(sub, pred, obj, opt)
Creates a triple pattern matching rule for the triple [S, P, O] (Subject, Predicate, Object) added to the current commit.
Parameters
sub
str
Subject
pred
str
Predicate
obj
str
Object
opt
bool
weather or not this triple is optional, default to be False
Returns
WOQLQuery object
query object that can be chained and/or execute
select(args)
Filters the query so that only the variables included in [V1...Vn] are returned in the bindings
Parameters
args
only these variables are returned
Returns
WOQLQuery object
query object that can be chained and/or execute
sequence(value, start, end, step, count)
Generates a sequence of values in the half-open range [start, end).
When value is unbound, produces each value via backtracking.
Parameters
value
str or number
the generated sequence value (or variable)
start
str or number
the inclusive start of the sequence
end
str or number
the exclusive end of the sequence
step
str or number, optional
increment per step
count
str or number, optional
total count (validates if bound, unifies if unbound)
Returns
WOQLQuery object
query object that can be chained and/or execute
set_difference(list_a, list_b, result)
Computes the set difference between two lists (elements in list_a but not in list_b)
Parameters
list_a
str or list
First list or variable
list_b
str or list
Second list or variable
result
str
Variable to store the result
Returns
WOQLQuery object
query object that can be chained and/or execute
set_intersection(list_a, list_b, result)
Computes the set intersection of two lists (elements in both list_a and list_b)
Parameters
list_a
str or list
First list or variable
list_b
str or list
Second list or variable
result
str
Variable to store the result
Returns
WOQLQuery object
query object that can be chained and/or execute
set_member(element, set_list)
Checks if an element is a member of a set (efficient O(log n) lookup)
Parameters
element
any
Element to check
set_list
str or list
Set (list) to check membership in
Returns
WOQLQuery object
query object that can be chained and/or execute
set_union(list_a, list_b, result)
Computes the set union of two lists (all unique elements from both lists)
Parameters
list_a
str or list
First list or variable
list_b
str or list
Second list or variable
result
str
Variable to store the result
Returns
WOQLQuery object
query object that can be chained and/or execute
size(graph: Graph which needs to be set as resource, size: Size which needs to be set)
Sets the given graph and size for cursor.
Parameters
graph: Graph which needs to be set as resource
—
size: Size which needs to be set
—
Returns
WOQLQuery object
query object that can be chained and/or execute
slice(input_list, result, start, end)
Extracts a contiguous subsequence from a list, following slice() semantics.
Parameters
input_list
list or str
A list of values or a variable representing a list
result
str
A variable that stores the sliced result
start
int or str
The start index (0-based, supports negative indices)
end
int or str, optional
The end index (exclusive). If omitted, takes the rest of the list
Splits a variable apart (input) into a list of variables (output) by separating the strings together with separator
Parameters
user_input
str
input string or WOQL variable "v:"
glue
str
character string to separate string into list
output
str
WOQL variable that stores output list
Returns
WOQLQuery object
query object that can be chained and/or execute
star(GraphIRI, Subj, Pred, Obj)
Selects everything as triples in the graph identified by GraphIRI into variables Subj, Pred, Obj - by default they are "v:Subject", "v:Predicate", "v:Object"
Parameters
GraphIRI
str
graphIRI
Subj
str, optional
target subject
Pred
str, optional
target predicate
Obj
str, optional
target object
Returns
WOQLQuery object
query object that can be chained and/or execute
start(start, query)
Specifies that the start of the query returned
Parameters
start
int
index of the frist result got returned
query
WOQLQuery object, optional
—
Returns
WOQLQuery object
query object that can be chained and/or execute
string(input_str)
Transforms the given string into the proper json-ld form
Parameters
input_str
str
the given input string
Returns
dict
sub(parent, child)
Returns true if child is a sub-class of parent, according to the current DB schema
Parameters
parent
str
the parent class to be checked
child
str, optional
the child class to be checked
Returns
bool
sum(user_input, output)
Joins a list variable containing numbers together (input) into a single number
containing the sum.
Parameters
user_input
list
a variable containing a list of numbers
output
str
a variable that stores the output
Returns
WOQLQuery object
query object that can be chained and/or execute
times(args)
Multiplies numbers N1...Nn together
Parameters
args
int or float
numbers to be multiplied
Returns
WOQLQuery object
query object that can be chained and/or execute
to_dict()
Give the dictionary that represents the query in JSON-LD format.
to_json()
Dumps the JSON-LD format of the query in a json string
trim(untrimmed, trimmed)
A trimmed version of untrimmed (with leading and trailing whitespace removed) is copied into trimmed
Parameters
untrimmed
str
original string
trimmed
str
WOQL varible storing the result string
Returns
WOQLQuery object
query object that can be chained and/or execute
triple(sub, pred, obj, opt)
Creates a triple pattern matching rule for the triple [S, P, O] (Subject, Predicate, Object)
Parameters
sub
str
Subject, has to be a node (URI)
pred
str
Predicate, can be variable (prefix with "v:") or node
obj
str
Object, can be variable or node or value
opt
bool
whether or not this triple is optional, default to be False
Returns
WOQLQuery object
query object that can be chained and/or execute
triple_count(graph: Graph which needs to be set as resource, triple_count: Triple count which needs to be set)
Sets the given triple count and size for cursor.
Parameters
graph: Graph which needs to be set as resource
—
triple_count: Triple count which needs to be set
—
Returns
WOQLQuery object
query object that can be chained and/or execute
triple_next(sub, pred, obj, next_val)
Finds the next object value after a reference for a given subject-predicate pair.
When object is bound and next is free, finds the smallest next > object.
When next is bound and object is free, finds the largest object < next.
Parameters
sub
str
Subject, has to be a node (URI) or variable
pred
str
Predicate, can be variable (prefix with "v:") or node
obj
str
Object value or variable
next_val
object
Next object value or variable
Returns
WOQLQuery object
query object that can be chained and/or execute
triple_previous(sub, pred, obj, prev_val)
Finds the previous object value before a reference for a given subject-predicate pair.
When object is bound and previous is free, finds the largest previous < object.
When previous is bound and object is free, finds the smallest object > previous.
Parameters
sub
str
Subject, has to be a node (URI) or variable
pred
str
Predicate, can be variable (prefix with "v:") or node
obj
str
Object value or variable
prev_val
object
Previous object value or variable
Returns
WOQLQuery object
query object that can be chained and/or execute
triple_slice(sub, pred, obj, low, high)
Creates a triple pattern matching rule for [S, P, O] with a half-open
value range [low, high) on the object. Returns triples whose typed object
value falls within the specified range.
Parameters
sub
str
Subject, has to be a node (URI) or variable
pred
str
Predicate, can be variable (prefix with "v:") or node
obj
str
Object, can be variable or node or value
low
object
The inclusive lower bound as a typed value
high
object
The exclusive upper bound as a typed value
Returns
WOQLQuery object
query object that can be chained and/or execute
triple_slice_rev(sub, pred, obj, low, high)
Creates a triple pattern matching rule for [S, P, O] with a half-open
value range [low, high) on the object, returning results in reverse
(descending) object order. Same semantics as triple_slice but iterates
from highest to lowest value.
Parameters
sub
str
Subject, has to be a node (URI) or variable
pred
str
Predicate, can be variable (prefix with "v:") or node
obj
str
Object, can be variable or node or value
low
object
The inclusive lower bound as a typed value
high
object
The exclusive upper bound as a typed value
Returns
WOQLQuery object
query object that can be chained and/or execute
true()
Sets true for cursor type.
Returns
WOQLQuery object
query object that can be chained and/or execute
type_of(value, vtype)
Sets the given value and type for cursor.
Parameters
value
str
Value which needs to be set
vtype
type
Type which needs to be set
Returns
WOQLQuery object
query object that can be chained and/or execute
unique(prefix, key_list, uri)
Generates an ID for a node as a function of the passed VariableList with a specific prefix (URL base)(A.K.A Hashing) If the values of the passed variables are the same, the output will be the same