# Python gRPC driver

## [](#_connection_header)Connection

### [](#_TypeDBDriver)TypeDBDriver

`class`

**Package**: `typedb.native_driver_wrapper`

Properties   

Name

Type

Description

`thisown`

The membership flag

### [](#_Driver)Driver

`class`

**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` for this connection, providing access to user management methods.

#### [](#_Driver_close_)method `close`

```python
close() -> None
```

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

Returns

`None`

Code examples

```python
driver.close()
```

#### [](#_Driver_is_open_)method `is_open`

```python
is_open() -> bool
```

Checks whether this connection is presently open.

Returns

`bool`

Code examples

```python
driver.is_open()
```

#### [](#_Driver_primary_server_server_routing_ServerRouting_None)method `primary_server`

```python
primary_server(server_routing: ServerRouting | None = None) -> Server | None
```

Returns the primary server for this driver connection.

Input parameters    

Name

Description

Type

Default Value

`server_routing`

The server routing to use for the operation. Auto by default

`ServerRouting | None`

`None`

Returns

`Server | None`

Code examples

```python
driver.primary_server()
driver.primary_server(ServerRouting.Auto())
```

#### [](#_Driver_server_version_server_routing_ServerRouting_None)method `server_version`

```python
server_version(server_routing: ServerRouting | None = None) -> ServerVersion
```

Retrieves the server’s version.

Input parameters    

Name

Description

Type

Default Value

`server_routing`

The server routing to use for the operation. Auto by default

`ServerRouting | None`

`None`

Returns

`ServerVersion`

Code examples

```python
driver.server_version()
driver.server_version(ServerRouting.Auto())
```

#### [](#_Driver_servers_server_routing_ServerRouting_None)method `servers`

```python
servers(server_routing: ServerRouting | None = None) -> Set[Server]
```

Set of servers for this driver connection.

Input parameters    

Name

Description

Type

Default Value

`server_routing`

The server routing to use for the operation. Auto by default

`ServerRouting | None`

`None`

Returns

`Set[Server]`

Code examples

```python
driver.servers()
driver.servers(ServerRouting.Auto())
```

#### [](#_Driver_transaction_database_name_str_transaction_type_TransactionType_options_TransactionOptions_None)method `transaction`

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

Opens a 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

```python
driver.transaction(database, transaction_type, options)
```

### [](#_Credentials)Credentials

`class`

**Package**: `typedb.api.connection.credentials`

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

Examples

```python
credentials = Credentials(username, password)
```

### [](#_DriverOptions)DriverOptions

`class`

**Package**: `typedb.api.connection.driver_options`

TypeDB driver options. `DriverOptions` are used to specify the driver’s connection behavior.

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

Examples

```python
options = DriverOptions(DriverTlsConfig.enabled_with_native_root_ca(), request_timeout_millis=6000)
options.request_timeout_millis = 6000
```

Properties   

Name

Type

Description

`primary_failover_retries`

`int`

Returns the value set for the primary failover retries limit in this `DriverOptions` object. Specifies the number of retries the driver performs to find and reach the cluster primary after a failed request, before giving up. Total attempts per user request = `N + 1`. Each retry either follows the server’s redirect address (fast path) or polls the known replicas with a 2-second sleep between polls (slow path). Set to `0` to disable failover. Defaults to 1.

`request_timeout_millis`

`int`

Returns the request timeout in milliseconds set for this `DriverOptions` object. Specifies the maximum time to wait for a response to a unary RPC request. This applies to operations like database creation, user management, and initial transaction opening. It does NOT apply to operations within transactions (queries, commits).

`tls_config`

`DriverTlsConfig`

Returns the TLS configuration associated with this `DriverOptions`. Specifies the TLS configuration of the connection to TypeDB.

### [](#_DatabaseManager)DatabaseManager

`class`

**Package**: `typedb.api.database.database_manager`

Provides access to all database management methods.

#### [](#_DatabaseManager_all_)method `all`

```python
all() -> List[Database]
```

Retrieves all databases present on the TypeDB server.

Returns

`List[Database]`

Code examples

```python
driver.databases.all()
```

#### [](#_DatabaseManager_contains_name_str)method `contains`

```python
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

```python
driver.databases.contains(name)
```

#### [](#_DatabaseManager_create_name_str)method `create`

```python
create(name: str) -> None
```

Creates 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

```python
driver.databases.create(name)
```

#### [](#_DatabaseManager_get_name_str)method `get`

```python
get(name: str) -> Database
```

Retrieves 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

```python
driver.databases.get(name)
```

#### [](#_DatabaseManager_import_from_file_name_str_schema_str_data_file_path_str)method `import_from_file`

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

Creates 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

```python
driver.databases.import_from_file(name, schema, "data.typedb")
```

Unresolved include directive in modules/ROOT/partials/python/api-reference.adoc - include::3.x@external-typeb-driver::partial$python/connection/Database.adoc\[\]

### [](#_UserManager)UserManager

`class`

**Package**: `typedb.api.user.user_manager`

Provides access to all user management methods.

#### [](#_UserManager_all_)method `all`

```python
all() -> List[User]
```

Retrieves all users which exist on the TypeDB server.

Returns

`List[User]`

Code examples

```python
driver.users.all()
```

#### [](#_UserManager_contains_username_str)method `contains`

```python
contains(username: str) -> bool
```

Checks if a user with the given name exists.

Input parameters    

Name

Description

Type

Default Value

`username`

The username to be checked

`str`

Returns

`bool`

Code examples

```python
driver.users.contains(username)
```

#### [](#_UserManager_create_username_str_password_str)method `create`

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

Creates 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

```python
driver.users.create(username, password)
```

#### [](#_UserManager_get_username_str)method `get`

```python
get(username: str) -> User | None
```

Retrieves 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

```python
driver.users.get(username)
```

#### [](#_UserManager_get_current_)method `get_current`

```python
get_current() -> User | None
```

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

Returns

`User | None`

Code examples

```python
driver.users.get_current()
```

### [](#_User)User

`class`

**Package**: `typedb.api.user.user`

TypeDB user information

Properties   

Name

Type

Description

`name`

`str`

Returns the name of this user.

#### [](#_User_delete_)method `delete`

```python
delete() -> None
```

Deletes this user.

Returns

`None`

Code examples

```python
user.delete()
```

#### [](#_User_update_password_password_str)method `update_password`

```python
update_password(password: str) -> None
```

Updates the password for this user.

Input parameters    

Name

Description

Type

Default Value

`password`

The new password

`str`

Returns

`None`

Code examples

```python
user.update_password("new-password")
```

## [](#_transaction_header)Transaction

### [](#_Transaction)Transaction

`class`

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

#### [](#_Transaction_close_)method `close`

```python
close() -> None
```

Closes the transaction.

Returns

`None`

Code examples

```python
transaction.close()
```

#### [](#_Transaction_commit_)method `commit`

```python
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

```python
transaction.commit()
```

#### [](#_Transaction_is_open_)method `is_open`

```python
is_open() -> bool
```

Checks whether this transaction is open.

Returns

`bool`

Code examples

```python
transaction.is_open()
```

#### [](#_Transaction_on_close_function_Callable)method `on_close`

```python
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

```python
transaction.on_close(function)
```

#### [](#_Transaction_query_query_str_options_QueryOptions_None_given_rows_GivenRows_List_Dict_str_object_Tuple_List_str_List_List_object_None)method `query`

```python
query(query: str, options: QueryOptions | None = None, given_rows: GivenRows | List[Dict[str, object]] | Tuple[List[str], List[List[object]]] | 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`

`given_rows`

Rows given to the query as input. May be a `GivenRows` object, a list of dicts mapping variable names to values, or a `(variables, rows)` tuple. Items in the dicts/rows may be `Concept` instances or primitives supported by `TypeDB.Concept.try_convert_to_value`.

`GivenRows | List[Dict[str, object]] | Tuple[List[str], List[List[object]]] | None`

`None`

Returns

`Promise[QueryAnswer]`

Code examples

```python
transaction.query("define entity person;", options).resolve()
```

```python
query = "given $n: string, $a: integer; insert $p isa person, has name == $n, has age == $a;"
rows = TypeDB.Concept.given_rows(
    ["n", "a"],
    [
        [TypeDB.Concept.new_string("Alice"), TypeDB.Concept.new_integer(28)],  # First row
        [TypeDB.Concept.new_string("Bob"),   TypeDB.Concept.new_integer(26)],  # Second row
    ]
)
transaction.query(query, given_rows=rows).resolve()
```

```python
transaction.query(query, given_rows=[{"n": "Alice", "a": 28}, {"n": "Bob", "a": 26}]).resolve()
```

#### [](#_Transaction_rollback_)method `rollback`

```python
rollback() -> None
```

Rolls back the uncommitted changes made via this transaction.

Returns

`None`

