Officially out now: The TypeDB 3.0 Roadmap >>

Python driver API reference

Connection

TypeDB

cloud_driver

static cloud_driver(addresses: Mapping[str, str] | Iterable[str] | str, credential: TypeDBCredential) -> TypeDBDriver

Creates a connection to TypeDB Cloud, authenticating with the provided credentials.

Input parameters
Name Description Type Default Value

addresses

Mapping[str, str] | Iterable[str] | str

credential

TypeDBCredential

Returns

TypeDBDriver

core_driver

static core_driver(address: str) -> TypeDBDriver

Creates a connection to TypeDB.

Input parameters
Name Description Type Default Value

address

Address of the TypeDB server.

str

Returns

TypeDBDriver

TypeDBDriver

Properties
Name Type Description

databases

DatabaseManager

The DatabaseManager for this connection, providing access to database management methods.

users

UserManager

The UserManager instance for this connection, providing access to user management methods. Only for TypeDB Cloud.

close

close() -> None

Closes the driver. Before instantiating a new driver, the driver that’s currently open should first be closed.

Returns

None

Code examples
driver.close()

is_open

is_open() -> bool

Checks whether this connection is presently open.

Returns

bool

Code examples
driver.is_open()

session

session(database_name: str, session_type: SessionType, options: TypeDBOptions | None = None) -> TypeDBSession

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 TypeDBSession section.

Input parameters
Name Description Type Default Value

database_name

The name of the database with which the session connects

str

session_type

The type of session to be created (DATA or SCHEMA)

SessionType

options

TypeDBOptions for the session

TypeDBOptions | None

None

Returns

TypeDBSession

Code examples
driver.session(database, session_type, options)

user

user() -> User

Returns the logged-in user for the connection. Only for TypeDB Cloud.

Returns

User

Code examples
driver.user()

TypeDBCredential

User credentials and TLS encryption settings for connecting to TypeDB Cloud. Arguments: 1) username: The name of the user to connect as. 2) password: The password for the user. 3) tls_root_ca_path: Path to the CA certificate to use for authenticating server certificates. 4) tls_enabled: Specify whether the connection to TypeDB Cloud must be done over TLS.

Examples
# Creates a credential using the specified username and password.
credential = TypeDBCredential(username, password)

# Creates a credential as above, but with TLS and the specified CA to authenticate server certificates.
credential = TypeDBCredential(username, password, tls_enabled=True, tls_root_ca_path="path/to/ca-certificate.pem")

DatabaseManager

Provides access to all database management methods.

all

all() -> List[Database]

Retrieves all databases present on the TypeDB server

Returns

List[Database]

Code examples
driver.databases.all()

contains

contains(name: str) -> bool

Checks if a database with the given name exists

Input parameters
Name Description Type Default Value

name

The database name to be checked

str

Returns

bool

Code examples
driver.databases.contains(name)

create

create(name: str) -> None

Create a database with the given name

Input parameters
Name Description Type Default Value

name

The name of the database to be created

str

Returns

None

Code examples
driver.databases.create(name)

get

get(name: str) -> Database

Retrieve the database with the given name.

Input parameters
Name Description Type Default Value

name

The name of the database to retrieve

str

Returns

Database

Code examples
driver.databases.get(name)

Database

Properties
Name Type Description

name

str

The database name as a string.

delete

delete() -> None

Deletes this database.

Returns

None

Code examples
database.delete()

preferred_replica

preferred_replica() -> Replica | None

Returns the preferred replica for this database. Operations which can be run on any replica will prefer to use this replica. Only works in TypeDB Cloud

Returns

Replica | None

Code examples
database.preferred_replica()

primary_replica

primary_replica() -> Replica | None

Returns the primary replica for this database. Only works in TypeDB Cloud

Returns

Replica | None

Code examples
database.primary_replica()

replicas

replicas() -> Set[Replica]

Set of Replica instances for this database. Only works in TypeDB Cloud

Returns

Set[Replica]

Code examples
database.replicas()

rule_schema

rule_schema() -> str

Returns the rules in the schema as a valid TypeQL define query string.

Returns

str

Code examples
database.rule_schema()

schema

schema() -> str

Returns a full schema text as a valid TypeQL define query string.

Returns

str

Code examples
database.schema()

type_schema

type_schema() -> str

Returns the types in the schema as a valid TypeQL define query string.

Returns

str

Code examples
database.type_schema()

Replica

The metadata and state of an individual raft replica of a database.

database

database() -> Database

Retrieves the database for which this is a replica

Returns

Database

is_preferred

is_preferred() -> bool

Checks whether this is the preferred replica of the raft cluster. If true, Operations which can be run on any replica will prefer to use this replica.

Returns

bool

is_primary

is_primary() -> bool

Checks whether this is the primary replica of the raft cluster.

Returns

bool

server

server() -> str

The server hosting this replica

Returns

str

term

term() -> int

The raft protocol ‘term’ of this replica.

Returns

int

UserManager

Provides access to all user management methods.

all

all() -> List[User]

Retrieves all users which exist on the TypeDB server.

Returns

List[User]

Code examples
driver.users.all()

contains

contains(username: str) -> bool

Checks if a user with the given name exists.

Input parameters
Name Description Type Default Value

username

The user name to be checked

str

Returns

bool

Code examples
driver.users.contains(username)

create

create(username: str, password: str) -> None

Create a user with the given name and password.

Input parameters
Name Description Type Default Value

username

The name of the user to be created

str

password

The password of the user to be created

str

Returns

None

Code examples
driver.users.create(username, password)

delete

delete(username: str) -> None

Deletes a user with the given name.

Input parameters
Name Description Type Default Value

username

The name of the user to be deleted

str

Returns

None

Code examples
driver.users.delete(username)

get

get(username: str) -> User | None

Retrieve a user with the given name.

Input parameters
Name Description Type Default Value

username

The name of the user to retrieve

str

Returns

User | None

Code examples
driver.users.get(username)

password_set

password_set(username: str, password: str) -> None

Sets a new password for a user. This operation can only be performed by administrators.

Input parameters
Name Description Type Default Value

username

The name of the user to set the password of

str

password

The new password

str

Returns

None

Code examples
driver.users.password_set(username, password)

User

TypeDB user information

password_expiry_seconds

password_expiry_seconds() -> int | None

Returns the number of seconds remaining till this user’s current password expires.

Returns

int | None

password_update

password_update(password_old: str, password_new: str) -> None

Updates the password for this user.

Input parameters
Name Description Type Default Value

password_old

The current password of this user

str

password_new

The new password

str

Returns

None

username

username() -> str

Returns the name of this user.

Returns

str

Session

TypeDBSession

Properties
Name Type Description

options

TypeDBOptions

Gets the options for the session

type

SessionType

The current session’s type (SCHEMA or DATA)

close

close() -> None

Closes the session. Before opening a new session, the session currently open should first be closed.

Returns

None

Code examples
session.close()

database_name

database_name() -> str

Returns the name of the database of the session.

Returns

str

Code examples
session.database_name()

is_open

is_open() -> bool

Checks whether this session is open.

Returns

bool

Code examples
session.is_open()

on_close

on_close(function: callable) -> None

Registers a callback function which will be executed when this session is closed.

Input parameters
Name Description Type Default Value

function

The callback function.

callable

Returns

None

Code examples
session.on_close(function)

on_reopen

on_reopen(function: callable) -> None

Registers a callback function which will be executed when this session is reopened. A session may be closed if it times out, or loses the connection to the database. In such situations, the session is reopened automatically when opening a new transaction.

Input parameters
Name Description Type Default Value

function

The callback function.

callable

Returns

None

Code examples
session.on_close(function)

transaction

transaction(transaction_type: TransactionType, options: TypeDBOptions = None) -> TypeDBTransaction

Opens a transaction to perform read or write queries on the database connected to the session.

Input parameters
Name Description Type Default Value

transaction_type

The type of transaction to be created (READ or WRITE)

TransactionType

options

Options for the session

TypeDBOptions

None

Returns

TypeDBTransaction

Code examples
session.transaction(transaction_type, options)

SessionType

This class is used to specify the type of the session.

Examples
driver.session(database, SessionType.SCHEMA)
Enum constants
Name Value

DATA

0

SCHEMA

1

is_data

is_data() -> bool
Returns

bool

is_schema

is_schema() -> bool
Returns

bool

