Python gRPC driver

Connection

TypeDB

Package: typedb.driver

driver

static driver(address: str, credentials: Credentials, driver_options: DriverOptions) -> Driver

Creates a connection to TypeDB.

Input parameters
Name Description Type Default Value

address

Address of the TypeDB server.

str

credentials

The credentials to connect with.

Credentials

driver_options

The connection settings to connect with.

DriverOptions

Returns

Driver

Driver

Package: typedb.api.connection.driver

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()

transaction

transaction(database_name: str, transaction_type: TransactionType, options: TransactionOptions | None = None) -> Transaction

Opens a communication tunnel (transaction) to the given database on the running TypeDB server.

Input parameters
Name Description Type Default Value

database_name

The name of the database with which the transaction connects

str

transaction_type

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

TransactionType

options

TransactionOptions to configure the opened transaction

TransactionOptions | None

None

Returns

Transaction

Code examples
driver.transaction(database, transaction_type, options)

Credentials

Package: typedb.api.connection.credentials

User credentials and TLS encryption settings for connecting to TypeDB Server.

Examples
credentials = Credentials(username, password)

DriverOptions

Package: typedb.api.connection.driver_options

User credentials and TLS encryption settings for connecting to TypeDB Server. Arguments: 1) is_tls_enabled: Specify whether the connection to TypeDB must be done over TLS. 2) tls_root_ca_path: Path to the CA certificate to use for authenticating server certificates.

Examples
driver_options = DriverOptions(is_tls_enabled=True, tls_root_ca_path="path/to/ca-certificate.pem")

DatabaseManager

Package: typedb.api.connection.database

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)

import_from_file

import_from_file(name: str, schema: str, data_file_path: str) -> None

Create a database with the given name based on previously exported another database’s data loaded from a file. This is a blocking operation and may take a significant amount of time depending on the database size.

Input parameters
Name Description Type Default Value

name

The name of the database to be created

str

schema

The schema definition query string for the database

str

data_file_path

The exported database file path to import the data from

str

Returns

None

Code examples
driver.databases.import_from_file(name, schema, "data.typedb")

Database

Package: typedb.api.connection.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()

export_to_file

export_to_file(schema_file_path: str, data_file_path: str) -> None

Export a database into a schema definition and a data files saved to the disk. This is a blocking operation and may take a significant amount of time depending on the database size.

Input parameters
Name Description Type Default Value

schema_file_path

The path to the schema definition file to be created

str

data_file_path

The path to the data file to be created

str

Returns

None

Code examples
database.export_to_file("schema.typeql", "data.typedb")

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()

UserManager

Package: typedb.api.user.user

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)

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)

get_current_user

get_current_user() -> User | None

Retrieve the name of the user who opened the current connection.

Returns

User | None

Code examples
driver.users.get_current_user()

User

Package: typedb.api.user.user

TypeDB user information

Properties
Name Type Description

name

str

Returns the name of this user.

delete

delete() -> None

Deletes a user with the given name.

Input parameters
Name Description Type Default Value

username

The name of the user to be deleted

Returns

None

Code examples
driver.users.delete(username)

update_password

update_password(password: str) -> None

Updates the password for this user.

Input parameters
Name Description Type Default Value

password_old

The current password of this user

password_new

The new password

Returns

None

Transaction

Transaction

Package: typedb.api.connection.transaction

Properties
Name Type Description

options

TransactionOptions

The options for the transaction

type

TransactionType

The transaction’s type (READ, WRITE, or SCHEMA)

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)

query

query(query: str, options: QueryOptions | None = None) -> Promise[QueryAnswer]

Execute a TypeQL query in this transaction.

Input parameters
Name Description Type Default Value

query

The query to execute.

str

options

The QueryOptions to execute the query with..

QueryOptions | None

None

Returns

Promise[QueryAnswer]

Code examples
transaction.query("define entity person;", options).resolve()

rollback

rollback() -> None

Rolls back the uncommitted changes made via this transaction.

Returns

None

Code examples
transaction.rollback()

TransactionType

Package: typedb.api.connection.transaction

This class is used to specify the type of transaction.

Examples
driver.transaction(database, TransactionType.READ)
Enum constants
Name Value

READ

0

SCHEMA

2

WRITE

1

is_read

is_read() -> bool
Returns

bool

is_schema

is_schema() -> bool
Returns

bool

is_write

is_write() -> bool
Returns

bool

Answer

QueryAnswer

Package: typedb.api.answer.query_answer

General answer on a query returned by a server. Can be a simple Ok response or a collection of concepts.

Properties
Name Type Description

query_type

QueryType

Retrieves the executed query’s type of this QueryAnswer.

as_concept_documents

as_concept_documents() -> ConceptDocumentIterator

Casts the query answer to ConceptDocumentIterator.

Returns

ConceptDocumentIterator

Code examples
query_answer.as_concept_documents()

as_concept_rows

as_concept_rows() -> ConceptRowIterator

Casts the query answer to ConceptRowIterator.

Returns

ConceptRowIterator

Code examples
query_answer.as_concept_rows()

as_ok

as_ok() -> OkQueryAnswer

Casts the query answer to OkQueryAnswer.

Returns

OkQueryAnswer

Code examples
query_answer.as_ok()

is_concept_documents

is_concept_documents() -> bool

Checks if the query answer is a ConceptDocumentIterator.

Returns

bool

Code examples
query_answer.is_concept_documents()

is_concept_rows

is_concept_rows() -> bool

Checks if the query answer is a ConceptRowIterator.

Returns

bool

Code examples
query_answer.is_concept_rows()

is_ok

is_ok() -> bool

Checks if the query answer is an Ok.

Returns

bool

Code examples
query_answer.is_ok()

OkQueryAnswer

Package: typedb.api.answer.ok_query_answer

Supertypes:

  • QueryAnswer

Represents a simple Ok message as a server answer. Doesn’t contain concepts.

as_ok

as_ok() -> OkQueryAnswer

Casts the query answer to OkQueryAnswer.

Returns

OkQueryAnswer

Code examples
query_answer.as_ok()

is_ok

is_ok() -> bool

Checks if the query answer is an Ok.

Returns

bool

Code examples
query_answer.is_ok()

ConceptRowIterator