Code examples

```python
transaction.rollback()
```

### [](#_TransactionType)TransactionType

`class`

**Package**: `typedb.api.connection.transaction`

This class is used to specify the type of transaction.

Examples

```python
driver.transaction(database, TransactionType.READ)
```

Enum constants  

Name

Value

`READ`

`0`

`SCHEMA`

`2`

`WRITE`

`1`

#### [](#_TransactionType_is_read_)method `is_read`

```python
is_read() -> bool
```

Returns

`bool`

#### [](#_TransactionType_is_schema_)method `is_schema`

```python
is_schema() -> bool
```

Returns

`bool`

#### [](#_TransactionType_is_write_)method `is_write`

```python
is_write() -> bool
```

Returns

`bool`

### [](#_TransactionOptions)TransactionOptions

`class`

**Package**: `typedb.api.connection.transaction_options`

TypeDB transaction options. `TransactionOptions` object can be used to override the default server behaviour for opened transactions.

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

Examples

```python
transaction_options = TransactionOptions(transaction_timeout_millis=20_000)
transaction_options.schema_lock_acquire_timeout_millis = 50_000
```

Properties   

Name

Type

Description

`schema_lock_acquire_timeout_millis`

`int | None`

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

`transaction_timeout_millis`

`int | None`

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

### [](#_QueryOptions)QueryOptions

`class`

**Package**: `typedb.api.connection.query_options`

TypeDB query options. `QueryOptions` object can be used to override the default server behaviour for executed queries.

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

Examples

```python
query_options = QueryOptions(include_instance_types=True)
query_options.prefetch_size = 10
```

Properties   

Name

Type

Description

`include_instance_types`

`bool | None`

If set, specifies if types should be included in instance structs returned in ConceptRow answers. This option allows reducing the amount of unnecessary data transmitted.

`include_query_structure`

`bool | None`

If set, specifies if types should be included in instance structs returned in ConceptRow answers.

`prefetch_size`

`int | None`

If set, specifies the number of extra query responses sent before the client side has to re-request more responses. Increasing this may increase performance for queries with a huge number of answers, as it can reduce the number of network round-trips at the cost of more resources on the server side. Minimal value: 1.

## [](#_answer_header)Answer

### [](#_QueryAnswer)QueryAnswer

`class`

**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`.

#### [](#_QueryAnswer_as_concept_documents_)method `as_concept_documents`

```python
as_concept_documents() -> ConceptDocumentIterator
```

Casts the query answer to `ConceptDocumentIterator`.

Returns

`ConceptDocumentIterator`

Code examples

```python
query_answer.as_concept_documents()
```

#### [](#_QueryAnswer_as_concept_rows_)method `as_concept_rows`

```python
as_concept_rows() -> ConceptRowIterator
```

Casts the query answer to `ConceptRowIterator`.

Returns

`ConceptRowIterator`

Code examples

```python
query_answer.as_concept_rows()
```

#### [](#_QueryAnswer_as_ok_)method `as_ok`

```python
as_ok() -> OkQueryAnswer
```

Casts the query answer to `OkQueryAnswer`.

Returns

`OkQueryAnswer`

Code examples

```python
query_answer.as_ok()
```

#### [](#_QueryAnswer_is_concept_documents_)method `is_concept_documents`

```python
is_concept_documents() -> bool
```

Checks if the query answer is a `ConceptDocumentIterator`.

Returns

`bool`

Code examples

```python
query_answer.is_concept_documents()
```

#### [](#_QueryAnswer_is_concept_rows_)method `is_concept_rows`

```python
is_concept_rows() -> bool
```

Checks if the query answer is a `ConceptRowIterator`.

Returns

`bool`

Code examples

```python
query_answer.is_concept_rows()
```

#### [](#_QueryAnswer_is_ok_)method `is_ok`

```python
is_ok() -> bool
```

Checks if the query answer is an `Ok`.

Returns

`bool`

Code examples

```python
query_answer.is_ok()
```

### [](#_OkQueryAnswer)OkQueryAnswer

`class`

**Package**: `typedb.api.answer.ok_query_answer`

**Supertypes:**

*   `QueryAnswer`
    

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

#### [](#_OkQueryAnswer_as_ok_)method `as_ok`

```python
as_ok() -> OkQueryAnswer
```

Casts the query answer to `OkQueryAnswer`.

Returns

`OkQueryAnswer`

Code examples

```python
query_answer.as_ok()
```

#### [](#_OkQueryAnswer_is_ok_)method `is_ok`

```python
is_ok() -> bool
```

Checks if the query answer is an `Ok`.

Returns

`bool`

Code examples

```python
query_answer.is_ok()
```

### [](#_ConceptRowIterator)ConceptRowIterator

`class`

**Package**: `typedb.api.answer.concept_row_iterator`

**Supertypes:**

*   `QueryAnswer`
    

Represents an iterator over `ConceptRow`s returned as a server answer.

#### [](#_ConceptRowIterator_as_concept_rows_)method `as_concept_rows`

```python
as_concept_rows() -> ConceptRowIterator
```

Casts the query answer to `ConceptRowIterator`.

Returns

`ConceptRowIterator`

Code examples

```python
query_answer.as_concept_rows()
```

#### [](#_ConceptRowIterator_is_concept_rows_)method `is_concept_rows`

```python
is_concept_rows() -> bool
```

Checks if the query answer is a `ConceptRowIterator`.

Returns

`bool`

Code examples

```python
query_answer.is_concept_rows()
```

### [](#_ConceptRow)ConceptRow

`class`

**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.

#### [](#_ConceptRow_column_names_)method `column_names`

```python
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

```python
concept_row.column_names()
```

#### [](#_ConceptRow_concepts_)method `concepts`

```python
concepts() -> Iterator[Concept]
```

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

Returns

`Iterator[Concept]`

Code examples

```python
concept_row.concepts()
```

#### [](#_ConceptRow_get_column_name_str)method `get`

```python
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

```python
concept_row.get(column_name)
```

#### [](#_ConceptRow_get_index_column_index_int)method `get_index`

```python
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

```python
concept_row.get_index(column_index)
```

#### [](#_ConceptRow_involved_conjunctions_)method `involved_conjunctions`

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

Retrieve the ConjunctionIDs of Conjunctions that answered this row.

Returns

`Iterator['ConjunctionID'] | None`

Code examples

```python
concept_row.involved_conjunctions()
```

#### [](#_ConceptRow_query_structure_)method `query_structure`

```python
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

```python
concept_row.query_structure()
```

### [](#_ConceptDocumentIterator)ConceptDocumentIterator

`class`

**Package**: `typedb.api.answer.concept_document_iterator`

**Supertypes:**

*   `QueryAnswer`
    

Represents an iterator over `ConceptRow`s returned as a server answer.

#### [](#_ConceptDocumentIterator_as_concept_documents_)method `as_concept_documents`

```python
as_concept_documents() -> ConceptDocumentIterator
```

Casts the query answer to `ConceptDocumentIterator`.

Returns

`ConceptDocumentIterator`

Code examples

```python
query_answer.as_concept_documents()
```

#### [](#_ConceptDocumentIterator_is_concept_documents_)method `is_concept_documents`

```python
is_concept_documents() -> bool
```

Checks if the query answer is a `ConceptDocumentIterator`.

Returns

`bool`

Code examples

```python
query_answer.is_concept_documents()
```

### [](#_QueryType)QueryType

`class`

**Package**: `typedb.api.answer.query_type`

Used to specify the type of the executed query.

Examples

```python
concept_row.query_type
```

Enum constants  

Name

Value

`READ`

`0`

`SCHEMA`

`2`

`WRITE`

`1`

#### [](#_QueryType_is_read_)method `is_read`

```python
is_read() -> bool
```

Returns

`bool`

#### [](#_QueryType_is_schema_)method `is_schema`

```python
is_schema() -> bool
```

Returns

`bool`

#### [](#_QueryType_is_write_)method `is_write`

```python
is_write() -> bool
```

Returns

`bool`

### [](#_Promise)Promise

`class`

**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 `resolve`d.

#### [](#_Promise_map_)method `map`

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

Returns

`Promise[T]`

#### [](#_Promise_resolve_)method `resolve`

```python
resolve() -> T
```

Retrieves the result of the Promise.

Returns

`T`

Code examples

```python
promise.resolve()
```

## [](#_concept_header)Concept

### [](#_Concept)Concept

`class`

**Package**: `typedb.api.concept.concept`

#### [](#_Concept_as_attribute_)method `as_attribute`

```python
as_attribute() -> Attribute
```

Casts the concept to `Attribute`.

Returns

`Attribute`

Code examples

```python
concept.as_attribute()
```

#### [](#_Concept_as_attribute_type_)method `as_attribute_type`

```python
as_attribute_type() -> AttributeType
```

Casts the concept to `AttributeType`.

Returns

`AttributeType`

Code examples

```python
concept.as_attribute_type()
```

#### [](#_Concept_as_entity_)method `as_entity`

```python
as_entity() -> Entity
```

Casts the concept to `Entity`.

Returns

`Entity`

Code examples

```python
concept.as_entity()
```

#### [](#_Concept_as_entity_type_)method `as_entity_type`

```python
as_entity_type() -> EntityType
```

Casts the concept to `EntityType`.

Returns

`EntityType`

Code examples

```python
concept.as_entity_type()
```

#### [](#_Concept_as_instance_)method `as_instance`

```python
as_instance() -> Instance
```

Casts the concept to `Instance`.

Returns

`Instance`

Code examples

```python
concept.as_instance()
```

#### [](#_Concept_as_relation_)method `as_relation`

```python
as_relation() -> Relation
```

Casts the concept to `Relation`.

Returns

`Relation`

Code examples

```python
concept.as_relation()
```

#### [](#_Concept_as_relation_type_)method `as_relation_type`

```python
as_relation_type() -> RelationType
```

Casts the concept to `RelationType`.

Returns

`RelationType`

Code examples

```python
concept.as_relation_type()
```

#### [](#_Concept_as_role_type_)method `as_role_type`

```python
as_role_type() -> RoleType
```

Casts the concept to `RoleType`.

Returns

`RoleType`

Code examples

```python
concept.as_role_type()
```

#### [](#_Concept_as_type_)method `as_type`

```python
as_type() -> Type
```

Casts the concept to `Type`.

Returns

`Type`

Code examples

```python
concept.as_type()
```

#### [](#_Concept_as_value_)method `as_value`

```python
as_value() -> Value
```

Casts the concept to `Value`.

Returns

`Value`

Code examples

```python
concept.as_value()
```

#### [](#_Concept_get_label_)method `get_label`

```python
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