TypeDBOptions

TypeDB session and transaction options. TypeDBOptions object can be used to override the default server behaviour.

Options could be specified either as constructor arguments or using properties assignment.

Examples
transaction_options = TypeDBOptions(infer=True, session_idle_timeout_millis=20000)
transaction_options.explain = True
Properties
Name Type Description

explain

bool | None

If set to True, enables explanations for queries. Only affects read transactions.

infer

bool | None

If set to True, enables inference for queries. Only settable at transaction level and above. Only affects read transactions.

parallel

bool | None

If set to True, the server uses parallel instead of single-threaded execution.

prefetch

bool | None

If set to True, the first batch of answers is streamed to the driver even without an explicit request for it.

prefetch_size

int | None

If set, specifies a guideline number of answers that the server should send before the driver issues a fresh request.

read_any_replica

bool | None

If set to True, enables reading data from any replica, potentially boosting read throughput. Only settable in TypeDB Cloud.

schema_lock_acquire_timeout_millis

int | None

If set, specifies how long the driver should wait if opening a session or transaction is blocked by a schema write lock.

session_idle_timeout_millis

int | None

If set, specifies a timeout that allows the server to close sessions if the driver terminates or becomes unresponsive.

trace_inference

bool | None

If set to True, reasoning tracing graphs are output in the logging directory. Should be used with parallel = False.

transaction_timeout_millis

int | None

If set, specifies a timeout for killing transactions automatically, preventing memory leaks in unclosed transactions.

Transaction

TypeDBTransaction

Properties
Name Type Description

concepts

ConceptManager

The ConceptManager for this transaction, providing access to all Concept API methods.

logic

LogicManager

The LogicManager for this Transaction, providing access to all Concept API - Logic methods.

options

TypeDBOptions

The options for the transaction

query

QueryManager

TheQueryManager for this Transaction, from which any TypeQL query can be executed.

transaction_type

TransactionType

The transaction’s type (READ or WRITE)

close

close() -> None

Closes the transaction.

Returns

None

Code examples
transaction.close()

commit

commit() -> None

Commits the changes made via this transaction to the TypeDB database. Whether or not the transaction is commited successfully, it gets closed after the commit call.

Returns

None

Code examples
transaction.commit()

is_open

is_open() -> bool

Checks whether this transaction is open.

Returns

bool

Code examples
transaction.is_open()

on_close

on_close(function: callable) -> None

Registers a callback function which will be executed when this transaction is closed.

Input parameters
Name Description Type Default Value

function

The callback function.

callable

Returns

None

Code examples
transaction.on_close(function)

rollback

rollback() -> None

Rolls back the uncommitted changes made via this transaction.

Returns

None

Code examples
transaction.rollback()

TransactionType

This class is used to specify the type of transaction.

Examples
session.transaction(TransactionType.READ)
Enum constants
Name Value

READ

0

WRITE

1

is_read

is_read() -> bool
Returns

bool

is_write

is_write() -> bool
Returns

bool

QueryManager

Provides methods for executing TypeQL queries in the transaction.

define

define(query: str, options: TypeDBOptions = None) -> Promise[None]

Performs a TypeQL Define query in the transaction.

Input parameters
Name Description Type Default Value

query

The TypeQL Define query to be executed

str

options

Specify query options

TypeDBOptions

None

Returns

Promise[None]

Code examples
transaction.query.define(query, options).resolve()

delete

delete(query: str, options: TypeDBOptions | None = None) -> Promise[None]

Performs a TypeQL Delete query in the transaction.

Input parameters
Name Description Type Default Value

query

The TypeQL Delete query to be executed

str

options

Specify query options

TypeDBOptions | None

None

Returns

Promise[None]

Code examples
transaction.query.delete(query, options).resolve()

explain

explain(explainable: ConceptMap.Explainable, options: TypeDBOptions | None = None) -> Iterator[Explanation]

Performs a TypeQL Explain query in the transaction.

Input parameters
Name Description Type Default Value

explainable

The Explainable to be explained

ConceptMap.Explainable

options

Specify query options

TypeDBOptions | None

None

Returns

Iterator[Explanation]

Code examples
transaction.query.explain(explainable, options)

fetch

fetch(query: str, options: TypeDBOptions | None = None) -> Iterator[dict]

Performs a TypeQL Fetch query in the transaction.

Input parameters
Name Description Type Default Value

query

The TypeQL Fetch query to be executed

str

options

Specify query options

TypeDBOptions | None

None

Returns

Iterator[dict]

Code examples
transaction.query.fetch(query, options)

get

get(query: str, options: TypeDBOptions | None = None) -> Iterator[ConceptMap]

Performs a TypeQL Match (Get) query in the transaction.

Input parameters
Name Description Type Default Value

query

The TypeQL Match (Get) query to be executed

str

options

Specify query options

TypeDBOptions | None

None

Returns

Iterator[ConceptMap]

Code examples
transaction.query.get(query, options)

get_aggregate

get_aggregate(query: str, options: TypeDBOptions | None = None) -> Promise[Value | None]

Performs a TypeQL Match Aggregate query in the transaction.

Input parameters
Name Description Type Default Value

query

The TypeQL Match Aggregate query to be executed

str

options

Specify query options

TypeDBOptions | None

None

Returns

Promise[Value | None]

Code examples
transaction.query.get_aggregate(query, options).resolve()

get_group

get_group(query: str, options: TypeDBOptions | None = None) -> Iterator[ConceptMapGroup]

Performs a TypeQL Match Group query in the transaction.

Input parameters
Name Description Type Default Value

query

The TypeQL Match Group query to be executed

str

options

Specify query options

TypeDBOptions | None

None

Returns

Iterator[ConceptMapGroup]

Code examples
transaction.query.get_group(query, options)

get_group_aggregate

get_group_aggregate(query: str, options: TypeDBOptions | None = None) -> Iterator[ValueGroup]

Performs a TypeQL Match Group Aggregate query in the transaction.

Input parameters
Name Description Type Default Value

query

The TypeQL Match Group Aggregate query to be executed

str

options

Specify query options

TypeDBOptions | None

None

Returns

Iterator[ValueGroup]

Code examples
transaction.query.get_group_aggregate(query, options)

insert

insert(query: str, options: TypeDBOptions | None = None) -> Iterator[ConceptMap]

Performs a TypeQL Insert query in the transaction.

Input parameters
Name Description Type Default Value

query

The TypeQL Insert query to be executed

str

options

Specify query options

TypeDBOptions | None

None

Returns

Iterator[ConceptMap]

Code examples
transaction.query.insert(query, options)

undefine

undefine(query: str, options: TypeDBOptions = None) -> Promise[None]

Performs a TypeQL Undefine query in the transaction.

Input parameters
Name Description Type Default Value

query

The TypeQL Undefine query to be executed

str

options

Specify query options

TypeDBOptions

None

Returns

Promise[None]

Code examples
transaction.query.undefine(query, options).resolve()

update

update(query: str, options: TypeDBOptions | None = None) -> Iterator[ConceptMap]

Performs a TypeQL Update query in the transaction.

Input parameters
Name Description Type Default Value

query

The TypeQL Update query to be executed

str

options

Specify query options

TypeDBOptions | None

None

Returns

Iterator[ConceptMap]

Code examples
transaction.query.update(query, options)

Answer

ConceptMapGroup

Contains an element of the group query result.

concept_maps

concept_maps() -> Iterator[ConceptMap]

Retrieves the ConceptMaps of the group.

Returns

Iterator[ConceptMap]

Code examples
concept_map_group.concept_maps()

owner

owner() -> Concept

Retrieves the concept that is the group owner.

Returns

Concept

Code examples
concept_map_group.owner()

ConceptMap

Contains a mapping of variables to concepts.

concepts

concepts() -> Iterator[Concept]

Produces an iterator over all concepts in this ConceptMap.

Returns

Iterator[Concept]

Code examples
concept_map.concepts()

explainables

explainables() -> Explainables

Gets the Explainables object for this ConceptMap, exposing which of the concepts in this ConceptMap are explainable.

Returns

Explainables

Code examples
concept_map.explainables()

get

get(variable: str) -> Concept

Retrieves a concept for a given variable name.

Input parameters
Name Description Type Default Value

variable

The string representation of a variable

str

Returns

Concept

Code examples
concept_map.get(variable)

map

map() -> Mapping[str, Concept]