Package: typedb.api.answer.concept_row_iterator

Supertypes:

  • QueryAnswer

Represents an iterator over ConceptRows returned as a server answer.

as_concept_rows

as_concept_rows() -> ConceptRowIterator

Casts the query answer to ConceptRowIterator.

Returns

ConceptRowIterator

Code examples
query_answer.as_concept_rows()

is_concept_rows

is_concept_rows() -> bool

Checks if the query answer is a ConceptRowIterator.

Returns

bool

Code examples
query_answer.is_concept_rows()

ConceptRow

Package: typedb.api.answer.concept_row

Contains a row of concepts with a header.

Properties
Name Type Description

query_type

QueryType

Retrieves the executed query’s type of this ConceptRow. Shared between all the rows in a QueryAnswer.

column_names

column_names() -> Iterator[str]

Produces an iterator over all column names (variables) in the header of this ConceptRow. Shared between all the rows in a QueryAnswer.

Returns

Iterator[str]

Code examples
concept_row.column_names()

concepts

concepts() -> Iterator[Concept]

Produces an iterator over all concepts in this ConceptRow, skipping empty results.

Returns

Iterator[Concept]

Code examples
concept_row.concepts()

get

get(column_name: str) -> Concept | None

Retrieves a concept for a given column name (variable). Returns None if the variable has an empty answer. Throws an exception if the variable is not present.

Input parameters
Name Description Type Default Value

column_name

The string representation of a variable (column name from column_names)

str

Returns

Concept | None

Code examples
concept_row.get(column_name)

get_index

get_index(column_index: int) -> Concept | None

Retrieves a concept for a given index of the header (‘’column_names’’). Returns None if the index points to an empty answer. Throws an exception if the index is not in the row’s range.

Input parameters
Name Description Type Default Value

column_index

The column index

int

Returns

Concept | None

Code examples
concept_row.get_index(column_index)

involved_conjunctions

involved_conjunctions() -> Iterator['ConjunctionID'] | None

Retrieve the ConjunctionIDs of Conjunctions that answered this row.

Returns

Iterator['ConjunctionID'] | None

Code examples
concept_row.involved_conjunctions()

query_structure

query_structure() -> 'Pipeline' | None

Retrieve the executed query’s structure from the ConceptRow’s header, if set. It must be requested via “include query structure” in QueryOptions Shared between all the rows in a QueryAnswer.

Returns

'Pipeline' | None

Code examples
concept_row.query_structure()

ConceptDocumentIterator

Package: typedb.api.answer.concept_document_iterator

Supertypes:

  • QueryAnswer

Represents an iterator over ConceptRows returned as a server answer.

as_concept_documents

as_concept_documents() -> ConceptDocumentIterator

Casts the query answer to ConceptDocumentIterator.

Returns

ConceptDocumentIterator

Code examples
query_answer.as_concept_documents()

is_concept_documents

is_concept_documents() -> bool

Checks if the query answer is a ConceptDocumentIterator.

Returns

bool

Code examples
query_answer.is_concept_documents()

QueryType

Package: typedb.api.answer.query_type

Used to specify the type of the executed query.

Examples
concept_row.query_type
Enum constants
Name Value

READ

0

SCHEMA

2

WRITE

1

is_read

is_read() -> bool
Returns

bool

is_schema

is_schema() -> bool
Returns

bool

is_write

is_write() -> bool
Returns

bool

Promise

Package: typedb.common.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()

Concept

Concept

Package: typedb.api.concept.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_instance

as_instance() -> Instance

Casts the concept to Instance.

Returns

Instance

Code examples
concept.as_instance()

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_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()

get_label

get_label() -> str

Get the label of the concept. If this is an Instance, return the label of the type of this instance (“unknown” if type fetching is disabled). If this is a Value, return the label of the value type of the value. If this is a Type, return the label of the type.

Returns

str

Code examples
concept.get_label()

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_boolean

is_boolean() -> bool

Returns True if the value which this Concept holds is of type boolean or if this Concept is an AttributeType of type boolean. Otherwise, returns False.

Returns

bool

Code examples
concept.is_boolean()

is_date

is_date() -> bool

Returns True if the value which this Concept holds is of type date or if this Concept is an AttributeType of type date. Otherwise, returns False.

Returns

bool

Code examples
concept.is_date()

is_datetime

is_datetime() -> bool

Returns True if the value which this Concept holds is of type datetime or if this Concept is an AttributeType of type datetime. Otherwise, returns False.

Returns

bool

Code examples
concept.is_datetime()

is_datetime_tz

is_datetime_tz() -> bool

Returns True if the value which this Concept holds is of type datetime-tz or if this Concept is an AttributeType of type datetime-tz. Otherwise, returns False.

Returns

bool

Code examples
concept.is_datetime_tz()

is_decimal

is_decimal() -> bool

Returns True if the value which this Concept holds is of type decimal or if this Concept is an AttributeType of type decimal. Otherwise, returns False.

Returns

bool

Code examples
concept.is_decimal()

is_double

is_double() -> bool

Returns True if the value which this Concept holds is of type double or if this Concept is an AttributeType of type double. Otherwise, returns False.

Returns

bool

Code examples
concept.is_double()

is_duration

is_duration() -> bool

Returns True if the value which this Concept holds is of type duration or if this Concept is an AttributeType of type duration. Otherwise, returns False.

Returns

bool

Code examples
concept.is_duration()

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_instance

is_instance() -> bool

Checks if the concept is a Instance.

Returns

bool

Code examples
concept.is_instance()

is_integer

is_integer() -> bool

Returns True if the value which this Concept holds is of type integer or if this Concept is an AttributeType of type integer. Otherwise, returns False.

Returns

bool

Code examples
concept.is_integer()

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_string

is_string() -> bool

Returns True if the value which this Concept holds is of type string or if this Concept is an AttributeType of type string. Otherwise, returns False.

Returns

bool

Code examples
concept.is_string()

is_struct

is_struct() -> bool

Returns True if the value which this Concept holds is of type struct or if this Concept is an AttributeType of type struct. Otherwise, returns False.

Returns

bool

Code examples
concept.is_struct()

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()

try_get_boolean

try_get_boolean() -> bool | None

Returns a boolean value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

bool | None