```python
concept.get_label()
```

#### [](#_Concept_is_attribute_)method `is_attribute`

```python
is_attribute() -> bool
```

Checks if the concept is an `Attribute`.

Returns

`bool`

Code examples

```python
concept.is_attribute()
```

#### [](#_Concept_is_attribute_type_)method `is_attribute_type`

```python
is_attribute_type() -> bool
```

Checks if the concept is an `AttributeType`.

Returns

`bool`

Code examples

```python
concept.is_attribute_type()
```

#### [](#_Concept_is_boolean_)method `is_boolean`

```python
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

```python
concept.is_boolean()
```

#### [](#_Concept_is_date_)method `is_date`

```python
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

```python
concept.is_date()
```

#### [](#_Concept_is_datetime_)method `is_datetime`

```python
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

```python
concept.is_datetime()
```

#### [](#_Concept_is_datetime_tz_)method `is_datetime_tz`

```python
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

```python
concept.is_datetime_tz()
```

#### [](#_Concept_is_decimal_)method `is_decimal`

```python
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

```python
concept.is_decimal()
```

#### [](#_Concept_is_double_)method `is_double`

```python
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

```python
concept.is_double()
```

#### [](#_Concept_is_duration_)method `is_duration`

```python
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

```python
concept.is_duration()
```

#### [](#_Concept_is_entity_)method `is_entity`

```python
is_entity() -> bool
```

Checks if the concept is an `Entity`.

Returns

`bool`

Code examples

```python
concept.is_entity()
```

#### [](#_Concept_is_entity_type_)method `is_entity_type`

```python
is_entity_type() -> bool
```

Checks if the concept is an `EntityType`.

Returns

`bool`

Code examples

```python
concept.is_entity_type()
```

#### [](#_Concept_is_instance_)method `is_instance`

```python
is_instance() -> bool
```

Checks if the concept is a `Instance`.

Returns

`bool`

Code examples

```python
concept.is_instance()
```

#### [](#_Concept_is_integer_)method `is_integer`

```python
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

```python
concept.is_integer()
```

#### [](#_Concept_is_relation_)method `is_relation`

```python
is_relation() -> bool
```

Checks if the concept is a `Relation`.

Returns

`bool`

Code examples

```python
concept.is_relation()
```

#### [](#_Concept_is_relation_type_)method `is_relation_type`

```python
is_relation_type() -> bool
```

Checks if the concept is a `RelationType`.

Returns

`bool`

Code examples

```python
concept.is_relation_type()
```

#### [](#_Concept_is_role_type_)method `is_role_type`

```python
is_role_type() -> bool
```

Checks if the concept is a `RoleType`.

Returns

`bool`

Code examples

```python
concept.is_role_type()
```

#### [](#_Concept_is_string_)method `is_string`

```python
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

```python
concept.is_string()
```

#### [](#_Concept_is_struct_)method `is_struct`

```python
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

```python
concept.is_struct()
```

#### [](#_Concept_is_type_)method `is_type`

```python
is_type() -> bool
```

Checks if the concept is a `Type`.

Returns

`bool`

Code examples

```python
concept.is_type()
```

#### [](#_Concept_is_value_)method `is_value`

```python
is_value() -> bool
```

Checks if the concept is a `Value`.

Returns

`bool`

Code examples

```python
concept.is_value()
```

#### [](#_Concept_try_get_boolean_)method `try_get_boolean`

```python
try_get_boolean() -> bool | None
```

Returns a `boolean` value of this `Concept`. If it’s not a `Value` or it has another type, returns `None`.

Returns

`bool | None`

Code examples

```python
value.try_get_boolean()
```

#### [](#_Concept_try_get_date_)method `try_get_date`

```python
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, returns `None`.

Returns

`date | None`

Code examples

```python
value.try_get_date()
```

#### [](#_Concept_try_get_datetime_)method `try_get_datetime`

```python
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, returns `None`.

Returns

`Datetime | None`

Code examples

```python
value.try_get_datetime()
```

#### [](#_Concept_try_get_datetime_tz_)method `try_get_datetime_tz`

```python
try_get_datetime_tz() -> Datetime | None
```

Returns a `datetime_tz` value of this `Concept`. If it’s not a `Value` or it has another type, returns `None`.

Returns

`Datetime | None`

Code examples

```python
value.try_get_datetime_tz()
```

#### [](#_Concept_try_get_decimal_)method `try_get_decimal`

```python
try_get_decimal() -> Decimal | None
```

Returns a `decimal` value of this `Concept`. If it’s not a `Value` or it has another type, returns `None`.

Returns

`Decimal | None`

Code examples

```python
value.try_get_decimal()
```

#### [](#_Concept_try_get_double_)method `try_get_double`

```python
try_get_double() -> float | None
```

Returns a `double` value of this `Concept`. If it’s not a `Value` or it has another type, returns `None`.

Returns

`float | None`

Code examples

```python
value.try_get_double()
```

#### [](#_Concept_try_get_duration_)method `try_get_duration`

```python
try_get_duration() -> Duration | None
```

Returns a `duration` value of this `Concept`. If it’s not a `Value` or it has another type, returns `None`.

Returns

`Duration | None`

Code examples

```python
value.try_get_duration()
```

#### [](#_Concept_try_get_iid_)method `try_get_iid`

```python
try_get_iid() -> str | None
```

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

Returns

`str | None`

Code examples

```python
concept.try_get_iid()
```

#### [](#_Concept_try_get_integer_)method `try_get_integer`

```python
try_get_integer() -> int | None
```

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

Returns

`int | None`

Code examples

```python
value.try_get_integer()
```

#### [](#_Concept_try_get_label_)method `try_get_label`

```python
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

```python
concept.try_get_label()
```

#### [](#_Concept_try_get_string_)method `try_get_string`

```python
try_get_string() -> str | None
```

Returns a `string` value of this `Concept`. If it’s not a `Value` or it has another type, returns `None`.

Returns

`str | None`

Code examples

```python
value.try_get_string()
```

#### [](#_Concept_try_get_struct_)method `try_get_struct`

```python
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, returns `None`.

Returns

`STRUCT | None`

Code examples

```python
value.try_get_struct()
```

#### [](#_Concept_try_get_value_)method `try_get_value`

```python
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

```python
concept.try_get_value()
```

#### [](#_Concept_try_get_value_type_)method `try_get_value_type`

```python
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

```python
concept.try_get_value_type()
```

### [](#_Kind)Kind

`class`

**Package**: `typedb.common.enums`

Enum constants  

Name

Value

`Attribute`

`1`

`Entity`

`0`

`Relation`

`2`

`Role`

`3`

## [](#_schema_header)Schema

### [](#_Type)Type

`class`

**Package**: `typedb.api.concept.type.type`

**Supertypes:**

*   `Concept`
    

#### [](#_Type_is_type_)method `is_type`

```python
is_type() -> bool
```

Checks if the concept is a `Type`.

Returns

`bool`

Code examples

```python
type_.is_type()
```

### [](#_EntityType)EntityType