Returns the inner Mapping where keys are query variables, and values are concepts.

Returns

Mapping[str, Concept]

Code examples
concept_map.concepts()

variables

variables() -> Iterator[str]

Produces an iterator over all variables in this ConceptMap.

Returns

Iterator[str]

Code examples
concept_map.variables()

ValueGroup

Contains an element of the group aggregate query result.

owner

owner() -> Concept

Retrieves the concept that is the group owner.

Returns

Concept

Code examples
value_group.owner()

value

value() -> Value | None

Retrieves the Value answer of the group.

Returns

Value | None

Code examples
value_group.value()

Promise

A Promise represents an asynchronous network operation.

The request it represents is performed immediately. The response is only retrieved once the Promise is resolved.

map

classmethod map(ctor: Callable[[U], T], raw: Callable[[], U]) -> Promise[T]
Returns

Promise[T]

resolve

resolve() -> T

Retrieves the result of the Promise.

Returns

T

Code examples
promise.resolve()

Explainables

Contains explainable objects.

attribute

attribute(variable: str) -> Explainable

Retrieves the explainable attribute with the given variable name.

Input parameters
Name Description Type Default Value

variable

The string representation of a variable

str

Returns

Explainable

Code examples
concept_map.explainables().attribute(variable)

attributes

attributes() -> Mapping[str, Explainable]

Retrieves all of this ConceptMap’s explainable attributes.

Returns

Mapping[str, Explainable]

Code examples
concept_map.explainables().attributes()

ownership

ownership(owner: str, attribute: str) -> Explainable

Retrieves the explainable attribute ownership with the pair of (owner, attribute) variable names.

Input parameters
Name Description Type Default Value

owner

The string representation of the owner variable

str

attribute

The string representation of the attribute variable

str

Returns

Explainable

Code examples
concept_map.explainables().ownership(owner, attribute)

ownerships

ownerships() -> Mapping[tuple[str, str], Explainable]

Retrieves all of this ConceptMap’s explainable ownerships.

Returns

Mapping[tuple[str, str], Explainable]

Code examples
concept_map.explainables().ownerships()

relation

relation(variable: str) -> Explainable

Retrieves the explainable relation with the given variable name.

Input parameters
Name Description Type Default Value

variable

The string representation of a variable

str

Returns

Explainable

Code examples
concept_map.explainables().relation(variable)

relations

relations() -> Mapping[str, Explainable]

Retrieves all of this ConceptMap’s explainable relations.

Returns

Mapping[str, Explainable]

Code examples
concept_map.explainables().relations()

Explainable

Contains an explainable object.

conjunction

conjunction() -> str

Retrieves the subquery of the original query that is actually being explained.

Returns

str

Code examples
explainable.conjunction()

id

id() -> int

Retrieves the unique ID that identifies this Explainable.

Returns

int

Code examples
explainable.id()

Explanation

An explanation of which rule was used for inferring the explained concept, the condition of the rule, the conclusion of the rule, and the mapping of variables between the query and the rule’s conclusion.

conclusion

conclusion() -> ConceptMap

Retrieves the Conclusion for this Explanation.

Returns

ConceptMap

Code examples
explanation.conclusion()

condition

condition() -> ConceptMap

Retrieves the Condition for this Explanation.

Returns

ConceptMap

Code examples
explanation.condition()

query_variable_mapping

query_variable_mapping(var: str) -> set[str]

Retrieves the rule variables corresponding to the query variable var for this Explanation.

Input parameters
Name Description Type Default Value

var

The query variable to map to rule variables.

str

Returns

set[str]

Code examples
explanation.variable_mapping(var)

query_variables

query_variables() -> set[str]

Retrieves the query variables for this Explanation.

Returns

set[str]

Code examples
explanation.query_variables()

rule

rule() -> Rule

Retrieves the Rule for this Explanation.

Returns

Rule

Code examples
explanation.rule()

Concept

ConceptManager

Provides access for all Concept API methods.

get_attribute

get_attribute(iid: str) -> Promise[Attribute]

Retrieves an Attribute by its iid.

Input parameters
Name Description Type Default Value

iid

The iid of the Attribute to retrieve

str

Returns

Promise[Attribute]

Code examples
transaction.concepts.get_attribute(iid).resolve()

get_attribute_type

get_attribute_type(label: str) -> Promise[AttributeType]

Retrieves an AttributeType by its label.

Input parameters
Name Description Type Default Value

label

The label of the AttributeType to retrieve

str

Returns

Promise[AttributeType]

Code examples
transaction.concepts.get_attribute_type(label).resolve()

get_entity

get_entity(iid: str) -> Promise[Entity]

Retrieves an Entity by its iid.

Input parameters
Name Description Type Default Value

iid

The iid of the Entity to retrieve

str

Returns

Promise[Entity]

Code examples
transaction.concepts.get_entity(iid).resolve()

get_entity_type

get_entity_type(label: str) -> Promise[EntityType]

Retrieves an EntityType by its label.

Input parameters
Name Description Type Default Value

label

The label of the EntityType to retrieve

str

Returns

Promise[EntityType]

Code examples
transaction.concepts.get_entity_type(label).resolve()

get_relation

get_relation(iid: str) -> Promise[Relation]

Retrieves a Relation by its iid.

Input parameters
Name Description Type Default Value

iid

The iid of the Relation to retrieve

str

Returns

Promise[Relation]

Code examples
transaction.concepts.get_relation(iid).resolve()

get_relation_type

get_relation_type(label: str) -> Promise[RelationType]

Retrieves a RelationType by its label.

Input parameters
Name Description Type Default Value

label

The label of the RelationType to retrieve

str

Returns

Promise[RelationType]

Code examples
transaction.concepts.get_relation_type(label).resolve()

get_root_attribute_type

get_root_attribute_type() -> AttributeType

Retrieve the root AttributeType, “attribute”.

Returns

AttributeType

Code examples
transaction.concepts.get_root_attribute_type()

get_root_entity_type

get_root_entity_type() -> EntityType

Retrieves the root EntityType, “entity”.

Returns

EntityType

Code examples
transaction.concepts.get_root_entity_type()

get_root_relation_type

get_root_relation_type() -> RelationType

Retrieve the root RelationType, “relation”.

Returns

RelationType

Code examples
transaction.concepts.get_root_relation_type()

get_schema_exception

get_schema_exception() -> list[TypeDBException]

Retrieves a list of all schema exceptions for the current transaction.

Returns

list[TypeDBException]

Code examples
transaction.concepts.get_schema_exception()

put_attribute_type

put_attribute_type(label: str, value_type: ValueType) -> Promise[AttributeType]

Creates a new AttributeType if none exists with the given label, or retrieves the existing one.

Input parameters
Name Description Type Default Value

label

The label of the AttributeType to create or retrieve

str

value_type

The value type of the AttributeType to create or retrieve.

ValueType

Returns

Promise[AttributeType]

Code examples
transaction.concepts.put_attribute_type(label, value_type).resolve()

put_entity_type

put_entity_type(label: str) -> Promise[EntityType]

Creates a new EntityType if none exists with the given label, otherwise retrieves the existing one.

Input parameters
Name Description Type Default Value

label

The label of the EntityType to create or retrieve

str

Returns

Promise[EntityType]

Code examples
transaction.concepts.put_entity_type(label).resolve()

put_relation_type

put_relation_type(label: str) -> Promise[RelationType]

Creates a new RelationType if none exists with the given label, otherwise retrieves the existing one.

Input parameters
Name Description Type Default Value

label

The label of the RelationType to create or retrieve

str

Returns

Promise[RelationType]

Code examples
transaction.concepts.put_relation_type(label).resolve()

Concept

as_attribute

as_attribute() -> Attribute

Casts the concept to Attribute.

Returns

Attribute

Code examples
concept.as_attribute()

as_attribute_type

as_attribute_type() -> AttributeType

Casts the concept to AttributeType.

Returns

AttributeType

Code examples
concept.as_attribute_type()

as_entity

as_entity() -> Entity

Casts the concept to Entity.

Returns

Entity

Code examples
concept.as_entity()

as_entity_type

as_entity_type() -> EntityType

Casts the concept to EntityType.

Returns

EntityType

Code examples
concept.as_entity_type()

as_relation

as_relation() -> Relation

Casts the concept to Relation.

Returns

Relation

Code examples
concept.as_relation()