Code examples
value.try_get_boolean()

try_get_date

try_get_date() -> date | None

Returns a timezone naive date value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

date | None

Code examples
value.try_get_date()

try_get_datetime

try_get_datetime() -> Datetime | None

Returns a timezone naive datetime value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

Datetime | None

Code examples
value.try_get_datetime()

try_get_datetime_tz

try_get_datetime_tz() -> Datetime | None

Returns a timezone naive datetime_tz value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

Datetime | None

Code examples
value.try_get_datetime_tz()

try_get_decimal

try_get_decimal() -> Decimal | None

Returns a decimal value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

Decimal | None

Code examples
value.try_get_decimal()

try_get_double

try_get_double() -> float | None

Returns a double value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

float | None

Code examples
value.try_get_double()

try_get_duration

try_get_duration() -> Duration | None

Returns a timezone naive duration value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

Duration | None

Code examples
value.try_get_duration()

try_get_iid

try_get_iid() -> str | None

Retrieves the unique id of the Concept. Returns None if absent.

Returns

str | None

Code examples
concept.try_get_iid()

try_get_integer

try_get_integer() -> int | None

Returns a integer value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

int | None

Code examples
value.try_get_integer()

try_get_label

try_get_label() -> str | None

Get the label of the concept. If this is an Instance, return the label of the type of this instance (None if type fetching is disabled). Returns None if type fetching is disabled. If this is a Value, return the label of the value type of the value. If this is a Type, return the label of the type.

Returns

str | None

Code examples
concept.try_get_label()

try_get_string

try_get_string() -> str | None

Returns a string value of this Concept. If it’s not a Value or it has another type, raises an exception.

Returns

str | None

Code examples
value.try_get_string()

try_get_struct

try_get_struct() -> STRUCT | None

Returns a struct value of this Concept represented as a map from field names to values. If it’s not a Value or it has another type, raises an exception.

Returns

STRUCT | None

Code examples
value.try_get_struct()

try_get_value

try_get_value() -> VALUE | None

Retrieves the value which this Concept holds. Returns None if this Concept does not hold any value.

Returns

VALUE | None

Code examples
concept.try_get_value()

try_get_value_type

try_get_value_type() -> str | None