`class`

**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.

#### [](#_EntityType_as_entity_type_)method `as_entity_type`

```python
as_entity_type() -> EntityType
```

Casts the concept to `EntityType`.

Returns

`EntityType`

Code examples

```python
entity_type.as_entity_type()
```

#### [](#_EntityType_is_entity_type_)method `is_entity_type`

```python
is_entity_type() -> bool
```

Checks if the concept is an `EntityType`.

Returns

`bool`

Code examples

```python
entity_type.is_entity_type()
```

### [](#_RelationType)RelationType

`class`

**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.

#### [](#_RelationType_as_relation_type_)method `as_relation_type`

```python
as_relation_type() -> RelationType
```

Casts the concept to `RelationType`.

Returns

`RelationType`

Code examples

```python
relation_type.as_relation_type()
```

#### [](#_RelationType_is_relation_type_)method `is_relation_type`

```python
is_relation_type() -> bool
```

Checks if the concept is a `RelationType`.

Returns

`bool`

Code examples

```python
relation_type.is_relation_type()
```

### [](#_RoleType)RoleType

`class`

**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.

#### [](#_RoleType_as_role_type_)method `as_role_type`

```python
as_role_type() -> RoleType
```

Casts the concept to `RoleType`.

Returns

`RoleType`

Code examples

```python
role_type.as_role_type()
```

#### [](#_RoleType_is_role_type_)method `is_role_type`

```python
is_role_type() -> bool
```

Checks if the concept is a `RoleType`.

Returns

`bool`

Code examples

```python
role_type.is_role_type()
```

### [](#_AttributeType)AttributeType

`class`

**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.

#### [](#_AttributeType_as_attribute_type_)method `as_attribute_type`

```python
as_attribute_type() -> AttributeType
```

Casts the concept to `AttributeType`.

Returns

`AttributeType`

Code examples

```python
attribute.as_attribute_type()
```

#### [](#_AttributeType_is_attribute_type_)method `is_attribute_type`

```python
is_attribute_type() -> bool
```

Checks if the concept is an `AttributeType`.

Returns

`bool`

Code examples

```python
attribute.is_attribute_type()
```

## [](#_data_header)Data

### [](#_Instance)Instance

`class`

**Package**: `typedb.api.concept.instance.instance`

**Supertypes:**

*   `Concept`
    

#### [](#_Instance_as_instance_)method `as_instance`

```python
as_instance() -> Instance
```

Casts the concept to `Instance`.

Returns

`Instance`

Code examples

```python
instance.as_instance()
```

#### [](#_Instance_get_type_)method `get_type`

```python
get_type() -> Type
```

Retrieves the type which this `Instance` belongs to.

Returns

`Type`

Code examples

```python
instance.get_type()
```

#### [](#_Instance_is_instance_)method `is_instance`

```python
is_instance() -> bool
```

Checks if the concept is a `Instance`.

Returns

`bool`

Code examples

```python
instance.is_instance()
```

### [](#_Entity)Entity

`class`

**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.

#### [](#_Entity_as_entity_)method `as_entity`

```python
as_entity() -> Entity
```

Casts the concept to `Entity`.

Returns

`Entity`

Code examples

```python
entity.as_entity()
```

#### [](#_Entity_get_iid_)method `get_iid`

```python
get_iid() -> str
```

Retrieves the unique id of the `Entity`.

Returns

`str`

Code examples

```python
entity.get_iid()
```

#### [](#_Entity_get_type_)method `get_type`

```python
get_type() -> EntityType
```

Retrieves the type which this `Entity` belongs to.

Returns

`EntityType`

Code examples

```python
entity.get_type()
```

#### [](#_Entity_is_entity_)method `is_entity`

```python
is_entity() -> bool
```

Checks if the concept is an `Entity`.

Returns

`bool`

Code examples

```python
entity.is_entity()
```

### [](#_Relation)Relation

`class`

**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.

#### [](#_Relation_as_relation_)method `as_relation`

```python
as_relation() -> Relation
```

Casts the concept to `Relation`.

Returns

`Relation`

Code examples

```python
relation.as_relation()
```

#### [](#_Relation_get_iid_)method `get_iid`

```python
get_iid() -> str
```

Retrieves the unique id of the `Relation`.

Returns

`str`

Code examples

```python
relation.get_iid()
```

#### [](#_Relation_get_type_)method `get_type`

```python
get_type() -> RelationType
```

Retrieves the type which this `Relation` belongs to.

Returns

`RelationType`

Code examples

```python
relation.get_type()
```

#### [](#_Relation_is_relation_)method `is_relation`

```python
is_relation() -> bool
```

Checks if the concept is a `Relation`.

Returns

`bool`

Code examples

```python
relation.is_relation()
```

### [](#_Attribute)Attribute

`class`

**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.

#### [](#_Attribute_as_attribute_)method `as_attribute`

```python
as_attribute() -> Attribute
```

Casts the concept to `Attribute`.

Returns

`Attribute`

Code examples

```python
attribute.as_attribute()
```

#### [](#_Attribute_get_boolean_)method `get_boolean`

```python
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

```python
attribute.get_boolean()
```

#### [](#_Attribute_get_date_)method `get_date`

```python
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

```python
attribute.get_date()
```

#### [](#_Attribute_get_datetime_)method `get_datetime`

```python
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

```python
attribute.get_datetime()
```

#### [](#_Attribute_get_datetime_tz_)method `get_datetime_tz`

```python
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

```python
attribute.get_datetime_tz()
```

#### [](#_Attribute_get_decimal_)method `get_decimal`

```python
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

```python
attribute.get_decimal()
```

#### [](#_Attribute_get_double_)method `get_double`

```python
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

```python
attribute.get_double()
```

#### [](#_Attribute_get_duration_)method `get_duration`

```python
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

```python
attribute.get_duration()
```

#### [](#_Attribute_get_integer_)method `get_integer`

```python
get_integer() -> int
```

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

Returns

`int`

Code examples

```python
attribute.get_integer()
```

#### [](#_Attribute_get_string_)method `get_string`

```python
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

```python
attribute.get_string()
```

#### [](#_Attribute_get_struct_)method `get_struct`

```python
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

```python
attribute.get_struct()
```

#### [](#_Attribute_get_type_)method `get_type`

```python
get_type() -> AttributeType
```

Retrieves the type which this `Attribute` belongs to.

Returns

`AttributeType`

Code examples

```python
attribute.get_type()
```

#### [](#_Attribute_get_value_)method `get_value`

```python
get_value() -> Concept.VALUE
```

Retrieves the value which the `Attribute` instance holds.

Returns

`Concept.VALUE`

Code examples

```python
attribute.get_value()
```

#### [](#_Attribute_get_value_type_)method `get_value_type`

```python
get_value_type() -> str
```

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

Returns

`str`

Code examples

```python
attribute.get_value_type()
```

#### [](#_Attribute_is_attribute_)method `is_attribute`

```python
is_attribute() -> bool
```

Checks if the concept is an `Attribute`.

Returns

`bool`

Code examples

```python
attribute.is_attribute()
```

### [](#_Value)Value

`class`

**Package**: `typedb.api.concept.value.value`

**Supertypes:**

*   `Concept`
    

#### [](#_Value_as_value_)method `as_value`

```python
as_value() -> Value
```

Casts the concept to `Value`.

Returns

`Value`

Code examples

```python
value.as_value()
```

#### [](#_Value_get_)method `get`

```python
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

```python
value.get()
```

#### [](#_Value_get_boolean_)method `get_boolean`

```python
get_boolean() -> bool
```

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

Returns

`bool`

Code examples

```python
value.get_boolean()
```

#### [](#_Value_get_date_)method `get_date`

```python
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

```python
value.get_date()
```

#### [](#_Value_get_datetime_)method `get_datetime`

```python
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

```python
value.get_datetime()
```

#### [](#_Value_get_datetime_tz_)method `get_datetime_tz`

```python
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

```python
value.get_datetime_tz()
```

#### [](#_Value_get_decimal_)method `get_decimal`

```python
get_decimal() -> Decimal
```

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

Returns

`Decimal`

Code examples

```python
value.get_decimal()
```

#### [](#_Value_get_double_)method `get_double`

```python
get_double() -> float
```

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

Returns

`float`

Code examples

```python
value.get_double()
```

#### [](#_Value_get_duration_)method `get_duration`

```python
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

```python
value.get_duration()
```

#### [](#_Value_get_integer_)method `get_integer`

```python
get_integer() -> int
```

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

Returns

`int`

Code examples

```python
value.get_integer()
```

#### [](#_Value_get_string_)method `get_string`

```python
get_string() -> str
```

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

Returns

`str`

Code examples

```python
value.get_string()
```

#### [](#_Value_get_struct_)method `get_struct`