as_relation_type

as_relation_type() -> RelationType

Casts the concept to RelationType.

Returns

RelationType

Code examples
concept.as_relation_type()

as_role_type

as_role_type() -> RoleType

Casts the concept to RoleType.

Returns

RoleType

Code examples
concept.as_role_type()

as_thing

as_thing() -> Thing

Casts the concept to Thing.

Returns

Thing

Code examples
concept.as_thing()

as_thing_type

as_thing_type() -> ThingType

Casts the concept to ThingType.

Returns

ThingType

Code examples
concept.as_thing_type()

as_type

as_type() -> Type

Casts the concept to Type.

Returns

Type

Code examples
concept.as_type()

as_value

as_value() -> Value

Casts the concept to Value.

Returns

Value

Code examples
concept.as_value()

is_attribute

is_attribute() -> bool

Checks if the concept is an Attribute.

Returns

bool

Code examples
concept.is_attribute()

is_attribute_type

is_attribute_type() -> bool

Checks if the concept is an AttributeType.

Returns

bool

Code examples
concept.is_attribute_type()

is_entity

is_entity() -> bool

Checks if the concept is an Entity.

Returns

bool

Code examples
concept.is_entity()

is_entity_type

is_entity_type() -> bool

Checks if the concept is an EntityType.

Returns

bool

Code examples
concept.is_entity_type()

is_relation

is_relation() -> bool

Checks if the concept is a Relation.

Returns

bool

Code examples
concept.is_relation()

is_relation_type

is_relation_type() -> bool

Checks if the concept is a RelationType.

Returns

bool

Code examples
concept.is_relation_type()

is_role_type

is_role_type() -> bool

Checks if the concept is a RoleType.

Returns

bool

Code examples
concept.is_role_type()

is_thing

is_thing() -> bool

Checks if the concept is a Thing.

Returns

bool

Code examples
concept.is_thing()

is_thing_type

is_thing_type() -> bool

Checks if the concept is a ThingType.

Returns

bool

Code examples
concept.is_thing_type()

is_type

is_type() -> bool

Checks if the concept is a Type.

Returns

bool

Code examples
concept.is_type()

is_value

is_value() -> bool

Checks if the concept is a Value.

Returns

bool

Code examples
concept.is_value()

Schema

Type

Supertypes:

  • Concept

delete

delete(transaction: TypeDBTransaction) -> Promise[None]

Deletes this type from the database.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Promise[None]

Code examples
type_.delete(transaction).resolve()

get_label

get_label() -> Label

Retrieves the unique label of the type.

Returns

Label

Code examples
type_.get_label()

get_subtypes

get_subtypes(transaction: TypeDBTransaction, transitivity: Transitivity = Transitivity.TRANSITIVE) -> Iterator[Type]

Retrieves all direct and indirect (or direct only) subtypes of the type.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

transitivity

Transitivity.TRANSITIVE for direct and indirect subtypes, Transitivity.EXPLICIT for direct subtypes only

Transitivity

Transitivity.TRANSITIVE

Returns

Iterator[Type]

Code examples
type_.get_subtypes(transaction)
type_.get_subtypes(transaction, Transitivity.EXPLICIT)

get_supertype

get_supertype(transaction: TypeDBTransaction) -> Promise[Type | None]

Retrieves the most immediate supertype of the type.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Promise[Type | None]

Code examples
type_.get_supertype(transaction).resolve()

get_supertypes

get_supertypes(transaction: TypeDBTransaction) -> Iterator[Type]

Retrieves all supertypes of the type.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Iterator[Type]

Code examples
type_.get_supertypes(transaction)

is_abstract

is_abstract() -> bool

Checks if the type is prevented from having data instances (i.e., abstract).

Returns

bool

Code examples
type_.is_abstract()

is_root

is_root() -> bool

Checks if the type is a root type.

Returns

bool

Code examples
type_.is_root()

is_type

is_type() -> bool

Checks if the concept is a Type.

Returns

bool

Code examples
type_.is_type()

set_label

set_label(transaction: TypeDBTransaction, new_label: str) -> Promise[None]

Renames the label of the type. The new label must remain unique.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

new_label

The new name to be given to the type.

str

Returns

Promise[None]

Code examples
type_.set_label(transaction, new_label).resolve()

Label

A Label holds the uniquely identifying name of a type.

It consists of an optional scope, and a name, represented scope:name. The scope is used only used to distinguish between role-types of the same name declared in different relation types.

Properties
Name Type Description

name

str

The name part of the label

scope

str | None

The scope part of the label

of

static of(*args: str) -> Label

Creates a Label from a specified name, or scoped name.

Input parameters
Name Description Type Default Value

args

If a single string is provided, this is interpreted as the label name. If a pair of strings is provided, the first string is the scope and the second string is the name.

str

Returns

Label

Code examples
Label.of("entity")
Label.of("relation", "role")

scoped_name

scoped_name() -> str

Returns the string representation of the scoped name.

Returns

str

Code examples
label.scoped_name()

ThingType

Supertypes:

  • Type

get_instances

get_instances(transaction: TypeDBTransaction, transitivity: Transitivity = Transitivity.TRANSITIVE) -> Iterator[Thing]

Retrieves all direct and indirect (or direct only) Thing objects that are instances of this ThingType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

transitivity

Transitivity.TRANSITIVE for direct and indirect instances, Transitivity.EXPLICIT for direct instances only

Transitivity

Transitivity.TRANSITIVE

Returns

Iterator[Thing]

Code examples
thing_type.get_instances(transaction)
thing_type.get_instances(transaction, Transitivity.EXPLICIT)

get_owns

get_owns(transaction: TypeDBTransaction, value_type: ValueType | None = None, transitivity: Transitivity = Transitivity.TRANSITIVE, annotations: set[Annotation] | None = None) -> Iterator[AttributeType]

Retrieves AttributeType that the instances of this ThingType are allowed to own directly or via inheritance.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

value_type

If specified, only attribute types of this ValueType will be retrieved.

ValueType | None

None

transitivity

Transitivity.TRANSITIVE for direct and inherited ownership, Transitivity.EXPLICIT for direct ownership only

Transitivity

Transitivity.TRANSITIVE

annotations

Only retrieve attribute types owned with annotations.

set[Annotation] | None

None

Returns

Iterator[AttributeType]

Code examples
thing_type.get_owns(transaction)
thing_type.get_owns(transaction, value_type,
                    transitivity=Transitivity.EXPLICIT,
                    annotations={Annotation.key()})

get_owns_overridden

get_owns_overridden(transaction: TypeDBTransaction, attribute_type: AttributeType) -> Promise[AttributeType | None]

Retrieves an AttributeType, ownership of which is overridden for this ThingType by a given attribute_type.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

attribute_type

The AttributeType that overrides requested AttributeType

AttributeType

Returns

Promise[AttributeType | None]

Code examples
thing_type.get_owns_overridden(transaction, attribute_type).resolve()

get_plays

get_plays(transaction: TypeDBTransaction, transitivity: Transitivity = Transitivity.TRANSITIVE) -> Iterator[RoleType]

Retrieves all direct and inherited (or direct only) roles that are allowed to be played by the instances of this ThingType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

transitivity

Transitivity.TRANSITIVE for direct and indirect playing, Transitivity.EXPLICIT for direct playing only

Transitivity

Transitivity.TRANSITIVE

Returns

Iterator[RoleType]

Code examples
thing_type.get_plays(transaction)
thing_type.get_plays(transaction, Transitivity.EXPLICIT)

get_plays_overridden

get_plays_overridden(transaction: TypeDBTransaction, role_type: RoleType) -> Promise[RoleType | None]

Retrieves a RoleType that is overridden by the given role_type for this ThingType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

role_type

The RoleType that overrides an inherited role

RoleType

Returns

Promise[RoleType | None]

Code examples
thing_type.get_plays_overridden(transaction, role_type).resolve()

get_subtypes

get_subtypes(transaction: TypeDBTransaction, transitivity: Transitivity = Transitivity.TRANSITIVE) -> Iterator[ThingType]

Retrieves all direct and indirect (or direct only) subtypes of the ThingType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

transitivity

Transitivity.TRANSITIVE for direct and indirect subtypes, Transitivity.EXPLICIT for direct subtypes only

Transitivity

Transitivity.TRANSITIVE

Returns

Iterator[ThingType]