Retrieves the str` describing the value type fo this Concept. Returns None`` if absent.

Returns

str | None

Code examples
concept.try_get_value_type()

Schema

Type

Package: typedb.api.concept.type.type

Supertypes:

  • Concept

is_type

is_type() -> bool

Checks if the concept is a Type.

Returns

bool

Code examples
type_.is_type()

EntityType

Package: typedb.api.concept.type.entity_type

Supertypes:

  • Type

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()

is_entity_type

is_entity_type() -> bool

Checks if the concept is an EntityType.

Returns

bool

Code examples
entity_type.is_entity_type()

RelationType

Package: typedb.api.concept.type.relation_type

Supertypes:

  • Type

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()

is_relation_type

is_relation_type() -> bool

Checks if the concept is a RelationType.

Returns

bool

Code examples
relation_type.is_relation_type()

RoleType

Package: typedb.api.concept.type.role_type

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()

is_role_type

is_role_type() -> bool

Checks if the concept is a RoleType.

Returns

bool

Code examples
role_type.is_role_type()

AttributeType

Package: typedb.api.concept.type.attribute_type

Supertypes:

  • Type

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()

is_attribute_type

is_attribute_type() -> bool

Checks if the concept is an AttributeType.

Returns

bool

Code examples
attribute.is_attribute_type()

Data

Instance

Package: typedb.api.concept.instance.instance

Supertypes:

  • Concept

as_instance

as_instance() -> Instance

Casts the concept to Instance.

Returns

Instance

Code examples
instance.as_instance()

get_type

get_type() -> Type

Retrieves the type which this Instance belongs to.

Returns

Type

Code examples
instance.get_type()

is_instance

is_instance() -> bool

Checks if the concept is a Instance.

Returns

bool

Code examples
instance.is_instance()

Entity

Package: typedb.api.concept.instance.entity

Supertypes:

  • Instance

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_iid

get_iid() -> str

Retrieves the unique id of the Entity.

Returns

str

Code examples
entity.get_iid()

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

Package: typedb.api.concept.instance.relation

Supertypes:

  • Instance

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

as_relation

as_relation() -> Relation

Casts the concept to Relation.

Returns

Relation

Code examples
relation.as_relation()

get_iid

get_iid() -> str

Retrieves the unique id of the Relation.

Returns

str

Code examples
relation.get_iid()

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()

Attribute

Package: typedb.api.concept.instance.attribute

Supertypes:

  • Instance

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()

get_boolean

get_boolean() -> bool

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

Returns

bool

Code examples
attribute.get_boolean()

get_date

get_date() -> date

Returns a timezone naive date value of the value concept that this attribute holds. If the value has another type, raises an exception.

Returns

date

Code examples
attribute.get_date()

get_datetime

get_datetime() -> Datetime

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

Returns

Datetime

Code examples
attribute.get_datetime()

get_datetime_tz

get_datetime_tz() -> Datetime

Returns a timezone naive datetime_tz value of the value concept that this attribute holds. If the value has another type, raises an exception.

Returns

Datetime

Code examples
attribute.get_datetime_tz()

get_decimal

get_decimal() -> Decimal

Returns a decimal value of the value concept that this attribute holds. If the value has another type, raises an exception.

Returns

Decimal

Code examples
attribute.get_decimal()

get_double

get_double() -> float

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

Returns

float

Code examples
attribute.get_double()

get_duration

get_duration() -> Duration

Returns a timezone naive duration value of the value concept that this attribute holds. If the value has another type, raises an exception.

Returns

Duration

Code examples
attribute.get_duration()

get_integer

get_integer() -> int

Returns a integer value of the value concept that this attribute holds. If the value has another type, raises an exception.

Returns

int

Code examples
attribute.get_integer()

get_string

get_string() -> str

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

Returns

str

Code examples
attribute.get_string()

get_struct

get_struct() -> Concept.STRUCT

Returns a struct value of the value concept that this attribute holds represented as a map from field names to values. If the value has another type, raises an exception.

Returns

Concept.STRUCT

Code examples
attribute.get_struct()

get_type

get_type() -> AttributeType

Retrieves the type which this Attribute belongs to.

Returns

AttributeType

Code examples
attribute.get_type()

get_value

get_value() -> Concept.VALUE

Retrieves the value which the Attribute instance holds.

Returns

Concept.VALUE

Code examples
attribute.get_value()

get_value_type

get_value_type() -> str

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

Returns

str

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()

Value

Package: typedb.api.concept.value.value

Supertypes:

  • Concept

as_value

as_value() -> Value

Casts the concept to Value.

Returns

Value

Code examples
value.as_value()

get

get() -> bool | int | float | Decimal | str | date | Datetime | Duration | Dict[str, Value | None]

Retrieves the value which this value concept holds.

Returns

bool | int | float | Decimal | str | date | Datetime | Duration | Dict[str, Value | None]

Code examples
value.get()

get_boolean

get_boolean() -> bool

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

Returns

bool

Code examples
value.get_boolean()

get_date

get_date() -> date

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

Returns

date

Code examples
value.get_date()

get_datetime

get_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.get_datetime()

get_datetime_tz

get_datetime_tz() -> Datetime

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

Returns

Datetime

Code examples
value.get_datetime_tz()

get_decimal

get_decimal() -> Decimal

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

Returns

Decimal

Code examples
value.get_decimal()

get_double

get_double() -> float

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

Returns

float

Code examples
value.get_double()

get_duration

get_duration() -> Duration

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

Returns

Duration

Code examples
value.get_duration()

get_integer

get_integer() -> int

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

Returns

int

Code examples
value.get_integer()

get_string

get_string() -> str

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

Returns

str

Code examples
value.get_string()

get_struct

get_struct() -> Dict[str, Value | None]

Returns a struct value of this value concept represented as a map from field names to values. If the value has another type, raises an exception.

Returns

Dict[str, Value | None]

Code examples
value.get_struct()

get_type

get_type() -> str

Retrieves the str describing the value type of this Value concept.

Returns

str

Code examples
value.get_type()

is_value

is_value() -> bool

Checks if the concept is a Value.

Returns

bool

Code examples
value.is_value()

Value

Datetime

Package: typedb.common.datetime

An extension class for datetime.datetime class to store additional information about nanoseconds. It is split to a timestamp (time zoned or not) based on the number of full seconds and a nanoseconds part.

Properties
Name Type Description

date

date

Return the date part.

datetime_without_nanos

datetime

Return the standard library’s datetime, containing data up to microseconds.

day

int

Return the datetime’s day (1-31).

hour

int

Return the datetime’s hour (0-23).

microsecond

int

Return the rounded number of microseconds.

minute

int

Return the datetime’s minute (0-59).

month

int

Return the datetime’s month (1-12).

nanos

int

Return the nanoseconds part.

offset_seconds

str | None

Return the timezone offset (local minus UTC) in seconds. None if an IANA name is used for the initialisation instead.

second

int

Return the datetime’s second (0-59).

total_seconds

float

Return the total number of seconds including the nanoseconds part as a float.

ValueError – If timestamp is before the start of the epoch.

tz_name

str | None

Return the timezone IANA name. None if fixed offset is used for the initialisation instead.

tzinfo

tzinfo

Return timezone info.

weekday

int

Return the day of the week as an integer, where Monday == 0 … Sunday == 6.

year

int

Return the datetime’s year (1-9999).

fromstring

classmethod fromstring(datetime_str: str, tz_name: str | None = None, offset_seconds: int | None = None, datetime_fmt: str = '%Y-%m-%dT%H:%M:%S') -> Datetime

Parses a Datetime object from a string with an optional nanoseconds part with a specified tz_name or offset_seconds. The timestamp is adjusted to the given timezone similarly to datetime.fromtimestamp. To save timestamp and tz without automatic adjustment, see Datetime.utcfromstring.

Input parameters
Name Description Type Default Value

datetime_str

The timezone-aware datetime string to parse. Should either be “{datetime_fmt}” or “{datetime_fmt}.{nanos}”. All digits of {nanos} after the 9th one are truncated!

str

tz_name

A timezone name. Accepts any format suitable for ZoneInfo, e.g. IANA.

str | None

None

offset_seconds

Offset in seconds from UTC (e.g., 3600 for +01:00, -18000 for -05:00).

int | None

None

datetime_fmt

The format of the datetime string without the fractional (.%f) part. Default is “%Y-%m-%dT%H:%M:%S”.

str

'%Y-%m-%dT%H:%M:%S'

Returns

Datetime

Code examples
Datetime.fromstring("2024-09-21T18:34:22", tz_name="America/New_York")
Datetime.fromstring("2024-09-21T18:34:22.009257123", tz_name="Europe/London")
Datetime.fromstring("2024-09-21", tz_name="Asia/Calcutta", datetime_fmt="%Y-%m-%d")
Datetime.fromstring("21/09/24 18:34", tz_name="Africa/Cairo", datetime_fmt="%d/%m/%y %H:%M")

fromtimestamp

classmethod fromtimestamp(timestamp_seconds: int, subsec_nanos: int, tz_name: str | None = None, offset_seconds: int | None = None)

Creates a new Datetime based on a timestamp with a specified tz_name or offset_seconds. The timestamp is adjusted to the given timezone similarly to datetime.fromtimestamp. To save timestamp and tz without automatic adjustment, see Datetime.utcfromtimestamp.

Input parameters
Name Description Type Default Value

timestamp_seconds

Amount of full seconds since the epoch in the specified timezone (tz_name).

int

subsec_nanos

A number of nanoseconds since the last seconds boundary. Should be between 0 and 999,999,999.

int

tz_name

A timezone name. Accepts any format suitable for ZoneInfo, e.g. IANA.

str | None

None

offset_seconds

Offset in seconds from UTC (e.g., 3600 for +01:00, -18000 for -05:00).

int | None

None

Returns

``

isoformat

isoformat() -> str

Return the time formatted according to ISO.

Returns

str

offset_seconds_fromstring

classmethod offset_seconds_fromstring(offset: str) -> int

Converts a timezone offset in the format +HHMM or -HHMM to seconds.

Input parameters
Name Description Type Default Value

offset

A string representing the timezone offset in the format +HHMM or -HHMM.

str

Returns

int

Code examples
Datetime.fromstring("2024-09-21T18:34:22.009257123", offset_seconds=Datetime.offset_seconds_fromstring("+0100"))

utcfromstring

classmethod utcfromstring(datetime_str: str, tz_name: str | None = None, offset_seconds: int | None = None, datetime_fmt: str = '%Y-%m-%dT%H:%M:%S') -> Datetime

Parses a Datetime object from a string with an optional nanoseconds part based on a timestamp in the given timezone (tz_name) or UTC by default. If tz_name is passed, the timestamp is not adjusted, saving the data as is. For automatic timestamp adjustment, see Datetime.fromstring.

Input parameters
Name Description Type Default Value

datetime_str

The timezone-aware datetime string to parse. Should either be “{datetime_fmt}” or “{datetime_fmt}.{nanos}”. All digits of {nanos} after the 9th one are truncated!

str

tz_name

A timezone name. Accepts any format suitable for ZoneInfo, e.g. IANA.

str | None

None

offset_seconds

Offset in seconds from UTC (e.g., 3600 for +01:00, -18000 for -05:00).

int | None

None

datetime_fmt

The format of the datetime string without the fractional (.%f) part. Default is “%Y-%m-%dT%H:%M:%S”.

str

'%Y-%m-%dT%H:%M:%S'

Returns

Datetime

Code examples
Datetime.utcfromstring("2024-09-21T18:34:22")
Datetime.utcfromstring("2024-09-21T18:34:22.009257123")
Datetime.utcfromstring("2024-09-21T18:34:22.009257123", tz_name="Europe/London")
Datetime.utcfromstring("2024-09-21", datetime_fmt="%Y-%m-%d")
Datetime.utcfromstring("21/09/24 18:34", tz_name="Europe/London", datetime_fmt="%d/%m/%y %H:%M")

utcfromtimestamp

classmethod utcfromtimestamp(timestamp_seconds: int, subsec_nanos: int, tz_name: str | None = None, offset_seconds: int | None = None)

Creates a new Datetime based on a timestamp in the given timezone (tz_name) or UTC by default. If tz_name is passed, the timestamp is not adjusted, saving the data as is. For automatic timestamp adjustment, see Datetime.fromtimestamp.

Input parameters
Name Description Type Default Value

timestamp_seconds

Amount of full seconds since the epoch in UTC.

int

subsec_nanos

A number of nanoseconds since the last seconds boundary. Should be between 0 and 999,999,999.

int

tz_name

A timezone name. Accepts any format suitable for ZoneInfo, e.g. IANA.

str | None

None

offset_seconds

Offset in seconds from UTC (e.g., 3600 for +01:00, -18000 for -05:00).

int | None

None

Returns

``

Duration

Package: typedb.common.duration

A relative duration, which contains months, days, and nanoseconds. Can be used for calendar-relative durations (eg 7 days forward), or for absolute durations using the nanosecond component. Not convertible to datetime.timedelta due to the lack of months and nanos alternatives.

Properties
Name Type Description

days

int

The days part of the duration

months

int

The months part of the duration

nanos

int

The nanoseconds part of the duration

fromstring

classmethod fromstring(duration_str: str) -> Duration

Parses a Duration object from a string in ISO 8601 format.

Input parameters
Name Description Type Default Value

duration_str

A string representation of the duration. Expected format: PnYnMnDTnHnMnS / PnW

str

Returns

Duration

Code examples
Duration.fromstring("P1Y10M7DT15H44M5.00394892S")
Duration.fromstring("P55W")

Analyze

AnalyzedQuery

Package: typedb.api.analyze.analyzed_query

An AnalyzedQuery contains the server’s representation of the query and preamble functions; as well as the result of types inferred for each variable by type-inference.

fetch

fetch() -> 'Fetch' | None

A representation of the Fetch stage of the query, if it has one.

Returns

'Fetch' | None

pipeline

pipeline() -> Pipeline

A representation of the query as a Pipeline.

Returns

Pipeline

preamble

preamble() -> Iterator['Function']

A representation of the Functions in the preamble of the query.

Returns

Iterator['Function']

Comparator

Package: typedb.common.enums

An enumeration.

Enum constants
Name Value

Contains

7

Equal

0

Greater

4

GreaterOrEqual

5

LessOrEqual

3

LessThan

2

Like

6

NotEqual

1

symbol

symbol()
Returns

``

Conjunction

Package: typedb.api.analyze.conjunction

A representation of the constraints involved in the query, and types inferred for each variable.

annotated_variables

annotated_variables() -> Iterator['Variable']

The variables that have annotations in this conjunction.

Returns

Iterator['Variable']

constraints

constraints() -> Iterator['Constraint']

The Constraint(s) in the conjunction.

Returns

Iterator['Constraint']

variable_annotations

variable_annotations(variable: Variable) -> 'VariableAnnotations' | None

Gets the annotations for a specific variable in this conjunction.

Input parameters
Name Description Type Default Value

variable

the variable to get annotations for

Variable

Returns

'VariableAnnotations' | None

Constraint

Package: typedb.api.analyze.constraint

A representation of a TypeQL constraint.

as_comparison

as_comparison() -> Comparison
Returns

Comparison

as_expression

as_expression() -> Expression
Returns

Expression

as_function_call

as_function_call() -> FunctionCall
Returns

FunctionCall

as_has

as_has() -> Has
Returns

Has

as_iid

as_iid() -> Iid
Returns

Iid

as_is

as_is() -> Is
Returns

Is

as_isa

as_isa() -> Isa
Returns

Isa

as_kind

as_kind() -> Kind
Returns

Kind

as_label

as_label() -> Label
Returns

Label

as_links() -> Links
Returns

Links

as_not

as_not() -> Not
Returns

Not

as_or

as_or() -> Or
Returns

Or

as_owns

as_owns() -> Owns
Returns

Owns

as_plays

as_plays() -> Plays
Returns

Plays

as_relates

as_relates() -> Relates
Returns

Relates

as_sub

as_sub() -> Sub
Returns

Sub

as_try

as_try() -> Try
Returns

Try

as_value

as_value() -> Value
Returns

Value

is_comparison

is_comparison() -> bool
Returns

bool

is_expression

is_expression() -> bool
Returns

bool

is_function_call

is_function_call() -> bool
Returns

bool

is_has

is_has() -> bool
Returns

bool

is_iid

is_iid() -> bool
Returns

bool

is_is

is_is() -> bool
Returns

bool

is_isa

is_isa() -> bool
Returns

bool

is_kind_of

is_kind_of() -> bool
Returns

bool

is_label

is_label() -> bool
Returns

bool

is_links() -> bool
Returns

bool

is_not

is_not() -> bool
Returns

bool

is_or

is_or() -> bool
Returns

bool

is_owns

is_owns() -> bool
Returns

bool

is_plays

is_plays() -> bool
Returns

bool

is_relates

is_relates() -> bool
Returns

bool

is_sub

is_sub() -> bool
Returns

bool

is_try

is_try() -> bool
Returns

bool

is_value

is_value() -> bool
Returns

bool

span

span() -> Span

Gets the span of this constraint in the source query.

Returns

Span

ConstraintExactness

Package: typedb.common.enums

An enumeration.

Enum constants
Name Value

Exact

0

Subtypes

1

ConstraintVertex

Package: typedb.api.analyze.constraint_vertex

The answer to a TypeDB query is a set of concepts which satisfy the constraints in the query. A ConstraintVertex is either a variable, or some identifier of the concept.

as_label

as_label() -> typedb.api.concept.type.type.Type

Down-casts this vertex to a type label.

Returns

typedb.api.concept.type.type.Type

as_named_role

as_named_role() -> typedb.api.analyze.named_role.NamedRole

Down-casts this vertex to a NamedRole. This is an internal variable injected to handle ambiguity in unscoped role-names.

Returns

typedb.api.analyze.named_role.NamedRole

as_value

as_value() -> typedb.api.concept.value.value.Value

Down-casts this vertex to a value.

Returns

typedb.api.concept.value.value.Value

as_variable

as_variable() -> Variable

Down-casts this vertex to a variable.

Returns

Variable

is_label

is_label() -> bool

Checks if this vertex is a label.

Returns

bool

is_named_role

is_named_role() -> bool

Checks if this vertex is a named role.

Returns

bool

is_value

is_value() -> bool

Checks if this vertex is a value.

Returns

bool

is_variable

is_variable() -> bool

Checks if this vertex is a variable.

Returns

bool

Comparison

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents a comparison: <lhs> <comparator> <rhs>

comparator

comparator() -> Comparator
Returns

Comparator

lhs

lhs() -> ConstraintVertex
Returns

ConstraintVertex

rhs

rhs() -> ConstraintVertex
Returns

ConstraintVertex

Expression

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents an expression: let <assigned> = <expression>

arguments

arguments() -> Iterator['ConstraintVertex']
Returns

Iterator['ConstraintVertex']

assigned

assigned() -> ConstraintVertex
Returns

ConstraintVertex

text

text() -> str
Returns

str

Has

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents a ‘has’ constraint: <owner> has <attribute>

attribute

attribute() -> ConstraintVertex
Returns

ConstraintVertex

exactness

exactness() -> ConstraintExactness
Returns

ConstraintExactness

owner

owner() -> ConstraintVertex
Returns

ConstraintVertex

FunctionCall

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents a function call: let <assigned> = name(<arguments>)

arguments

arguments() -> Iterator['ConstraintVertex']
Returns

Iterator['ConstraintVertex']

assigned

assigned() -> Iterator['ConstraintVertex']
Returns

Iterator['ConstraintVertex']

name

name() -> str
Returns

str

Iid

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents an IID constraint: <concept> iid <iid>

iid

iid() -> str
Returns

str

variable

variable() -> ConstraintVertex
Returns

ConstraintVertex

Is

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents an ‘is’ constraint: <lhs> is <rhs>

lhs

lhs() -> ConstraintVertex
Returns

ConstraintVertex

rhs

rhs() -> ConstraintVertex
Returns

ConstraintVertex

Isa

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents an ‘isa’ constraint: <instance> isa(!) <type>

exactness

exactness() -> ConstraintExactness
Returns

ConstraintExactness

instance

instance() -> ConstraintVertex
Returns

ConstraintVertex

type

type() -> ConstraintVertex
Returns

ConstraintVertex

Kind

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents a kind constraint: <kind> <type>

kind

kind() -> typedb.common.enums.Kind
Returns

typedb.common.enums.Kind

type

type() -> ConstraintVertex
Returns

ConstraintVertex

Label

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents a label constraint: <type> label <label>

label

label() -> str
Returns

str

variable

variable() -> ConstraintVertex
Returns

ConstraintVertex

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents a ‘links’ constraint: <relation> links (<role>: <player>)

exactness() -> ConstraintExactness
Returns

ConstraintExactness

player() -> ConstraintVertex
Returns

ConstraintVertex

relation() -> ConstraintVertex
Returns

ConstraintVertex

role() -> ConstraintVertex
Returns

ConstraintVertex

Not

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents a ‘not’ constraint: not { <conjunction> }

conjunction

conjunction() -> ConjunctionID

Index into Pipeline.conjunctions

Returns

ConjunctionID

Plays

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents a ‘plays’ constraint: <player> plays <role>

exactness

exactness() -> ConstraintExactness
Returns

ConstraintExactness

player

player() -> ConstraintVertex
Returns

ConstraintVertex

role

role() -> ConstraintVertex
Returns

ConstraintVertex

Relates

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents a ‘relates’ constraint: <relation> relates <role>

exactness

exactness() -> ConstraintExactness
Returns

ConstraintExactness

relation

relation() -> ConstraintVertex
Returns

ConstraintVertex

role

role() -> ConstraintVertex
Returns

ConstraintVertex

Or

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents an ‘or’ constraint: { <branches[0]> } or { <branches[1]> } [or …]

branches

branches() -> Iterator['ConjunctionID']

Index into Pipeline.conjunctions

Returns

Iterator['ConjunctionID']

Owns

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents an ‘owns’ constraint: <owner> owns <attribute>

attribute

attribute() -> ConstraintVertex
Returns

ConstraintVertex

exactness

exactness() -> ConstraintExactness
Returns

ConstraintExactness

owner

owner() -> ConstraintVertex
Returns

ConstraintVertex

Sub

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents a ‘sub’ constraint: <subtype> sub(!) <supertype>

exactness

exactness() -> ConstraintExactness
Returns

ConstraintExactness

subtype

subtype() -> ConstraintVertex
Returns

ConstraintVertex

supertype

supertype() -> ConstraintVertex
Returns

ConstraintVertex

Try

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents a ‘try’ constraint: try { <conjunction> }

conjunction

conjunction() -> ConjunctionID

Index into Pipeline.conjunctions

Returns

ConjunctionID

Value

Package: typedb.api.analyze.constraint

Supertypes:

  • Constraint

Represents a value constraint: <attribute_type> value <value_type>

attribute_type

attribute_type() -> ConstraintVertex
Returns

ConstraintVertex

value_type

value_type() -> str
Returns

str

Fetch

Package: typedb.api.analyze.fetch

A representation of the ‘fetch’ stage of a query.

as_leaf

as_leaf() -> FetchLeaf

Down-casts this Fetch as a FetchLeaf variant.

Returns

FetchLeaf

as_list

as_list() -> FetchList

Down-casts this Fetch as a FetchList variant.

Returns

FetchList

as_object

as_object() -> FetchObject

Down-casts this Fetch as a FetchObject variant.

Returns

FetchObject

is_leaf

is_leaf() -> bool
Returns

bool

is_list

is_list() -> bool
Returns

bool

is_object

is_object() -> bool
Returns

bool

FetchLeaf

Package: typedb.api.analyze.fetch

Supertypes:

  • Fetch

The leaf of a Fetch object. Holds information on the value it can hold.

annotations

annotations() -> Iterator[str]

The possible ValueType(s) as strings.

Returns

Iterator[str]

FetchList

Package: typedb.api.analyze.fetch

Supertypes:

  • Fetch

A list of Fetch documents.

element

element() -> Fetch

The element type of the list.

Returns

Fetch

FetchObject

Package: typedb.api.analyze.fetch

Supertypes:

  • Fetch

A mapping of string keys to Fetch documents.

get

get(key: str) -> Fetch

The Fetch object for the given key.

Returns

Fetch

keys

keys() -> Iterator[str]

The available keys of this Fetch document.

Returns

Iterator[str]

Function

Package: typedb.api.analyze.function

Holds a representation of a function, and the result of type-inference for each variable.

argument_annotations

argument_annotations() -> Iterator['VariableAnnotations']

Gets the type annotations for each argument of the function.

Returns

Iterator['VariableAnnotations']

argument_variables

argument_variables() -> Iterator['Variable']

Gets the variables which are the arguments of the function.

Returns

Iterator['Variable']

body

body() -> Pipeline

Gets the pipeline which forms the body of the function.

Returns

Pipeline

return_annotations

return_annotations() -> Iterator['VariableAnnotations']

Gets the type annotations for each concept returned by the function.

Returns

Iterator['VariableAnnotations']

return_operation

return_operation() -> ReturnOperation

Gets the return operation of the function.

Returns

ReturnOperation

NamedRole

Package: typedb.api.analyze.named_role

‘links’ & ‘relates’ constraints accept unscoped role names. Since an unscoped role-name does not uniquely identify a role-type, (Different role-types belonging to different relation types may share the same name) an internal variable is introduced to handle the ambiguity

name

name() -> str

The unscoped role name specified in the query.

Returns

str

variable

variable() -> Variable

The internal variable injected to handle ambiguity in unscoped role names.

Returns

Variable

Pipeline

Package: typedb.api.analyze.pipeline

A representation of a query pipeline.

conjunction

conjunction(conjunction_id: ConjunctionID) -> 'Conjunction' | None

Gets the Conjunction corresponding to the ConjunctionID.

Input parameters
Name Description Type Default Value

conjunction_id

the ConjunctionID of the conjunction to retrieve

ConjunctionID

Returns

'Conjunction' | None

get_variable_name

get_variable_name(variable: Variable) -> str | None

Gets the name of the specified variable, if it has one.

Input parameters
Name Description Type Default Value

variable

the variable from this pipeline

Variable

Returns

str | None

stages

stages() -> Iterator['PipelineStage']

A stream/iterator of the stages making up the pipeline.

Returns

Iterator['PipelineStage']

PipelineStage

Package: typedb.api.analyze.pipeline_stage

Representation of a stage in a Pipeline.

as_delete

as_delete() -> DeleteStage
Returns

DeleteStage

as_distinct

as_distinct() -> DistinctStage
Returns

DistinctStage

as_insert

as_insert() -> InsertStage
Returns

InsertStage

as_limit

as_limit() -> LimitStage
Returns

LimitStage

as_match

as_match() -> MatchStage
Returns

MatchStage

as_offset

as_offset() -> OffsetStage
Returns

OffsetStage

as_put

as_put() -> PutStage
Returns

PutStage

as_reduce

as_reduce() -> ReduceStage
Returns

ReduceStage

as_require

as_require() -> RequireStage
Returns

RequireStage

as_select

as_select() -> SelectStage
Returns

SelectStage

as_sort

as_sort() -> SortStage
Returns

SortStage

as_update

as_update() -> UpdateStage
Returns

UpdateStage

is_delete

is_delete() -> bool
Returns

bool

is_distinct

is_distinct() -> bool
Returns

bool

is_insert

is_insert() -> bool
Returns

bool

is_limit

is_limit() -> bool
Returns

bool

is_match

is_match() -> bool
Returns

bool

is_offset

is_offset() -> bool
Returns

bool

is_put

is_put() -> bool
Returns

bool

is_reduce

is_reduce() -> bool
Returns

bool

is_require

is_require() -> bool
Returns

bool

is_select

is_select() -> bool
Returns

bool

is_sort

is_sort() -> bool
Returns

bool

is_update

is_update() -> bool
Returns

bool

DeleteStage

Package: typedb.api.analyze.pipeline_stage

Supertypes:

  • PipelineStage

Represents a ‘delete’ stage.

block

block() -> ConjunctionID
Returns

ConjunctionID

deleted_variables

deleted_variables() -> Iterator['Variable']

The variables for which the unified concepts are to be deleted.

Returns

Iterator['Variable']

DistinctStage

Package: typedb.api.analyze.pipeline_stage

Supertypes:

  • PipelineStage

Represents a ‘distinct’ stage.

InsertStage

Package: typedb.api.analyze.pipeline_stage

Supertypes:

  • PipelineStage

Represents an ‘insert’ stage: insert <block>

block

block() -> ConjunctionID
Returns

ConjunctionID

LimitStage

Package: typedb.api.analyze.pipeline_stage

Supertypes:

  • PipelineStage

Represents a ‘limit’ stage: limit <limit>

limit

limit() -> int
Returns

int

MatchStage

Package: typedb.api.analyze.pipeline_stage

Supertypes:

  • PipelineStage

Represents a ‘match’ stage: match <block>

block

block() -> ConjunctionID

The index into Pipeline.conjunctions.

Returns

ConjunctionID

OffsetStage

Package: typedb.api.analyze.pipeline_stage

Supertypes:

  • PipelineStage

Represents an ‘offset’ stage: offset <offset>

offset

offset() -> int
Returns

int

PutStage

Package: typedb.api.analyze.pipeline_stage

Supertypes:

  • PipelineStage

Represents a ‘put’ stage: put <block>

block

block() -> ConjunctionID
Returns

ConjunctionID

ReduceStage

Package: typedb.api.analyze.pipeline_stage

Supertypes:

  • PipelineStage

Represents a ‘reduce’ stage: reduce <reducers> groupby <groupby>

group_by

group_by() -> Iterator['Variable']

The variables to group by.

Returns

Iterator['Variable']

reduce_assignments

reduce_assignments() -> Iterator[ReduceAssignment]

The reducer assignments.

Returns

Iterator[ReduceAssignment]

RequireStage

Package: typedb.api.analyze.pipeline_stage

Supertypes:

  • PipelineStage

Represents a ‘require’ stage: require <variables>

variables

variables() -> Iterator['Variable']
Returns

Iterator['Variable']

SelectStage

Package: typedb.api.analyze.pipeline_stage

Supertypes:

  • PipelineStage

Represents a ‘select’ stage: select <variables>

variables

variables() -> Iterator['Variable']
Returns

Iterator['Variable']

SortStage

Package: typedb.api.analyze.pipeline_stage

Supertypes:

  • PipelineStage

Represents a ‘sort’ stage: sort <variables-and-order>

variables

variables() -> Iterator[SortVariable]
Returns

Iterator[SortVariable]

UpdateStage

Package: typedb.api.analyze.pipeline_stage

Supertypes:

  • PipelineStage

Represents an ‘update’ stage: update <block>

block

block() -> ConjunctionID
Returns

ConjunctionID

ReduceAssignment

Package: typedb.api.analyze.pipeline_stage.ReduceStage

An assignment of a reducer to a variable.

assigned

assigned() -> Variable
Returns

Variable

reducer

reducer() -> Reducer
Returns

Reducer

Reducer

Package: typedb.api.analyze.reducer

Representation of a reducer used either in a PipelineStage::Reduce or in a function’s ReturnOperation.

arguments

arguments() -> Iterator['Variable']

The arguments to the reducer.

Returns

Iterator['Variable']

name

name() -> str

The reduce operation applied (e.g. ‘sum’, ‘count’).

Returns

str

ReturnOperation

Package: typedb.api.analyze.function

as_check

as_check() -> ReturnOperationCheck
Returns

ReturnOperationCheck

as_reduce

as_reduce() -> ReturnOperationReduce
Returns

ReturnOperationReduce

as_single

as_single() -> ReturnOperationSingle
Returns

ReturnOperationSingle

as_stream

as_stream() -> ReturnOperationStream
Returns

ReturnOperationStream

is_check

is_check() -> bool
Returns

bool

is_reduce

is_reduce() -> bool
Returns

bool

is_single

is_single() -> bool
Returns

bool

is_stream

is_stream() -> bool
Returns

bool

ReturnOperationCheck

Package: typedb.api.analyze.function

Supertypes:

  • ReturnOperation

ReturnOperationReduce

Package: typedb.api.analyze.function

Supertypes:

  • ReturnOperation

reducers

reducers() -> Iterator['Reducer']

Gets the reducers used to compute the aggregations.

Returns

Iterator['Reducer']

ReturnOperationSingle

Package: typedb.api.analyze.function

Supertypes:

  • ReturnOperation

selector

selector() -> str

Gets the selector that determines how the operation selects the row.

Returns

str

variables

variables() -> Iterator['Variable']

Gets the variables in the returned row.

Returns

Iterator['Variable']

ReturnOperationStream

Package: typedb.api.analyze.function

Supertypes:

  • ReturnOperation

variables

variables() -> Iterator['Variable']

Gets the variables in the returned row.

Returns

Iterator['Variable']

SortVariable

Package: typedb.api.analyze.pipeline_stage.SortStage

A variable and its sort order.

order

order() -> SortOrder
Returns

SortOrder

variable

variable() -> Variable
Returns

Variable

SortOrder

Package: typedb.common.enums

An enumeration.

Enum constants
Name Value

Ascending

0

Descending

1

Span

Package: typedb.api.analyze.constraint

The span of a constraint in the source query.

begin

begin() -> int

The offset of the first character.

Returns

int

end

end() -> int

The offset after the last character.

Returns

int

VariableAnnotations

Package: typedb.api.analyze.variable_annotations

Holds typing information about a variable (instance/type/value annotations).

as_instance

as_instance() -> Iterator['Type']

The possible Types of instances this variable can hold.

Returns

Iterator['Type']

as_type

as_type() -> Iterator['Type']

The possible types this variable can hold.

Returns

Iterator['Type']

as_value

as_value() -> Iterator[str]

The possible ValueType(s) of values this variable can hold.

Returns

Iterator[str]

is_instance

is_instance() -> bool

Returns True if this variable is an Instance variable.

Returns

bool

is_type

is_type() -> bool

Returns True if this variable is a Type variable.

Returns

bool

is_value

is_value() -> bool

Returns True if this variable is a Value variable.

Returns

bool

Errors

TypeDBDriverException

Package: typedb.common.exception

Supertypes:

  • RuntimeError

Exceptions raised by the driver.

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