```python
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

```python
value.get_struct()
```

#### [](#_Value_get_type_)method `get_type`

```python
get_type() -> str
```

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

Returns

`str`

Code examples

```python
value.get_type()
```

#### [](#_Value_is_value_)method `is_value`

```python
is_value() -> bool
```

Checks if the concept is a `Value`.

Returns

`bool`

Code examples

```python
value.is_value()
```

## [](#_value_header)Value

### [](#_Datetime)Datetime

`class`

**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`

Returns the date part.

`datetime_without_nanos`

`datetime`

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

`day`

`int`

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

`hour`

`int`

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

`microsecond`

`int`

Returns the rounded number of microseconds.

`minute`

`int`

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

`month`

`int`

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

`nanos`

`int`

Returns the nanoseconds part.

`offset_seconds`

`str | None`

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

`second`

`int`

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

`total_seconds`

`float`

Returns 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`

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

`tzinfo`

`tzinfo`

Returns timezone info.

`weekday`

`int`

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

`year`

`int`

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

#### [](#_Datetime_fromstring_datetime_str_str_tz_name_str_None_offset_seconds_int_None_datetime_fmt_str)method `fromstring`

```python
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

```python
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")
```

#### [](#_Datetime_fromtimestamp_timestamp_seconds_int_subsec_nanos_int_tz_name_str_None_offset_seconds_int_None)method `fromtimestamp`

```python
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

\`\`

#### [](#_Datetime_isoformat_)method `isoformat`

```python
isoformat() -> str
```

Returns the time formatted according to ISO.

Returns

`str`

#### [](#_Datetime_offset_seconds_fromstring_offset_str)method `offset_seconds_fromstring`

```python
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

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

#### [](#_Datetime_utcfromstring_datetime_str_str_tz_name_str_None_offset_seconds_int_None_datetime_fmt_str)method `utcfromstring`

```python
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

```python
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")
```

#### [](#_Datetime_utcfromtimestamp_timestamp_seconds_int_subsec_nanos_int_tz_name_str_None_offset_seconds_int_None)method `utcfromtimestamp`

```python
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)Duration

`class`

**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

#### [](#_Duration_fromstring_duration_str_str)method `fromstring`

```python
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

```python
Duration.fromstring("P1Y10M7DT15H44M5.00394892S")
Duration.fromstring("P55W")
```

## [](#_analyze_header)Analyze

### [](#_AnalyzedQuery)AnalyzedQuery

`class`

**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.

#### [](#_AnalyzedQuery_fetch_)method `fetch`

```python
fetch() -> 'Fetch' | None
```

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

Returns

`'Fetch' | None`

#### [](#_AnalyzedQuery_given_)method `given`

```python
given() -> 'Given' | None
```

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

Returns

`'Given' | None`

#### [](#_AnalyzedQuery_pipeline_)method `pipeline`

```python
pipeline() -> Pipeline
```

A representation of the query as a Pipeline.

Returns

`Pipeline`

#### [](#_AnalyzedQuery_preamble_)method `preamble`

```python
preamble() -> Iterator['Function']
```

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

Returns

`Iterator['Function']`

### [](#_Comparator)Comparator

`class`

**Package**: `typedb.common.enums`

Enum constants  

Name

Value

`Contains`

`7`

`Equal`

`0`

`Greater`

`4`

`GreaterOrEqual`

`5`

`LessOrEqual`

`3`

`LessThan`

`2`

`Like`

`6`

`NotEqual`

`1`

#### [](#_Comparator_symbol_)method `symbol`

```python
symbol()
```

Returns

\`\`

### [](#_Conjunction)Conjunction

`class`

**Package**: `typedb.api.analyze.conjunction`

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

#### [](#_Conjunction_annotated_variables_)method `annotated_variables`

```python
annotated_variables() -> Iterator['Variable']
```

The variables that have annotations in this conjunction.

Returns

`Iterator['Variable']`

#### [](#_Conjunction_constraints_)method `constraints`

```python
constraints() -> Iterator['Constraint']
```

The Constraint(s) in the conjunction.

Returns

`Iterator['Constraint']`

#### [](#_Conjunction_variable_annotations_variable_Variable)method `variable_annotations`

```python
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)Constraint

`class`

**Package**: `typedb.api.analyze.constraint`

A representation of a TypeQL constraint.

#### [](#_Constraint_as_comparison_)method `as_comparison`

```python
as_comparison() -> Comparison
```

Returns

`Comparison`

#### [](#_Constraint_as_expression_)method `as_expression`

```python
as_expression() -> Expression
```

Returns

`Expression`

#### [](#_Constraint_as_function_call_)method `as_function_call`

```python
as_function_call() -> FunctionCall
```

Returns

`FunctionCall`

#### [](#_Constraint_as_has_)method `as_has`

```python
as_has() -> Has
```

Returns

`Has`

#### [](#_Constraint_as_iid_)method `as_iid`

```python
as_iid() -> Iid
```

Returns

`Iid`

#### [](#_Constraint_as_is_)method `as_is`

```python
as_is() -> Is
```

Returns

`Is`

#### [](#_Constraint_as_isa_)method `as_isa`

```python
as_isa() -> Isa
```

Returns

`Isa`

#### [](#_Constraint_as_kind_)method `as_kind`

```python
as_kind() -> Kind
```

Returns

`Kind`

#### [](#_Constraint_as_label_)method `as_label`

```python
as_label() -> Label
```

Returns

`Label`

#### [](#_Constraint_as_links_)method `as_links`

```python
as_links() -> Links
```

Returns

`Links`

#### [](#_Constraint_as_not_)method `as_not`

```python
as_not() -> Not
```

Returns

`Not`

#### [](#_Constraint_as_or_)method `as_or`

```python
as_or() -> Or
```

Returns

`Or`

#### [](#_Constraint_as_owns_)method `as_owns`

```python
as_owns() -> Owns
```

Returns

`Owns`

#### [](#_Constraint_as_plays_)method `as_plays`

```python
as_plays() -> Plays
```

Returns

`Plays`

#### [](#_Constraint_as_relates_)method `as_relates`

```python
as_relates() -> Relates
```

Returns

`Relates`

#### [](#_Constraint_as_sub_)method `as_sub`

```python
as_sub() -> Sub
```

Returns

`Sub`

#### [](#_Constraint_as_try_)method `as_try`

```python
as_try() -> Try
```

Returns

`Try`

#### [](#_Constraint_as_value_)method `as_value`

```python
as_value() -> Value
```

Returns

`Value`

#### [](#_Constraint_is_comparison_)method `is_comparison`

```python
is_comparison() -> bool
```

Returns

`bool`

#### [](#_Constraint_is_expression_)method `is_expression`

```python
is_expression() -> bool
```

Returns

`bool`

#### [](#_Constraint_is_function_call_)method `is_function_call`

```python
is_function_call() -> bool
```

Returns

`bool`

#### [](#_Constraint_is_has_)method `is_has`

```python
is_has() -> bool
```

Returns

`bool`

#### [](#_Constraint_is_iid_)method `is_iid`

```python
is_iid() -> bool
```

Returns

`bool`

#### [](#_Constraint_is_is_)method `is_is`

```python
is_is() -> bool
```

Returns

`bool`

#### [](#_Constraint_is_isa_)method `is_isa`

```python
is_isa() -> bool
```

Returns

`bool`

#### [](#_Constraint_is_kind_of_)method `is_kind_of`

```python
is_kind_of() -> bool
```

Returns

`bool`

#### [](#_Constraint_is_label_)method `is_label`

```python
is_label() -> bool
```

Returns

`bool`

#### [](#_Constraint_is_links_)method `is_links`

```python
is_links() -> bool
```

Returns

`bool`

#### [](#_Constraint_is_not_)method `is_not`

```python
is_not() -> bool
```

Returns

`bool`

#### [](#_Constraint_is_or_)method `is_or`

```python
is_or() -> bool
```

Returns

`bool`

#### [](#_Constraint_is_owns_)method `is_owns`

```python
is_owns() -> bool
```

Returns

`bool`

#### [](#_Constraint_is_plays_)method `is_plays`

```python
is_plays() -> bool
```

Returns

`bool`

#### [](#_Constraint_is_relates_)method `is_relates`

```python
is_relates() -> bool
```

Returns

`bool`

#### [](#_Constraint_is_sub_)method `is_sub`

```python
is_sub() -> bool
```

Returns

`bool`

#### [](#_Constraint_is_try_)method `is_try`

```python
is_try() -> bool
```

Returns

`bool`

#### [](#_Constraint_is_value_)method `is_value`

```python
is_value() -> bool
```

Returns

`bool`

#### [](#_Constraint_span_)method `span`

```python
span() -> Span
```

Gets the span of this constraint in the source query.

Returns

`Span`

### [](#_ConstraintExactness)ConstraintExactness

`class`

**Package**: `typedb.common.enums`