Code examples
thing_type.get_subtypes(transaction)
thing_type.get_subtypes(transaction, Transitivity.EXPLICIT)

get_supertype

get_supertype(transaction: TypeDBTransaction) -> Promise[ThingType | None]

Retrieves the most immediate supertype of the ThingType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Promise[ThingType | None]

Code examples
thing_type.get_supertype(transaction).resolve()

get_supertypes

get_supertypes(transaction: TypeDBTransaction) -> Iterator[ThingType]

Retrieves all supertypes of the ThingType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Iterator[ThingType]

Code examples
thing_type.get_supertypes(transaction)

get_syntax

get_syntax(transaction: TypeDBTransaction) -> Promise[str]

Produces a pattern for creating this ThingType in a define query.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Promise[str]

Code examples
thing_type.get_syntax(transaction).resolve()

is_thing_type

is_thing_type() -> bool

Checks if the concept is a ThingType.

Returns

bool

Code examples
thing_type.is_thing_type()

set_abstract

set_abstract(transaction: TypeDBTransaction) -> Promise[None]

Set a ThingType to be abstract, meaning it cannot have instances.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Promise[None]

Code examples
thing_type.set_abstract(transaction).resolve()

set_owns

set_owns(transaction: TypeDBTransaction, attribute_type: AttributeType, overridden_type: AttributeType | None = None, annotations: set[Annotation] | None = None) -> Promise[None]

Allows the instances of this ThingType to own the given AttributeType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

attribute_type

The AttributeType to be owned by the instances of this type.

AttributeType

overridden_type

The AttributeType that this attribute ownership overrides, if applicable.

AttributeType | None

None

annotations

Adds annotations to the ownership.

set[Annotation] | None

None

Returns

Promise[None]

Code examples
thing_type.set_owns(transaction, attribute_type).resolve()
thing_type.set_owns(transaction, attribute_type,
                    overridden_type=overridden_type,
                    annotations={Annotation.key()}).resolve()

set_plays

set_plays(transaction: TypeDBTransaction, role_type: RoleType, overriden_type: RoleType | None = None) -> Promise[None]

Allows the instances of this ThingType to play the given role.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

role_type

The role to be played by the instances of this type

RoleType

overriden_type

The role type that this role overrides, if applicable

RoleType | None

None

Returns

Promise[None]

Code examples
thing_type.set_plays(transaction, role_type).resolve()
thing_type.set_plays(transaction, role_type, overridden_type).resolve()

unset_abstract

unset_abstract(transaction: TypeDBTransaction) -> Promise[None]

Set a ThingType to be non-abstract, meaning it can have instances.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Promise[None]

Code examples
thing_type.unset_abstract(transaction).resolve()

unset_owns

unset_owns(transaction: TypeDBTransaction, attribute_type: AttributeType) -> Promise[None]

Disallows the instances of this ThingType from owning the given AttributeType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

attribute_type

The AttributeType to not be owned by the type.

AttributeType

Returns

Promise[None]

Code examples
thing_type.unset_owns(transaction, attribute_type).resolve()

unset_plays

unset_plays(transaction: TypeDBTransaction, role_type: RoleType) -> Promise[None]

Disallows the instances of this ThingType from playing the given role.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

role_type

The role to not be played by the instances of this type.

RoleType

Returns

Promise[None]

Code examples
thing_type.unset_plays(transaction, role_type).resolve()

EntityType

Supertypes:

  • ThingType

Entity types represent the classification of independent objects in the data model of the business domain.

as_entity_type

as_entity_type() -> EntityType

Casts the concept to EntityType.

Returns

EntityType

Code examples
entity_type.as_entity_type()

create

create(transaction: TypeDBTransaction) -> Promise[Entity]

Creates and returns a new instance of this EntityType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Promise[Entity]

Code examples
entity_type.create(transaction).resolve()

get_instances

get_instances(transaction: TypeDBTransaction, transitivity: Transitivity = Transitivity.TRANSITIVE) -> Iterator[Entity]

Retrieves all direct and indirect (or direct only) Entity objects that are instances of this EntityType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

transitivity

Transitivity.TRANSITIVE for direct and indirect instances, Transitivity.EXPLICIT for direct instances only

Transitivity

Transitivity.TRANSITIVE

Returns

Iterator[Entity]

Code examples
entity_type.get_instances(transaction, transitivity)

get_subtypes

get_subtypes(transaction: TypeDBTransaction, transitivity: Transitivity = Transitivity.TRANSITIVE) -> Iterator[EntityType]

Retrieves all direct and indirect (or direct only) subtypes of the EntityType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

transitivity

Transitivity.TRANSITIVE for direct and indirect subtypes, Transitivity.EXPLICIT for direct subtypes only

Transitivity

Transitivity.TRANSITIVE

Returns

Iterator[EntityType]

Code examples
entity_type.get_subtypes(transaction, transitivity)

is_entity_type

is_entity_type() -> bool

Checks if the concept is an EntityType.

Returns

bool

Code examples
entity_type.is_entity_type()

set_supertype

set_supertype(transaction: TypeDBTransaction, super_entity_type: EntityType) -> Promise[None]

Sets the supplied EntityType as the supertype of the current EntityType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

super_entity_type

The EntityType to set as the supertype of this EntityType

EntityType

Returns

Promise[None]

Code examples
entity_type.set_supertype(transaction, super_entity_type).resolve()

RelationType

Supertypes:

  • ThingType

Relation types (or subtypes of the relation root type) represent relationships between types. Relation types have roles.

Other types can play roles in relations if it’s mentioned in their definition.

A relation type must specify at least one role.

as_relation_type

as_relation_type() -> RelationType

Casts the concept to RelationType.

Returns

RelationType

Code examples
relation_type.as_relation_type()

create

create(transaction: TypeDBTransaction) -> Promise[Relation]

Creates and returns an instance of this RelationType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Promise[Relation]

Code examples
relation_type.create(transaction).resolve()

get_instances

get_instances(transaction: TypeDBTransaction, transitivity: Transitivity = Transitivity.TRANSITIVE) -> Iterator[Relation]

Retrieves all direct and indirect (or direct only) Relations that are instances of this RelationType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

transitivity

Transitivity.TRANSITIVE for direct and indirect instances, Transitivity.EXPLICIT for direct relates only

Transitivity

Transitivity.TRANSITIVE

Returns

Iterator[Relation]

Code examples
relation_type.get_instances(transaction, transitivity)

get_relates

get_relates(transaction: TypeDBTransaction, role_label: str | None = None, transitivity: Transitivity = Transitivity.TRANSITIVE) -> Promise[RoleType | None] | Iterator[RoleType]

Retrieves roles that this RelationType relates to directly or via inheritance. If role_label is given, returns a corresponding RoleType or None.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

role_label

Label of the role we wish to retrieve (optional)

str | None

None

transitivity

Transitivity.TRANSITIVE for direct and inherited relates, Transitivity.EXPLICIT for direct relates only

Transitivity

Transitivity.TRANSITIVE

Returns

Promise[RoleType | None] | Iterator[RoleType]

Code examples
relation_type.get_relates(transaction, role_label, transitivity).resolve()
relation_type.get_relates(transaction, transitivity)

get_relates_overridden

get_relates_overridden(transaction: TypeDBTransaction, role_label: str) -> Promise[RoleType | None]

Retrieves a RoleType that is overridden by the role with the role_label.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

role_label

Label of the role that overrides an inherited role

str

Returns

Promise[RoleType | None]

Code examples
relation_type.get_relates_overridden(transaction, role_label).resolve()

get_subtypes

get_subtypes(transaction: TypeDBTransaction, transitivity: Transitivity = Transitivity.TRANSITIVE) -> Iterator[RelationType]

Retrieves all direct and indirect (or direct only) subtypes of the RelationType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

transitivity

Transitivity.TRANSITIVE for direct and indirect subtypes, Transitivity.EXPLICIT for direct subtypes only

Transitivity

Transitivity.TRANSITIVE

Returns

Iterator[RelationType]

Code examples
relation_type.get_subtypes(transaction, transitivity)

is_relation_type

is_relation_type() -> bool

Checks if the concept is a RelationType.

Returns

bool

Code examples
relation_type.is_relation_type()

set_relates

set_relates(transaction: TypeDBTransaction, role_label: str, overridden_label: str | None = None) -> Promise[None]

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.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

role_label

