Python Driver API reference
Query section
Query section consists of the following methods:
TypeDB Driver methods
Instantiating a TypeDB Core client
Description
In order to communicate with TypeDB Core databases via sessions and transactions, we first need to instantiate a TypeDB Core client. The created object connects our application with the running TypeDB server.
Instantiating a TypeDB cluster client
Description
In order to communicate with TypeDB cluster databases via sessions and transactions, we first need to instantiate a TypeDB cluster client. The created object connects our application with the running TypeDB cluster.
Node.js and Python Drivers always have TLS enabled! They can only connect to a server that is set up with TLS. |
When instantiating a TypeDB cluster client, it is sufficient to supply the address of just one server, as the addresses of the other servers will be relayed back to the client. However, to avoid failure in the unlikely event that the single server whose address is provided fails before communicating the addresses of the others, it is best practice to supply addresses of all the servers.
Input parameters
Name | Description | Type | Required | Default Value |
---|---|---|---|---|
addresses |
Addresses (host:port) on which TypeDB cluster nodes are running |
list of String |
True |
|
credential |
User credential and TLS encryption setting |
TypeDBCredential |
True |
|
parallelisation |
The number of threads to use for server communication |
int |
False |
2 |
Client methods
Create a session for a database
Description
Opens a communication tunnel (session) to the given database on the running TypeDB server.
For more information on the methods, available with sessions, see the Session methods section.
Input parameters
Name | Description | Type | Required | Default Value |
---|---|---|---|---|
database |
The name of the database with which the session connects. |
String |
True |
N/A |
type |
The type of session to be created (DATA or SCHEMA) |
SessionType |
True |
N/A |
options |
Options for the session. |
False |
N/A |
Create a database
Retrieve a database
Delete a database
Create a user
Retrieve a user
Delete a user
Session methods
Open a transaction
Description
Opens a transaction to perform read or write queries on the database connected to the session.
Input parameters
Name | Description | Type | Required | Default Value |
---|---|---|---|---|
transactionType |
The type of transaction to be created (READ or WRITE). |
Transaction.Type |
True |
|
options |
Options for the session. |
[ |
False |
N/A |
Transaction methods
Access Concept API methods
Access Concept API - Logic methods
Access Query API methods
Commit a write transaction
QueryManager methods
Execute a TypeQL Match (Get) query
Execute a TypeQL Match Aggregate query
Execute a TypeQL Match Group query
Execute a TypeQL Match Group Aggregate query
Execute a TypeQL Insert query
Execute a TypeQL Delete query
Execute a TypeQL Update query
Execute a TypeQL Explain query
Execute a TypeQL Define query
Options
The transaction query options object TypeDBOptions
can be used to override the default server behaviour
query processing. Use TypeDBOptions.core()
to create a new TypeDB Core options object, or TypeDBOptions.cluster()
for cluster client for TypeDB Enterprise & TypeDB Cloud..
The options are:
-
infer
: whether to enable inference for the provided query (only settable at transaction level and above, and only affects read transactions) (default:False
) -
explain
: whether to enable explanations for the provided query (only affects read transactions) (default:False
) -
parallel
: whether the server should use parallel or single-threaded execution (default:True
) -
prefetch_size
: a guideline number of answers that the server should send before the client issues a fresh request (default:50
) -
trace_inference
: if enabled, outputs reasoning tracing graphs in the logging directory. Should be used withparallel = False
. (default:False
) -
prefetch
: if enabled, the first batch of answers is streamed to the client even without an explicit request for it (default:True
if query type ismatch
, otherwiseFalse
) -
session_idle_timeout_millis
: this timeout allows the server to close sessions if a client terminates or becomes unresponsive (default:30_000
) -
transaction_timeout_millis
: this timeout will automatically kill transactions, preventing memory leaks in unclosed transactions (default:300_000
) -
schema_lock_acquire_timeout_millis
: how long the client should wait if opening a session or transaction is blocked by a schema write lock (default:10_000
)
TypeDBClusterOptions
has an additional option:
-
read_any_replica
: enables reading data from any replica, potentially boosting read throughput (default:False
)
Response section
Response section consists of the following methods:
Answer methods
Retrieve a concept corresponding to a specific variable
Retrieve explainable concepts
Retrieve explainable relation
Retrieve explainable attribute
Retrieve explainable ownership
Description
Retrieves the explainable attribute ownership with the pair of (owner, attribute) variable names.
Concept methods
Get a Remote version of the concept.
ConceptManager methods
Retrieve an EntityType
Create or retrieve an EntityType
Description
Creates a new EntityType if none exists with the given label, otherwise retrieves the existing one.
Retrieve a RelationType
Create or retrieve a RelationType
Description
Creates a new RelationType if none exists with the given label, otherwise retrieves the existing one.
Retrieve an AttributeType
Create or retrieve an AttributeType
Description
Creates a new AttributeType if none exists with the given label, or retrieves the existing one.
Type methods
Type
has all the Concept
methods plus what follows.
Get a Remote version of the type.
Rename label
ThingType methods
ThingType
has all the Type
methods plus what follows.
Get a Remote version of the ThingType.
Add new playable role
Add attribute ownership
Syntax
thing_type.as_remote(tx).set_owns(attribute_type, overridden_type=None, annotations=frozenset());
Input parameters
Name | Description | Type | Required | Default Value |
---|---|---|---|---|
attributeType |
The AttributeType to be owned by the instances of this type. |
[ |
True |
N/A |
overriddenType |
The AttributeType that this attribute ownership overrides, if applicable. |
[ |
False |
None |
annotations |
Adds annotations (KEY or UNIQUE) to the ownership. |
set of |
False |
frozenset() |
Retrieve playable roles
Retrieve attributes
Description
Retrieves attribute types that the instances of this type are allowed to own directly or via inheritance.
Retrieve direct attributes
Remove role
EntityType methods
EntityType
has all the ThingType
methods plus what follows.
Set supertype
RelationType methods
RelationType
has all the ThingType
methods plus what follows.
Retrieve specific role
Description
Retrieve the role that this RelationType relates to, if it exists, with the specified label.
Set new role
Description
Sets the new role that this RelationType relates to. If we are setting an overriding type this way, we have to also pass the overridden type as a second argument.
Remove role
Set supertype
Get a Remote version of the RelationType.
RoleType methods
RoleType
has all the Type
methods plus what follows.
Get a Remote version of the role type.
AttributeType methods
AttributeType
has all the ThingType
methods plus what follows.
Set supertype
Retrieve direct and inherited owners of this Type of Attribute
Description
Retrieve all Things that own an attribute of this type.
Optionally, filtered by annotations.
Retrieve direct owners of this Type of Attribute
Description
Retrieve all Things that directly own an attribute of this type. Optionally, filtered by annotations.
Get a Remote version of the AttributeType.
BooleanAttributeType methods
BooleanAttributeType
has all the AttributeType
methods plus what follows.
Put instance
Puts and returns a new instance of this BooleanAttributeType with the specified value. If an attribute with this value does not yet exist, it will be created.
Get instance
Returns the instance, if it exists, of this BooleanAttributeType with the specified value.
Set supertype
Sets the supplied BooleanAttributeType as the supertype of the current BooleanAttributeType
LongAttributeType methods
LongAttributeType
has all the AttributeType
methods plus what follows.
Put instance
Puts and returns a new instance of this LongAttributeType with the specified value. If an attribute with this value does not yet exist, it will be created.
Get instance
Set Supertype
DoubleAttributeType methods
DoubleAttributeType
has all the AttributeType
methods plus what follows.
Put instance
Puts and returns a new instance of this DoubleAttributeType with the specified value. If an attribute with this value does not yet exist, it will be created.
Get instance
Returns the instance, if it exists, of this DoubleAttributeType with the specified value.
Set Supertype
Sets the supplied DoubleAttributeType as the supertype of the current DoubleAttributeType
StringAttributeType methods
StringAttributeType
has all the AttributeType
methods plus what follows.
Put instance
Puts and returns a new instance of this StringAttributeType with the specified value. If an attribute with this value does not yet exist, it will be created.
Get instance
Returns the instance, if it exists, of this StringAttributeType with the specified value.
Set regex
Set Supertype
Sets the supplied StringAttributeType as the supertype of the current StringAttributeType
DateTimeAttributeType methods
DateTimeAttributeType
has all the AttributeType
methods plus what follows.
Put instance
Puts and returns a new instance of this DateTimeAttributeType with the specified value. If an attribute with this value does not yet exist, it will be created.
Get instance
Returns the instance, if it exists, of this DateTimeAttributeType with the specified value.
Set Supertype
Sets the supplied DateTimeAttributeType as the supertype of the current DateTimeAttributeType
Rule methods
Get a Remote version of the rule.
Rename label
LogicManager
Retrieve a Rule
Data methods
Data
has all the Concept
methods plus what follows.
Get a Remote version of the Thing.
Assign attribute
Unassign attribute
Retrieve attributes
Syntax
thing.as_remote(tx).get_has(attribute_type=None, attribute_types=[], annotations=frozenset())
Description
Retrieves the Attributes that this Thing owns.
Optionally, filtered by one or more AttributeTypes.
Optionally, filtered by annotations.
Input parameters
Name | Description | Type | Required | Default Value |
---|---|---|---|---|
attribute_type |
The AttributeType to filter the attributes by. |
|
False |
|
attribute_types |
The AttributeTypes to filter the attributes by. |
list of |
False |
|
annotations |
Only retrieve attributes with annotations (KEY or UNIQUE). |
set of |
False |
frozenset() |
Retrieve relations
Description
Retrieves all the Relations which this Thing plays a role in, optionally filtered by one or more given roles.
Entity methods
Entity
has all the Data
methods plus what follows.
Relation methods
Relation
has all the Data
methods plus what follows.
Retrieve role players
Description
Retrieves all roleplayers of this this Relation, optionally filtered by given role types.
Add roleplayer
Remove a roleplayer
Description
Removes the association of the given instance that plays the given role in this Relation.
Attribute methods
Attribute
has all the Data
methods plus what follows.