Enum constants  

Name

Value

`Exact`

`0`

`Subtypes`

`1`

### [](#_ConstraintVertex)ConstraintVertex

`class`

**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.

#### [](#_ConstraintVertex_as_label_)method `as_label`

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

Down-casts this vertex to a type label.

Returns

`typedb.api.concept.type.type.Type`

#### [](#_ConstraintVertex_as_named_role_)method `as_named_role`

```python
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`

#### [](#_ConstraintVertex_as_value_)method `as_value`

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

Down-casts this vertex to a value.

Returns

`typedb.api.concept.value.value.Value`

#### [](#_ConstraintVertex_as_variable_)method `as_variable`

```python
as_variable() -> Variable
```

Down-casts this vertex to a variable.

Returns

`Variable`

#### [](#_ConstraintVertex_is_label_)method `is_label`

```python
is_label() -> bool
```

Checks if this vertex is a label.

Returns

`bool`

#### [](#_ConstraintVertex_is_named_role_)method `is_named_role`

```python
is_named_role() -> bool
```

Checks if this vertex is a named role.

Returns

`bool`

#### [](#_ConstraintVertex_is_value_)method `is_value`

```python
is_value() -> bool
```

Checks if this vertex is a value.

Returns

`bool`

#### [](#_ConstraintVertex_is_variable_)method `is_variable`

```python
is_variable() -> bool
```

Checks if this vertex is a variable.

Returns

`bool`

### [](#_Comparison)Comparison

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

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

#### [](#_Comparison_comparator_)method `comparator`

```python
comparator() -> Comparator
```

Returns

`Comparator`

#### [](#_Comparison_lhs_)method `lhs`

```python
lhs() -> ConstraintVertex
```

Returns

`ConstraintVertex`

#### [](#_Comparison_rhs_)method `rhs`

```python
rhs() -> ConstraintVertex
```

Returns

`ConstraintVertex`

### [](#_Expression)Expression

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

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

#### [](#_Expression_arguments_)method `arguments`

```python
arguments() -> Iterator['ConstraintVertex']
```

Returns

`Iterator['ConstraintVertex']`

#### [](#_Expression_assigned_)method `assigned`

```python
assigned() -> ConstraintVertex
```

Returns

`ConstraintVertex`

#### [](#_Expression_text_)method `text`

```python
text() -> str
```

Returns

`str`

### [](#_Has)Has

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

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

#### [](#_Has_attribute_)method `attribute`

```python
attribute() -> ConstraintVertex
```

Returns

`ConstraintVertex`

#### [](#_Has_exactness_)method `exactness`

```python
exactness() -> ConstraintExactness
```

Returns

`ConstraintExactness`

#### [](#_Has_owner_)method `owner`

```python
owner() -> ConstraintVertex
```

Returns

`ConstraintVertex`

### [](#_FunctionCall)FunctionCall

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

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

#### [](#_FunctionCall_arguments_)method `arguments`

```python
arguments() -> Iterator['ConstraintVertex']
```

Returns

`Iterator['ConstraintVertex']`

#### [](#_FunctionCall_assigned_)method `assigned`

```python
assigned() -> Iterator['ConstraintVertex']
```

Returns

`Iterator['ConstraintVertex']`

#### [](#_FunctionCall_name_)method `name`

```python
name() -> str
```

Returns

`str`

### [](#_Iid)Iid

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

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

#### [](#_Iid_iid_)method `iid`

```python
iid() -> str
```

Returns

`str`

#### [](#_Iid_variable_)method `variable`

```python
variable() -> ConstraintVertex
```

Returns

`ConstraintVertex`

### [](#_Is)Is

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

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

#### [](#_Is_lhs_)method `lhs`

```python
lhs() -> ConstraintVertex
```

Returns

`ConstraintVertex`

#### [](#_Is_rhs_)method `rhs`

```python
rhs() -> ConstraintVertex
```

Returns

`ConstraintVertex`

### [](#_Isa)Isa

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

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

#### [](#_Isa_exactness_)method `exactness`

```python
exactness() -> ConstraintExactness
```

Returns

`ConstraintExactness`

#### [](#_Isa_instance_)method `instance`

```python
instance() -> ConstraintVertex
```

Returns

`ConstraintVertex`

#### [](#_Isa_type_)method `type`

```python
type() -> ConstraintVertex
```

Returns

`ConstraintVertex`

### [](#_Kind)Kind

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

Represents a kind constraint: <kind> <type>

#### [](#_Kind_kind_)method `kind`

```python
kind() -> typedb.common.enums.Kind
```

Returns

`typedb.common.enums.Kind`

#### [](#_Kind_type_)method `type`

```python
type() -> ConstraintVertex
```

Returns

`ConstraintVertex`

### [](#_Label)Label

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

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

#### [](#_Label_label_)method `label`

```python
label() -> str
```

Returns

`str`

#### [](#_Label_variable_)method `variable`

```python
variable() -> ConstraintVertex
```

Returns

`ConstraintVertex`

### [](#_Links)Links

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

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

#### [](#_Links_exactness_)method `exactness`

```python
exactness() -> ConstraintExactness
```

Returns

`ConstraintExactness`

#### [](#_Links_player_)method `player`

```python
player() -> ConstraintVertex
```

Returns

`ConstraintVertex`

#### [](#_Links_relation_)method `relation`

```python
relation() -> ConstraintVertex
```

Returns

`ConstraintVertex`

#### [](#_Links_role_)method `role`

```python
role() -> ConstraintVertex
```

Returns

`ConstraintVertex`

### [](#_Not)Not

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

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

#### [](#_Not_conjunction_)method `conjunction`

```python
conjunction() -> ConjunctionID
```

Index into Pipeline.conjunctions

Returns

`ConjunctionID`

### [](#_Plays)Plays

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

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

#### [](#_Plays_exactness_)method `exactness`

```python
exactness() -> ConstraintExactness
```

Returns

`ConstraintExactness`

#### [](#_Plays_player_)method `player`

```python
player() -> ConstraintVertex
```

Returns

`ConstraintVertex`

#### [](#_Plays_role_)method `role`

```python
role() -> ConstraintVertex
```

Returns

`ConstraintVertex`

### [](#_Relates)Relates

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

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

#### [](#_Relates_exactness_)method `exactness`

```python
exactness() -> ConstraintExactness
```

Returns

`ConstraintExactness`

#### [](#_Relates_relation_)method `relation`

```python
relation() -> ConstraintVertex
```

Returns

`ConstraintVertex`

#### [](#_Relates_role_)method `role`

```python
role() -> ConstraintVertex
```

Returns

`ConstraintVertex`

### [](#_Or)Or

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

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

#### [](#_Or_branches_)method `branches`

```python
branches() -> Iterator['ConjunctionID']
```

Index into Pipeline.conjunctions

Returns

`Iterator['ConjunctionID']`

### [](#_Owns)Owns

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

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

#### [](#_Owns_attribute_)method `attribute`

```python
attribute() -> ConstraintVertex
```

Returns

`ConstraintVertex`

#### [](#_Owns_exactness_)method `exactness`

```python
exactness() -> ConstraintExactness
```

Returns

`ConstraintExactness`

#### [](#_Owns_owner_)method `owner`

```python
owner() -> ConstraintVertex
```

Returns

`ConstraintVertex`

### [](#_Sub)Sub

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

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

#### [](#_Sub_exactness_)method `exactness`

```python
exactness() -> ConstraintExactness
```

Returns

`ConstraintExactness`

#### [](#_Sub_subtype_)method `subtype`

```python
subtype() -> ConstraintVertex
```

Returns

`ConstraintVertex`

#### [](#_Sub_supertype_)method `supertype`

```python
supertype() -> ConstraintVertex
```

Returns

`ConstraintVertex`

### [](#_Try)Try

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

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

#### [](#_Try_conjunction_)method `conjunction`

```python
conjunction() -> ConjunctionID
```

Index into Pipeline.conjunctions

Returns

`ConjunctionID`

### [](#_Value)Value

`class`

**Package**: `typedb.api.analyze.constraint`

**Supertypes:**

*   `Constraint`
    

Represents a value constraint: <attribute\_type> value <value\_type>

#### [](#_Value_attribute_type_)method `attribute_type`

```python
attribute_type() -> ConstraintVertex
```

Returns

`ConstraintVertex`

#### [](#_Value_value_type_)method `value_type`

```python
value_type() -> str
```

Returns

`str`

### [](#_Fetch)Fetch

`class`

**Package**: `typedb.api.analyze.fetch`

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

#### [](#_Fetch_as_leaf_)method `as_leaf`

```python
as_leaf() -> FetchLeaf
```

Down-casts this Fetch as a FetchLeaf variant.

Returns

`FetchLeaf`

#### [](#_Fetch_as_list_)method `as_list`

```python
as_list() -> FetchList
```