The new role for the RelationType to relate to

str

overridden_label

The label being overridden, if applicable

str | None

None

Returns

Promise[None]

Code examples
relation_type.set_relates(transaction, role_label).resolve()
relation_type.set_relates(transaction, role_label, overridden_label).resolve()

set_supertype

set_supertype(transaction: TypeDBTransaction, super_relation_type: RelationType) -> Promise[None]

Sets the supplied RelationType as the supertype of the current RelationType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

super_relation_type

The RelationType to set as the supertype of this RelationType

RelationType

Returns

Promise[None]

Code examples
relation_type.set_supertype(transaction, super_relation_type).resolve()

unset_relates

unset_relates(transaction: TypeDBTransaction, role_label: str) -> Promise[None]

Disallows this RelationType from relating to the given role.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

role_label

The role to not relate to the relation type.

str

Returns

Promise[None]

Code examples
relation_type.unset_relates(transaction, role_label).resolve()

RoleType

Supertypes:

  • Type

Roles are special internal types used by relations. We can not create an instance of a role in a database. But we can set an instance of another type (role player) to play a role in a particular instance of a relation type.

Roles allow a schema to enforce logical constraints on types of role players.

as_role_type

as_role_type() -> RoleType

Casts the concept to RoleType.

Returns

RoleType

Code examples
role_type.as_role_type()

get_player_instances

get_player_instances(transaction: TypeDBTransaction, transitivity: Transitivity = Transitivity.TRANSITIVE) -> Iterator[Thing]

Retrieves the Thing instances that play this role.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

transitivity

Transitivity.TRANSITIVE for direct and indirect playing, Transitivity.EXPLICIT for direct playing only

Transitivity

Transitivity.TRANSITIVE

Returns

Iterator[Thing]

Code examples
role_type.get_player_instances(transaction, transitivity)

get_player_types

get_player_types(transaction: TypeDBTransaction, transitivity: Transitivity = Transitivity.TRANSITIVE) -> Iterator[ThingType]

Retrieves the ThingTypes whose instances play this role.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

transitivity

Transitivity.TRANSITIVE for direct and indirect playing, Transitivity.EXPLICIT for direct playing only

Transitivity

Transitivity.TRANSITIVE

Returns

Iterator[ThingType]

Code examples
role_type.get_player_types(transaction, transitivity)

get_relation_instances

get_relation_instances(transaction: TypeDBTransaction, transitivity: Transitivity = Transitivity.TRANSITIVE) -> Iterator[Relation]

Retrieves the Relation instances that this role is related to.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

transitivity

Transitivity.TRANSITIVE for direct and indirect relation, Transitivity.EXPLICIT for direct relation only

Transitivity

Transitivity.TRANSITIVE

Returns

Iterator[Relation]

Code examples
role_type.get_relation_instances(transaction, transitivity)

get_relation_type

get_relation_type(transaction: TypeDBTransaction) -> Promise[RelationType]

Retrieves the RelationType that this role is directly related to.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Promise[RelationType]

Code examples
role_type.get_relation_type(transaction).resolve()

get_relation_types

get_relation_types(transaction: TypeDBTransaction) -> Iterator[RelationType]

Retrieves RelationTypes that this role is related to (directly or indirectly).

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Iterator[RelationType]

Code examples
role_type.get_relation_types(transaction)

get_subtypes

get_subtypes(transaction: TypeDBTransaction, transitivity: Transitivity = Transitivity.TRANSITIVE) -> Iterator[RoleType]

Retrieves all direct and indirect (or direct only) subtypes of the RoleType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

transitivity

Transitivity.TRANSITIVE for direct and indirect subtypes, Transitivity.EXPLICIT for direct subtypes only

Transitivity

Transitivity.TRANSITIVE

Returns

Iterator[RoleType]

Code examples
role_type.get_subtypes(transaction, transitivity)

get_supertype

get_supertype(transaction: TypeDBTransaction) -> Promise[RoleType | None]

Retrieves the most immediate supertype of the RoleType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Promise[RoleType | None]

Code examples
role_type.get_supertype(transaction).resolve()

get_supertypes

get_supertypes(transaction: TypeDBTransaction) -> Iterator[RoleType]

Retrieves all supertypes of the RoleType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Iterator[RoleType]

Code examples
role_type.get_supertypes(transaction)

is_role_type

is_role_type() -> bool

Checks if the concept is a RoleType.

Returns

bool

Code examples
role_type.is_role_type()

AttributeType

Supertypes:

  • ThingType

Attribute types represent properties that other types can own.

Attribute types have a value type. This value type is fixed and unique for every given instance of the attribute type.

Other types can own an attribute type. That means that instances of these other types can own an instance of this attribute type. This usually means that an object in our domain has a property with the matching value.

Multiple types can own the same attribute type, and different instances of the same type or different types can share ownership of the same attribute instance.

as_attribute_type

as_attribute_type() -> AttributeType

Casts the concept to AttributeType.

Returns

AttributeType

Code examples
attribute.as_attribute_type()

get

get(transaction: TypeDBTransaction, value: Value | bool | int | float | str | datetime) -> Promise[Attribute | None]

Retrieves an Attribute of this AttributeType with the given value if such Attribute exists. Otherwise, returns None.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

value

Attribute’s value

Value | bool | int | float | str | datetime

Returns

Promise[Attribute | None]

Code examples
attribute = attribute_type.get(transaction, value).resolve()

get_instances

get_instances(transaction: TypeDBTransaction, transitivity: Transitivity = Transitivity.TRANSITIVE) -> Iterator[Attribute]

Retrieves all direct and indirect (or direct only) Attributes that are instances of this AttributeType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

transitivity

Transitivity.TRANSITIVE for direct and indirect subtypes, Transitivity.EXPLICIT for direct subtypes only

Transitivity

Transitivity.TRANSITIVE

Returns

Iterator[Attribute]

Code examples
attribute_type.get_instances(transaction)
attribute_type.get_instances(transaction, Transitivity.EXPLICIT)

get_owners

get_owners(transaction: TypeDBTransaction, annotations: set[Annotation] | None = None, transitivity: Transitivity = Transitivity.TRANSITIVE) -> Iterator[ThingType]

Retrieve all Things that own an attribute of this AttributeType. Optionally, filtered by Annotations.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

annotations

Only retrieve ThingTypes that have an attribute of this AttributeType with all given Annotations

set[Annotation] | None

None

transitivity

Transitivity.TRANSITIVE for direct and inherited ownership, Transitivity.EXPLICIT for direct ownership only

Transitivity

Transitivity.TRANSITIVE

Returns

Iterator[ThingType]

Code examples
attribute_type.get_owners(transaction)
attribute_type.get_owners(transaction, annotations=Annotation.unique(), transitivity=Transitivity.EXPLICIT)

get_regex

get_regex(transaction: TypeDBTransaction) -> Promise[str]

Retrieves the regular expression that is defined for this AttributeType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Promise[str]

Code examples
attribute_type.get_regex(transaction).resolve()

get_subtypes_with_value_type

get_subtypes_with_value_type(transaction: TypeDBTransaction, value_type: ValueType, transitivity: Transitivity = Transitivity.TRANSITIVE) -> Iterator[AttributeType]

Retrieves all direct and indirect (or direct only) subtypes of this AttributeType with given ValueType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

value_type

ValueType for retrieving subtypes

ValueType

transitivity

Transitivity.TRANSITIVE for direct and indirect subtypes, Transitivity.EXPLICIT for direct subtypes only

Transitivity

Transitivity.TRANSITIVE

Returns

Iterator[AttributeType]

Code examples
attribute_type.get_subtypes_with_value_type(transaction, value_type)
attribute_type.get_subtypes_with_value_type(transaction, value_type,
                                            Transitivity.EXPLICIT)

get_value_type

get_value_type() -> ValueType

Retrieves the ValueType of this AttributeType.

Returns

ValueType

Code examples
attribute_type.get_value_type()

is_attribute_type

is_attribute_type() -> bool

Checks if the concept is an AttributeType.

Returns

bool

Code examples
attribute.is_attribute_type()

is_boolean

is_boolean() -> bool

Returns True if the value for attributes of this type is of type boolean. Otherwise, returns False.

Returns

bool

Code examples
attribute_type.is_boolean()

is_datetime

is_datetime() -> bool

Returns True if the value for attributes of this type is of type datetime. Otherwise, returns False.

Returns

bool

Code examples
attribute_type.is_datetime()

is_double

is_double() -> bool

Returns True if the value for attributes of this type is of type double. Otherwise, returns False.

Returns

bool

Code examples
attribute_type.is_double()

is_long

is_long() -> bool

Returns True if the value for attributes of this type is of type long. Otherwise, returns False.

Returns

bool

Code examples
attribute_type.is_long()

is_string

is_string() -> bool

Returns True if the value for attributes of this type is of type string. Otherwise, returns False.

Returns

bool

Code examples
attribute_type.is_string()

put

put(transaction: TypeDBTransaction, value: Value | bool | int | float | str | datetime) -> Promise[Attribute]

Adds and returns an Attribute of this AttributeType with the given value.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

value

New Attribute’s value (datetime values are treated as timezone naive, with tzinfo being ignored)

Value | bool | int | float | str | datetime

Returns

Promise[Attribute]

Code examples
attribute = attribute_type.put(transaction, value).resolve()

set_regex

set_regex(transaction: TypeDBTransaction, regex: str) -> Promise[None]

Sets a regular expression as a constraint for this AttributeType. Values of all Attributes of this type (inserted earlier or later) should match this regex.

Can only be applied for AttributeTypes with a string value type.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

regex

Regular expression

str

Returns

Promise[None]

Code examples
attribute_type.set_regex(transaction, regex).resolve()

set_supertype

set_supertype(transaction: TypeDBTransaction, super_attribute_type: AttributeType) -> Promise[None]

Sets the supplied AttributeType as the supertype of the current AttributeType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

super_attribute_type

The AttributeType to set as the supertype of this AttributeType

AttributeType

Returns

Promise[None]

Code examples
attribute_type.set_supertype(transaction, super_attribute_type).resolve()

unset_regex

unset_regex(transaction: TypeDBTransaction) -> Promise[None]

Removes the regular expression that is defined for this AttributeType.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Promise[None]

Code examples
attribute_type.unset_regex(transaction).resolve()

Annotation

is_key

is_key() -> bool

Checks if this Annotation is a @key annotation.

Returns

bool

Code examples
annotation.is_key()

is_unique

is_unique() -> bool

Checks if this Annotation is a @unique annotation.

Returns

bool

Code examples
annotation.is_unique()

key

static key() -> Annotation

Produces a @key annotation.

Returns

Annotation

Code examples
Annotation.key()

unique

static unique() -> Annotation

Produces a @unique annotation.

Returns

Annotation

Code examples
Annotation.unique()

Transitivity

This class is used for specifying whether we need explicit or transitive subtyping, instances, etc.

Examples
attribute_type.get_owners(transaction, annotations=annotations, transitivity=Transitivity.EXPLICIT)
Enum constants
Name Value

EXPLICIT

0

TRANSITIVE

1

ValueType

TypeQL value types for attributes and value concepts.

Enum constants
Name Value

BOOLEAN

_ValueType(is_writable=True, is_keyable=False, 1)

DATETIME

_ValueType(is_writable=True, is_keyable=True, 5)

DOUBLE

_ValueType(is_writable=True, is_keyable=False, 3)

LONG

_ValueType(is_writable=True, is_keyable=True, 2)

OBJECT

_ValueType(is_writable=False, is_keyable=False, 0)

STRING

_ValueType(is_writable=True, is_keyable=True, 4)

Data

Thing

Supertypes:

  • Concept

as_thing

as_thing() -> Thing

Casts the concept to Thing.

Returns

Thing

Code examples
thing.as_thing()

delete

delete(transaction: TypeDBTransaction) -> Promise[None]

Deletes this Thing.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Promise[None]

Code examples
thing.delete(transaction).resolve()

get_has

get_has(transaction: TypeDBTransaction, attribute_type: AttributeType = None, attribute_types: list[AttributeType] = None, annotations: set[Annotation] = frozenset({})) -> Iterator[Attribute]

Retrieves the Attributes that this Thing owns. Optionally, filtered by an AttributeType or a list of AttributeTypes. Optionally, filtered by Annotations.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

attribute_type

The AttributeType to filter the attributes by

AttributeType

None

attribute_types

The AttributeTypes to filter the attributes by

list[AttributeType]

None

annotations

Only retrieve attributes with all given Annotations

set[Annotation]

frozenset({})

Returns

Iterator[Attribute]

Code examples
thing.get_has(transaction)
thing.get_has(transaction, attribute_type=attribute_type,
              annotations=set(Annotation.key()))

get_iid

get_iid() -> str

Retrieves the unique id of the Thing.

Returns

str

Code examples
thing.get_iid()

get_playing

get_playing(transaction: TypeDBTransaction) -> Iterator[RoleType]

Retrieves the roles that this Thing is currently playing.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Iterator[RoleType]

Code examples
thing.get_playing(transaction)

get_relations

get_relations(transaction: TypeDBTransaction, *role_types: RoleType) -> Iterator[Relation]

Retrieves all the Relations which this Thing plays a role in, optionally filtered by one or more given roles.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

role_types

0 or more role types to filter the relations by.

RoleType

Returns

Iterator[Relation]

Code examples
thing.get_relations(transaction, role_types)

get_type

get_type() -> ThingType

Retrieves the type which this Thing belongs to.

Returns

ThingType

Code examples
thing.get_type()

is_deleted

is_deleted(transaction: TypeDBTransaction) -> Promise[bool]

Checks if this Thing is deleted.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Promise[bool]

Code examples
thing.is_deleted(transaction).resolve()

is_inferred

is_inferred() -> bool

Checks if this Thing is inferred by a [Reasoning Rule].

Returns

bool

Code examples
thing.is_inferred()

is_thing

is_thing() -> bool

Checks if the concept is a Thing.

Returns

bool

Code examples
thing.is_thing()

set_has

set_has(transaction: TypeDBTransaction, attribute: Attribute) -> Promise[None]

Assigns an Attribute to be owned by this Thing.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

attribute

The Attribute to be owned by this Thing.

Attribute

Returns

Promise[None]

Code examples
thing.set_has(transaction, attribute).resolve()

unset_has

unset_has(transaction: TypeDBTransaction, attribute: Attribute) -> Promise[None]

Unassigns an Attribute from this Thing.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

attribute

The Attribute to be disowned from this Thing.

Attribute

Returns

Promise[None]

Code examples
thing.unset_has(transaction, attribute).resolve()

Entity

Supertypes:

  • Thing

Instance of data of an entity type, representing a standalone object that exists in the data model independently.

Entity does not have a value. It is usually addressed by its ownership over attribute instances and/or roles played in relation instances.

as_entity

as_entity() -> Entity

Casts the concept to Entity.

Returns

Entity

Code examples
entity.as_entity()

get_type

get_type() -> EntityType

Retrieves the type which this Entity belongs to.

Returns

EntityType

Code examples
entity.get_type()

is_entity

is_entity() -> bool

Checks if the concept is an Entity.

Returns

bool

Code examples
entity.is_entity()

Relation

Supertypes:

  • Thing

Relation is an instance of a relation type and can be uniquely addressed by a combination of its type, owned attributes and role players.

add_player

add_player(transaction: TypeDBTransaction, role_type: RoleType, player: Thing) -> Promise[None]

Adds a new role player to play the given role in this Relation.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

role_type

The role to be played by the player

RoleType

player

The thing to play the role

Thing

Returns

Promise[None]

Code examples
relation.add_player(transaction, role_type, player).resolve()

as_relation

as_relation() -> Relation

Casts the concept to Relation.

Returns

Relation

Code examples
relation.as_relation()

get_players

get_players(transaction: TypeDBTransaction) -> dict[RoleType, list[Thing]]

Retrieves a mapping of all instances involved in the Relation and the role each play.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

dict[RoleType, list[Thing]]

Code examples
relation.get_players(transaction)

get_players_by_role_type

get_players_by_role_type(transaction: TypeDBTransaction, *role_types: RoleType) -> Iterator[Thing]

Retrieves all role players of this Relation, optionally filtered by given role types.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

role_types

0 or more role types

RoleType

Returns

Iterator[Thing]

Code examples
relation.get_players_by_role_type(transaction)
relation.get_players_by_role_type(transaction, role_type1, role_type2)

get_relating

get_relating(transaction: TypeDBTransaction) -> Iterator[RoleType]