Down-casts this Fetch as a FetchList variant.

Returns

`FetchList`

#### [](#_Fetch_as_object_)method `as_object`

```python
as_object() -> FetchObject
```

Down-casts this Fetch as a FetchObject variant.

Returns

`FetchObject`

#### [](#_Fetch_is_leaf_)method `is_leaf`

```python
is_leaf() -> bool
```

Returns

`bool`

#### [](#_Fetch_is_list_)method `is_list`

```python
is_list() -> bool
```

Returns

`bool`

#### [](#_Fetch_is_object_)method `is_object`

```python
is_object() -> bool
```

Returns

`bool`

### [](#_FetchLeaf)FetchLeaf

`class`

**Package**: `typedb.api.analyze.fetch`

**Supertypes:**

*   `Fetch`
    

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

#### [](#_FetchLeaf_annotations_)method `annotations`

```python
annotations() -> Iterator[str]
```

The possible ValueType(s) as strings.

Returns

`Iterator[str]`

### [](#_FetchList)FetchList

`class`

**Package**: `typedb.api.analyze.fetch`

**Supertypes:**

*   `Fetch`
    

A list of Fetch documents.

#### [](#_FetchList_element_)method `element`

```python
element() -> Fetch
```

The element type of the list.

Returns

`Fetch`

### [](#_FetchObject)FetchObject

`class`

**Package**: `typedb.api.analyze.fetch`

**Supertypes:**

*   `Fetch`
    

A mapping of string keys to Fetch documents.

#### [](#_FetchObject_get_)method `get`

```python
get(key: str) -> Fetch
```

The Fetch object for the given key.

Returns

`Fetch`

#### [](#_FetchObject_keys_)method `keys`

```python
keys() -> Iterator[str]
```

The available keys of this Fetch document.

Returns

`Iterator[str]`

### [](#_Function)Function

`class`

**Package**: `typedb.api.analyze.function`

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

#### [](#_Function_argument_annotations_)method `argument_annotations`

```python
argument_annotations() -> Iterator['VariableAnnotations']
```

Gets the type annotations for each argument of the function.

Returns

`Iterator['VariableAnnotations']`

#### [](#_Function_argument_variables_)method `argument_variables`

```python
argument_variables() -> Iterator['Variable']
```

Gets the variables which are the arguments of the function.

Returns

`Iterator['Variable']`

#### [](#_Function_body_)method `body`

```python
body() -> Pipeline
```

Gets the pipeline which forms the body of the function.

Returns

`Pipeline`

#### [](#_Function_return_annotations_)method `return_annotations`

```python
return_annotations() -> Iterator['VariableAnnotations']
```

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

Returns

`Iterator['VariableAnnotations']`

#### [](#_Function_return_operation_)method `return_operation`

```python
return_operation() -> ReturnOperation
```

Gets the return operation of the function.

Returns

`ReturnOperation`

### [](#_NamedRole)NamedRole

`class`

**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

#### [](#_NamedRole_name_)method `name`

```python
name() -> str
```

The unscoped role name specified in the query.

Returns

`str`

#### [](#_NamedRole_variable_)method `variable`

```python
variable() -> Variable
```

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

Returns

`Variable`

### [](#_Pipeline)Pipeline

`class`

**Package**: `typedb.api.analyze.pipeline`

A representation of a query pipeline.

#### [](#_Pipeline_conjunction_conjunction_id_ConjunctionID)method `conjunction`

```python
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`

#### [](#_Pipeline_get_variable_name_variable_Variable)method `get_variable_name`

```python
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`

#### [](#_Pipeline_stages_)method `stages`

```python
stages() -> Iterator['PipelineStage']
```

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

Returns

`Iterator['PipelineStage']`

### [](#_PipelineStage)PipelineStage

`class`

**Package**: `typedb.api.analyze.pipeline_stage`

Representation of a stage in a Pipeline.

#### [](#_PipelineStage_as_delete_)method `as_delete`

```python
as_delete() -> DeleteStage
```

Returns

`DeleteStage`

#### [](#_PipelineStage_as_distinct_)method `as_distinct`

```python
as_distinct() -> DistinctStage
```

Returns

`DistinctStage`

#### [](#_PipelineStage_as_insert_)method `as_insert`

```python
as_insert() -> InsertStage
```

Returns

`InsertStage`

#### [](#_PipelineStage_as_limit_)method `as_limit`

```python
as_limit() -> LimitStage
```

Returns

`LimitStage`

#### [](#_PipelineStage_as_match_)method `as_match`

```python
as_match() -> MatchStage
```

Returns

`MatchStage`

#### [](#_PipelineStage_as_offset_)method `as_offset`

```python
as_offset() -> OffsetStage
```

Returns

`OffsetStage`

#### [](#_PipelineStage_as_put_)method `as_put`

```python
as_put() -> PutStage
```

Returns

`PutStage`

#### [](#_PipelineStage_as_reduce_)method `as_reduce`

```python
as_reduce() -> ReduceStage
```

Returns

`ReduceStage`

#### [](#_PipelineStage_as_require_)method `as_require`

```python
as_require() -> RequireStage
```

Returns

`RequireStage`

#### [](#_PipelineStage_as_select_)method `as_select`

```python
as_select() -> SelectStage
```

Returns

`SelectStage`

#### [](#_PipelineStage_as_sort_)method `as_sort`

```python
as_sort() -> SortStage
```

Returns

`SortStage`

#### [](#_PipelineStage_as_update_)method `as_update`

```python
as_update() -> UpdateStage
```

Returns

`UpdateStage`

#### [](#_PipelineStage_is_delete_)method `is_delete`

```python
is_delete() -> bool
```

Returns

`bool`

#### [](#_PipelineStage_is_distinct_)method `is_distinct`

```python
is_distinct() -> bool
```

Returns

`bool`

#### [](#_PipelineStage_is_insert_)method `is_insert`

```python
is_insert() -> bool
```

Returns

`bool`

#### [](#_PipelineStage_is_limit_)method `is_limit`

```python
is_limit() -> bool
```

Returns

`bool`

#### [](#_PipelineStage_is_match_)method `is_match`

```python
is_match() -> bool
```

Returns

`bool`

#### [](#_PipelineStage_is_offset_)method `is_offset`

```python
is_offset() -> bool
```

Returns

`bool`

#### [](#_PipelineStage_is_put_)method `is_put`

```python
is_put() -> bool
```

Returns

`bool`

#### [](#_PipelineStage_is_reduce_)method `is_reduce`

```python
is_reduce() -> bool
```

Returns

`bool`

#### [](#_PipelineStage_is_require_)method `is_require`

```python
is_require() -> bool
```

Returns

`bool`

#### [](#_PipelineStage_is_select_)method `is_select`

```python
is_select() -> bool
```

Returns

`bool`

#### [](#_PipelineStage_is_sort_)method `is_sort`

```python
is_sort() -> bool
```

Returns

`bool`

#### [](#_PipelineStage_is_update_)method `is_update`

```python
is_update() -> bool
```

Returns

`bool`

### [](#_DeleteStage)DeleteStage

`class`

**Package**: `typedb.api.analyze.pipeline_stage`

**Supertypes:**

*   `PipelineStage`
    

Represents a ‘delete’ stage.

#### [](#_DeleteStage_block_)method `block`

```python
block() -> ConjunctionID
```

Returns

`ConjunctionID`

#### [](#_DeleteStage_deleted_variables_)method `deleted_variables`

```python
deleted_variables() -> Iterator['Variable']
```

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

Returns

`Iterator['Variable']`

### [](#_DistinctStage)DistinctStage

`class`

**Package**: `typedb.api.analyze.pipeline_stage`

**Supertypes:**

*   `PipelineStage`
    

Represents a ‘distinct’ stage.

### [](#_InsertStage)InsertStage

`class`

**Package**: `typedb.api.analyze.pipeline_stage`

**Supertypes:**

*   `PipelineStage`
    

Represents an ‘insert’ stage: insert <block>

#### [](#_InsertStage_block_)method `block`

```python
block() -> ConjunctionID
```

Returns

`ConjunctionID`

### [](#_LimitStage)LimitStage

`class`

**Package**: `typedb.api.analyze.pipeline_stage`

**Supertypes:**

*   `PipelineStage`
    

Represents a ‘limit’ stage: limit <limit>

#### [](#_LimitStage_limit_)method `limit`

```python
limit() -> int
```

Returns

`int`

### [](#_MatchStage)MatchStage

`class`

**Package**: `typedb.api.analyze.pipeline_stage`

**Supertypes:**

*   `PipelineStage`
    

Represents a ‘match’ stage: match <block>

#### [](#_MatchStage_block_)method `block`

```python
block() -> ConjunctionID
```

The index into Pipeline.conjunctions.

Returns

`ConjunctionID`

### [](#_OffsetStage)OffsetStage