Retrieves all role types currently played in this Relation.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

Returns

Iterator[RoleType]

Code examples
relation.get_relating(transaction)

get_type

get_type() -> RelationType

Retrieves the type which this Relation belongs to.

Returns

RelationType

Code examples
relation.get_type()

is_relation

is_relation() -> bool

Checks if the concept is a Relation.

Returns

bool

Code examples
relation.is_relation()

remove_player

remove_player(transaction: TypeDBTransaction, role_type: RoleType, player: Thing) -> Promise[None]

Removes the association of the given instance that plays the given role in this Relation.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

role_type

The role to no longer be played by the thing in this Relation

RoleType

player

The instance to no longer play the role in this Relation

Thing

Returns

Promise[None]

Code examples
relation.remove_player(transaction, role_type, player).resolve()

Attribute

Supertypes:

  • Thing

Attribute is an instance of the attribute type and has a value. This value is fixed and unique for every given instance of the attribute type.

Attributes can be uniquely addressed by their type and value.

as_attribute

as_attribute() -> Attribute

Casts the concept to Attribute.

Returns

Attribute

Code examples
attribute.as_attribute()

as_boolean

as_boolean() -> bool

Returns a boolean value of the attribute. If the value has another type, raises an exception.

Returns

bool

Code examples
attribute.as_boolean()

as_datetime

as_datetime() -> datetime

Returns a datetime value of the attribute. If the value has another type, raises an exception.

Returns

datetime

Code examples
attribute.as_boolean()

as_double

as_double() -> float

Returns a double value of the attribute. If the value has another type, raises an exception.

Returns

float

Code examples
attribute.as_boolean()

as_long

as_long() -> int

Returns a long value of the attribute. If the value has another type, raises an exception.

Returns

int

Code examples
attribute.as_long()

as_string

as_string() -> str

Returns a string value of the attribute. If the value has another type, raises an exception.

Returns

str

Code examples
attribute.as_boolean()

get_owners

get_owners(transaction: TypeDBTransaction, owner_type: ThingType | None = None) -> Iterator[Thing]

Retrieves the instances that own this Attribute.

Input parameters
Name Description Type Default Value

transaction

The current transaction

TypeDBTransaction

owner_type

If specified, filter results for only owners of the given type

ThingType | None

None

Returns

Iterator[Thing]

Code examples
attribute.get_owners(transaction)
attribute.get_owners(transaction, owner_type)

get_type

get_type() -> AttributeType

Retrieves the type which this Attribute belongs to.

Returns

AttributeType

Code examples
attribute.get_type()

get_value

get_value() -> bool | int | float | str | datetime

Retrieves the value which the Attribute instance holds.

Returns

bool | int | float | str | datetime

Code examples
attribute.get_value()

get_value_type

get_value_type() -> ValueType

Retrieves the type of the value which the Attribute instance holds.

Returns

ValueType

Code examples
attribute.get_value_type()

is_attribute

is_attribute() -> bool

Checks if the concept is an Attribute.

Returns

bool

Code examples
attribute.is_attribute()

is_boolean

is_boolean() -> bool

Returns True if the attribute value is of type boolean. Otherwise, returns False.

Returns

bool

Code examples
attribute.is_boolean()

is_datetime

is_datetime() -> bool

Returns True if the attribute value is of type datetime. Otherwise, returns False.

Returns

bool

Code examples
attribute.is_datetime()

is_double

is_double() -> bool

Returns True if the attribute value is of type double. Otherwise, returns False.

Returns

bool

Code examples
attribute.is_double()

is_long

is_long() -> bool

Returns True if the attribute value is of type long. Otherwise, returns False.

Returns

bool

Code examples
attribute.is_long()

is_string

is_string() -> bool

Returns True if the attribute value is of type string. Otherwise, returns False.

Returns

bool

Code examples
attribute.is_string()

Value

Supertypes:

  • Concept

as_boolean

as_boolean() -> bool

Returns a boolean value of this value concept. If the value has another type, raises an exception.

Returns

bool

Code examples
value.as_boolean()

as_datetime

as_datetime() -> datetime

Returns a timezone naive datetime value of this value concept. If the value has another type, raises an exception.

Returns

datetime

Code examples
value.as_datetime()

as_double

as_double() -> float

Returns a double value of this value concept. If the value has another type, raises an exception.

Returns

float

Code examples
value.as_double()

as_long

as_long() -> int

Returns a long value of this value concept. If the value has another type, raises an exception.

Returns

int

Code examples
value.as_long()

as_string

as_string() -> str

Returns a string value of this value concept. If the value has another type, raises an exception.

Returns

str

Code examples
value.as_string()

as_value

as_value() -> Value

Casts the concept to Value.

Returns

Value

Code examples
value.as_value()

get

get() -> bool | int | float | str | datetime

Retrieves the value which this value concept holds.

Returns

bool | int | float | str | datetime

Code examples
value.get()

get_value_type

get_value_type() -> ValueType

Retrieves the ValueType of this value concept.

Returns

ValueType

Code examples
value.get_value_type()

is_boolean

is_boolean() -> bool

Returns True if the value which this value concept holds is of type boolean. Otherwise, returns False.

Returns

bool

Code examples
value.is_boolean()

is_datetime

is_datetime() -> bool

Returns True if the value which this value concept holds is of type datetime. Otherwise, returns False.

Returns

bool

Code examples
value.is_datetime()

is_double

is_double() -> bool

Returns True if the value which this value concept holds is of type double. Otherwise, returns False.

Returns

bool

Code examples
value.is_double()

is_long

is_long() -> bool

Returns True if the value which this value concept holds is of type long. Otherwise, returns False.

Returns

bool

Code examples
value.is_long()

is_string

is_string() -> bool

Returns True if the value which this value concept holds is of type string. Otherwise, returns False.

Returns

bool

Code examples
value.is_string()

is_value

is_value() -> bool

Checks if the concept is a Value.

Returns

bool

Code examples
value.is_value()

Logic

LogicManager

Provides methods for manipulating rules in the database.

get_rule

get_rule(label: str) -> Promise[Rule | None]

Retrieves the Rule that has the given label.

Input parameters
Name Description Type Default Value

label

The label of the Rule to create or retrieve

str

Returns

Promise[Rule | None]

Code examples
transaction.logic.get_rule(label).resolve()

get_rules

get_rules() -> Iterator[Rule]

Retrieves all rules.

Returns

Iterator[Rule]

Code examples
transaction.logic.get_rules()

put_rule

put_rule(label: str, when: str, then: str) -> Promise[Rule]

Creates a new Rule if none exists with the given label, or replaces the existing one.

Input parameters
Name Description Type Default Value

label

The label of the Rule to create or replace

str

when

The when body of the rule to create

str

then

The then body of the rule to create

str

Returns

Promise[Rule]

Code examples
transaction.logic.put_rule(label, when, then).resolve()

Rule

Rules are a part of schema and define embedded logic. The reasoning engine uses rules as a set of logic to infer new data. A rule consists of a condition and a conclusion, and is uniquely identified by a label.

Properties
Name Type Description

label

str

The unique label of the rule.

then

str

The single statement that constitutes the ‘then’ of the rule.

when

str

The statements that constitute the ‘when’ of the rule.

delete

delete(transaction: TypeDBTransaction) -> Promise[None]

Deletes this rule.

Input parameters
Name Description Type Default Value

transaction

The current Transaction

TypeDBTransaction

Returns

Promise[None]

Code examples
rule.delete(transaction).resolve()

is_deleted

is_deleted(transaction: TypeDBTransaction) -> Promise[bool]

Check if this rule has been deleted.

Input parameters
Name Description Type Default Value

transaction

The current Transaction

TypeDBTransaction

Returns

Promise[bool]

Code examples
rule.is_deleted(transaction).resolve()

set_label

set_label(transaction: TypeDBTransaction, new_label: str) -> Promise[None]

Renames the label of the rule. The new label must remain unique.

Input parameters
Name Description Type Default Value

transaction

The current Transaction

TypeDBTransaction

new_label

The new label to be given to the rule

str

Returns

Promise[None]

Code examples
rule.set_label(transaction, new_label).resolve()

Errors

TypeDBDriverException

Supertypes:

  • RuntimeError

Exceptions raised by the driver.

Examples
try:
    transaction.commit()
except TypeDBDriverException as err:
    print("Error:", err)