`class`

**Package**: `typedb.api.analyze.pipeline_stage`

**Supertypes:**

*   `PipelineStage`
    

Represents an ‘offset’ stage: offset <offset>

#### [](#_OffsetStage_offset_)method `offset`

```python
offset() -> int
```

Returns

`int`

### [](#_PutStage)PutStage

`class`

**Package**: `typedb.api.analyze.pipeline_stage`

**Supertypes:**

*   `PipelineStage`
    

Represents a ‘put’ stage: put <block>

#### [](#_PutStage_block_)method `block`

```python
block() -> ConjunctionID
```

Returns

`ConjunctionID`

### [](#_ReduceStage)ReduceStage

`class`

**Package**: `typedb.api.analyze.pipeline_stage`

**Supertypes:**

*   `PipelineStage`
    

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

#### [](#_ReduceStage_group_by_)method `group_by`

```python
group_by() -> Iterator['Variable']
```

The variables to group by.

Returns

`Iterator['Variable']`

#### [](#_ReduceStage_reduce_assignments_)method `reduce_assignments`

```python
reduce_assignments() -> Iterator[ReduceAssignment]
```

The reducer assignments.

Returns

`Iterator[ReduceAssignment]`

### [](#_RequireStage)RequireStage

`class`

**Package**: `typedb.api.analyze.pipeline_stage`

**Supertypes:**

*   `PipelineStage`
    

Represents a ‘require’ stage: require <variables>

#### [](#_RequireStage_variables_)method `variables`

```python
variables() -> Iterator['Variable']
```

Returns

`Iterator['Variable']`

### [](#_SelectStage)SelectStage

`class`

**Package**: `typedb.api.analyze.pipeline_stage`

**Supertypes:**

*   `PipelineStage`
    

Represents a ‘select’ stage: select <variables>

#### [](#_SelectStage_variables_)method `variables`

```python
variables() -> Iterator['Variable']
```

Returns

`Iterator['Variable']`

### [](#_SortStage)SortStage

`class`

**Package**: `typedb.api.analyze.pipeline_stage`

**Supertypes:**

*   `PipelineStage`
    

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

#### [](#_SortStage_variables_)method `variables`

```python
variables() -> Iterator[SortVariable]
```

Returns

`Iterator[SortVariable]`

### [](#_UpdateStage)UpdateStage

`class`

**Package**: `typedb.api.analyze.pipeline_stage`

**Supertypes:**

*   `PipelineStage`
    

Represents an ‘update’ stage: update <block>

#### [](#_UpdateStage_block_)method `block`

```python
block() -> ConjunctionID
```

Returns

`ConjunctionID`

### [](#_ReduceStage)ReduceStage.ReduceAssignment

`class`

**Package**: `typedb.api.analyze.pipeline_stage`

An assignment of a reducer to a variable.

#### [](#_ReduceStage_ReduceAssignment_assigned_)method `assigned`

```python
assigned() -> Variable
```

Returns

`Variable`

#### [](#_ReduceStage_ReduceAssignment_reducer_)method `reducer`

```python
reducer() -> Reducer
```

Returns

`Reducer`

### [](#_Reducer)Reducer

`class`

**Package**: `typedb.api.analyze.reducer`

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

#### [](#_Reducer_arguments_)method `arguments`

```python
arguments() -> Iterator['Variable']
```

The arguments to the reducer.

Returns

`Iterator['Variable']`

#### [](#_Reducer_name_)method `name`

```python
name() -> str
```

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

Returns

`str`

### [](#_ReturnOperation)ReturnOperation

`class`

**Package**: `typedb.api.analyze.function`

#### [](#_ReturnOperation_as_check_)method `as_check`

```python
as_check() -> ReturnOperationCheck
```

Returns

`ReturnOperationCheck`

#### [](#_ReturnOperation_as_reduce_)method `as_reduce`

```python
as_reduce() -> ReturnOperationReduce
```

Returns

`ReturnOperationReduce`

#### [](#_ReturnOperation_as_single_)method `as_single`

```python
as_single() -> ReturnOperationSingle
```

Returns

`ReturnOperationSingle`

#### [](#_ReturnOperation_as_stream_)method `as_stream`

```python
as_stream() -> ReturnOperationStream
```

Returns

`ReturnOperationStream`

#### [](#_ReturnOperation_is_check_)method `is_check`

```python
is_check() -> bool
```

Returns

`bool`

#### [](#_ReturnOperation_is_reduce_)method `is_reduce`

```python
is_reduce() -> bool
```

Returns

`bool`

#### [](#_ReturnOperation_is_single_)method `is_single`

```python
is_single() -> bool
```

Returns

`bool`

#### [](#_ReturnOperation_is_stream_)method `is_stream`

```python
is_stream() -> bool
```

Returns

`bool`

### [](#_ReturnOperationCheck)ReturnOperationCheck

`class`

**Package**: `typedb.api.analyze.function`

**Supertypes:**

*   `ReturnOperation`
    

### [](#_ReturnOperationReduce)ReturnOperationReduce

`class`

**Package**: `typedb.api.analyze.function`

**Supertypes:**

*   `ReturnOperation`
    

#### [](#_ReturnOperationReduce_reducers_)method `reducers`

```python
reducers() -> Iterator['Reducer']
```

Gets the reducers used to compute the aggregations.

Returns

`Iterator['Reducer']`

### [](#_ReturnOperationSingle)ReturnOperationSingle

`class`

**Package**: `typedb.api.analyze.function`

**Supertypes:**

*   `ReturnOperation`
    

#### [](#_ReturnOperationSingle_selector_)method `selector`

```python
selector() -> str
```

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

Returns

`str`

#### [](#_ReturnOperationSingle_variables_)method `variables`

```python
variables() -> Iterator['Variable']
```

Gets the variables in the returned row.

Returns

`Iterator['Variable']`

### [](#_ReturnOperationStream)ReturnOperationStream

`class`

**Package**: `typedb.api.analyze.function`

**Supertypes:**

*   `ReturnOperation`
    

#### [](#_ReturnOperationStream_variables_)method `variables`

```python
variables() -> Iterator['Variable']
```

Gets the variables in the returned row.

Returns

`Iterator['Variable']`

### [](#_SortStage)SortStage.SortVariable

`class`

**Package**: `typedb.api.analyze.pipeline_stage`

A variable and its sort order.

#### [](#_SortStage_SortVariable_order_)method `order`

```python
order() -> SortOrder
```

Returns

`SortOrder`

#### [](#_SortStage_SortVariable_variable_)method `variable`

```python
variable() -> Variable
```

Returns

`Variable`

### [](#_SortOrder)SortOrder

`class`

**Package**: `typedb.common.enums`

Enum constants  

Name

Value

`Ascending`

`0`

`Descending`

`1`

### [](#_Span)Span

`class`

**Package**: `typedb.api.analyze.constraint`

The span of a constraint in the source query.

#### [](#_Span_begin_)method `begin`

```python
begin() -> int
```

The offset of the first character.

Returns

`int`

#### [](#_Span_end_)method `end`

```python
end() -> int
```

The offset after the last character.

Returns

`int`

### [](#_VariableAnnotations)VariableAnnotations

`class`

**Package**: `typedb.api.analyze.variable_annotations`

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

#### [](#_VariableAnnotations_as_instance_)method `as_instance`

```python
as_instance() -> Iterator['Type']
```

The possible Types of instances this variable can hold.

Returns

`Iterator['Type']`

#### [](#_VariableAnnotations_as_type_)method `as_type`

```python
as_type() -> Iterator['Type']
```

The possible types this variable can hold.

Returns

`Iterator['Type']`

#### [](#_VariableAnnotations_as_value_)method `as_value`

```python
as_value() -> Iterator[str]
```

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

Returns

`Iterator[str]`

#### [](#_VariableAnnotations_is_instance_)method `is_instance`

```python
is_instance() -> bool
```

Returns True if this variable is an Instance variable.

Returns

`bool`

#### [](#_VariableAnnotations_is_type_)method `is_type`

```python
is_type() -> bool
```

Returns True if this variable is a Type variable.

Returns

`bool`

#### [](#_VariableAnnotations_is_value_)method `is_value`

```python
is_value() -> bool
```

Returns True if this variable is a Value variable.

Returns

`bool`

## [](#_errors_header)Errors

### [](#_TypeDBDriverException)TypeDBDriverException

`class`

**Package**: `typedb.common.exception`

**Supertypes:**

*   `RuntimeError`
    

Exceptions raised by the driver.

Examples

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

[TypeDB GRPC Drivers](../index.md) [Java gRPC driver](../java/index.md)

[Edit on GitHub](https://github.com/typedb/typedb-docs/edit/3.x-development/reference/modules/ROOT/pages/typedb-grpc-drivers/python.adoc) Edit this page on GitHub.