TypeDB 3.0 is live! Get started for free.

Python driver API reference

Connection

TypeDB

cloud_driver

static cloud_driver(addresses: Mapping[str, str] | Iterable[str] | str, credentials: Credentials, driver_options: DriverOptions) -> Driver

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

Input parameters
Name Description Type Default Value

addresses

TypeDB server addresses as a single string, a list of strings, or as an address translation mapping.

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

credentials

The credentials to connect with.

Credentials

driver_options

The connection settings to connect with.

DriverOptions

Returns

Driver

core_driver

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

Creates a connection to TypeDB.

Input parameters
Name Description Type Default Value

address

Address of the TypeDB server.

str

credentials

The credentials to connect with.

Credentials

driver_options

The connection settings to connect with.

DriverOptions

Returns

Driver

Driver

Properties
Name Type Description

databases

DatabaseManager

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

users

UserManager

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

close

close() -> None

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

Returns

None

Code examples
driver.close()

is_open

is_open() -> bool

Checks whether this connection is presently open.

Returns

bool

Code examples
driver.is_open()

transaction

transaction(database_name: str, transaction_type: TransactionType) -> Transaction

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

Input parameters
Name Description Type Default Value

database_name

The name of the database with which the transaction connects

str

transaction_type

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

TransactionType

Returns

Transaction

Code examples
driver.transaction(database, transaction_type)

Credentials

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

Examples
credentials = Credentials(username, password)

DriverOptions

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

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

DatabaseManager

Provides access to all database management methods.

all

all() -> List[Database]

Retrieves all databases present on the TypeDB server

Returns

List[Database]

Code examples
driver.databases.all()

contains

contains(name: str) -> bool

Checks if a database with the given name exists

Input parameters
Name Description Type Default Value

name

The database name to be checked

str

Returns

bool

Code examples
driver.databases.contains(name)

create

create(name: str) -> None

Create a database with the given name

Input parameters
Name Description Type Default Value

name

The name of the database to be created

str

Returns

None

Code examples
driver.databases.create(name)

get

get(name: str) -> Database

Retrieve the database with the given name.

Input parameters
Name Description Type Default Value

name

The name of the database to retrieve

str

Returns

Database

Code examples
driver.databases.get(name)

Database

Properties
Name Type Description

name

str

The database name as a string.

delete

delete() -> None

Deletes this database.

Returns

None

Code examples
database.delete()

schema

schema() -> str

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

Returns

str

Code examples
database.schema()

type_schema

type_schema() -> str

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

Returns

str

Code examples
database.type_schema()

UserManager

Provides access to all user management methods.

all

all() -> List[User]

Retrieves all users which exist on the TypeDB server.

Returns

List[User]

Code examples
driver.users.all()

contains

contains(username: str) -> bool

Checks if a user with the given name exists.

Input parameters
Name Description Type Default Value

username

The user name to be checked

str

Returns

bool

Code examples
driver.users.contains(username)

create

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

Create a user with the given name and password.

Input parameters
Name Description Type Default Value

username

The name of the user to be created

str

password

The password of the user to be created

str

Returns

None

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

get

get(username: str) -> User | None

Retrieve a user with the given name.

Input parameters
Name Description Type Default Value

username

The name of the user to retrieve

str

Returns

User | None

Code examples
driver.users.get(username)

get_current_user

get_current_user() -> User | None

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

Returns

User | None

Code examples
driver.users.get_current_user()

User

TypeDB user information

Properties
Name Type Description

name

str

Returns the name of this user.

delete

delete() -> None

Deletes a user with the given name.

Input parameters
Name Description Type Default Value

username

The name of the user to be deleted

Returns

None

Code examples
driver.users.delete(username)

update_password

update_password(password: str) -> None

Updates the password for this user.

Input parameters
Name Description Type Default Value

password_old

The current password of this user

password_new

The new password

Returns

None

Transaction

Transaction

Properties
Name Type Description

type

TransactionType

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

close

close() -> None

Closes the transaction.

Returns

None

Code examples
transaction.close()

commit

commit() -> None

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

Returns

None

Code examples
transaction.commit()

is_open

is_open() -> bool

Checks whether this transaction is open.

Returns

bool

Code examples
transaction.is_open()

on_close

on_close(function: callable) -> None

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

Input parameters
Name Description Type Default Value

function

The callback function.

callable

Returns

None

Code examples
transaction.on_close(function)

query

query(query: str) -> Promise[QueryAnswer]

Execute a TypeQL query in this transaction.

Input parameters
Name Description Type Default Value

query

The query to execute.

str

Returns

Promise[QueryAnswer]

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

rollback

rollback() -> None

Rolls back the uncommitted changes made via this transaction.

Returns

None

Code examples
transaction.rollback()

TransactionType

This class is used to specify the type of transaction.

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

READ

0

SCHEMA

2

WRITE

1

is_read

is_read() -> bool
Returns

bool

is_schema

is_schema() -> bool
Returns

bool

is_write

is_write() -> bool
Returns

bool

Answer

QueryAnswer

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

Properties
Name Type Description

query_type

QueryType

Retrieves the executed query’s type of this QueryAnswer.

as_concept_documents

as_concept_documents() -> ConceptDocumentIterator

Casts the query answer to ConceptDocumentIterator.

Returns

ConceptDocumentIterator

Code examples
query_answer.as_concept_documents()

as_concept_rows

as_concept_rows() -> ConceptRowIterator

Casts the query answer to ConceptRowIterator.

Returns

ConceptRowIterator

Code examples
query_answer.as_concept_rows()

as_ok

as_ok() -> OkQueryAnswer

Casts the query answer to OkQueryAnswer.

Returns

OkQueryAnswer

Code examples
query_answer.as_ok()

is_concept_documents

is_concept_documents() -> bool

Checks if the query answer is a ConceptDocumentIterator.

Returns

bool

Code examples
query_answer.is_concept_documents()

is_concept_rows

is_concept_rows() -> bool

Checks if the query answer is a ConceptRowIterator.

Returns

bool

Code examples
query_answer.is_concept_rows()

is_ok

is_ok() -> bool

Checks if the query answer is an Ok.

Returns

bool

Code examples
query_answer.is_ok()

OkQueryAnswer

Supertypes:

  • QueryAnswer

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

as_ok

as_ok() -> OkQueryAnswer

Casts the query answer to OkQueryAnswer.

Returns

OkQueryAnswer

Code examples
query_answer.as_ok()

is_ok

is_ok() -> bool

Checks if the query answer is an Ok.

Returns

bool

Code examples
query_answer.is_ok()

ConceptRowIterator

Supertypes:

  • QueryAnswer

Represents an iterator over ConceptRows returned as a server answer.

as_concept_rows

as_concept_rows() -> ConceptRowIterator

Casts the query answer to ConceptRowIterator.

Returns

ConceptRowIterator

Code examples
query_answer.as_concept_rows()

is_concept_rows

is_concept_rows() -> bool

Checks if the query answer is a ConceptRowIterator.

Returns

bool

Code examples
query_answer.is_concept_rows()

ConceptRow

Contains a row of concepts with a header.

Properties
Name Type Description

query_type

QueryType

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

column_names

column_names() -> Iterator[str]

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

Returns

Iterator[str]

Code examples
concept_row.column_names()

concepts

concepts() -> Iterator[Concept]

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

Returns

Iterator[Concept]

Code examples
concept_row.concepts()

get

get(column_name: str) -> Concept | None

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

Input parameters
Name Description Type Default Value

column_name

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

str

Returns

Concept | None

Code examples
concept_row.get(column_name)

get_index

get_index(column_index: int) -> Concept | None

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

Input parameters
Name Description Type Default Value

column_index

The column index

int

Returns

Concept | None

Code examples
concept_row.get_index(column_index)

ConceptDocumentIterator

Supertypes:

  • QueryAnswer

Represents an iterator over ConceptRows returned as a server answer.

as_concept_documents

as_concept_documents() -> ConceptDocumentIterator

Casts the query answer to ConceptDocumentIterator.

Returns

ConceptDocumentIterator

Code examples
query_answer.as_concept_documents()

is_concept_documents

is_concept_documents() -> bool

Checks if the query answer is a ConceptDocumentIterator.

Returns

bool

Code examples
query_answer.is_concept_documents()

QueryType

Used to specify the type of the executed query.

Examples
concept_row.query_type
Enum constants
Name Value

READ

0

SCHEMA

2

WRITE

1

is_read

is_read() -> bool
Returns

bool

is_schema

is_schema() -> bool
Returns

bool

is_write

is_write() -> bool
Returns

bool

Promise

A Promise represents an asynchronous network operation.

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

map

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

Promise[T]

resolve

resolve() -> T

Retrieves the result of the Promise.

Returns

T

Code examples
promise.resolve()

Concept

Concept

as_attribute

as_attribute() -> Attribute

Casts the concept to Attribute.

Returns

Attribute

Code examples
concept.as_attribute()

as_attribute_type

as_attribute_type() -> AttributeType

Casts the concept to AttributeType.

Returns

AttributeType

Code examples
concept.as_attribute_type()

as_entity

as_entity() -> Entity

Casts the concept to Entity.

Returns

Entity

Code examples
concept.as_entity()

as_entity_type

as_entity_type() -> EntityType

Casts the concept to EntityType.

Returns

EntityType

Code examples
concept.as_entity_type()

as_instance

as_instance() -> Instance

Casts the concept to Instance.

Returns

Instance

Code examples
concept.as_instance()

as_relation

as_relation() -> Relation

Casts the concept to Relation.

Returns

Relation

Code examples
concept.as_relation()

as_relation_type

as_relation_type() -> RelationType

Casts the concept to RelationType.

Returns

RelationType

Code examples
concept.as_relation_type()

as_role_type

as_role_type() -> RoleType

Casts the concept to RoleType.

Returns

RoleType

Code examples
concept.as_role_type()

as_type

as_type() -> Type

Casts the concept to Type.

Returns

Type

Code examples
concept.as_type()

as_value

as_value() -> Value

Casts the concept to Value.

Returns

Value

Code examples
concept.as_value()

get_label

get_label() -> str

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

Returns

str

Code examples
concept.get_label()

is_attribute

is_attribute() -> bool

Checks if the concept is an Attribute.

Returns

bool

Code examples
concept.is_attribute()

is_attribute_type

is_attribute_type() -> bool

Checks if the concept is an AttributeType.

Returns

bool

Code examples
concept.is_attribute_type()

is_boolean

is_boolean() -> bool

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

Returns

bool

Code examples
concept.is_boolean()

is_date

is_date() -> bool

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

Returns

bool

Code examples
concept.is_date()

is_datetime

is_datetime() -> bool

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

Returns

bool

Code examples
concept.is_datetime()

is_datetime_tz

is_datetime_tz() -> bool

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

Returns

bool

Code examples
concept.is_datetime_tz()

is_decimal

is_decimal() -> bool

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

Returns

bool

Code examples
concept.is_decimal()

is_double

is_double() -> bool

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

Returns

bool

Code examples
concept.is_double()

is_duration

is_duration() -> bool

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

Returns

bool

Code examples
concept.is_duration()

is_entity

is_entity() -> bool

Checks if the concept is an Entity.

Returns

bool

Code examples
concept.is_entity()

is_entity_type

is_entity_type() -> bool

Checks if the concept is an EntityType.

Returns

bool

Code examples
concept.is_entity_type()

is_instance

is_instance() -> bool

Checks if the concept is a Instance.

Returns

bool

Code examples
concept.is_instance()

is_integer

is_integer() -> bool

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

Returns

bool

Code examples
concept.is_integer()

is_relation

is_relation() -> bool

Checks if the concept is a Relation.

Returns

bool

Code examples
concept.is_relation()

is_relation_type

is_relation_type() -> bool

Checks if the concept is a RelationType.

Returns

bool

Code examples
concept.is_relation_type()

is_role_type

is_role_type() -> bool

Checks if the concept is a RoleType.

Returns

bool

Code examples
concept.is_role_type()

is_string

is_string() -> bool

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

Returns

bool

Code examples
concept.is_string()

is_struct

is_struct() -> bool

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

Returns

bool

Code examples
concept.is_struct()

is_type

is_type() -> bool

Checks if the concept is a Type.

Returns

bool

Code examples
concept.is_type()

is_value

is_value() -> bool

Checks if the concept is a Value.

Returns

bool

Code examples
concept.is_value()

try_get_boolean

try_get_boolean() -> bool | None

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

Returns

bool | None

Code examples
value.try_get_boolean()

try_get_date

try_get_date() -> date | None

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

Returns

date | None

Code examples
value.try_get_date()

try_get_datetime

try_get_datetime() -> Datetime | None

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

Returns

Datetime | None

Code examples
value.try_get_datetime()

try_get_datetime_tz

try_get_datetime_tz() -> Datetime | None

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

Returns

Datetime | None

Code examples
value.try_get_datetime_tz()

try_get_decimal

try_get_decimal() -> Decimal | None

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

Returns

Decimal | None

Code examples
value.try_get_decimal()

try_get_double

try_get_double() -> float | None

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

Returns

float | None

Code examples
value.try_get_double()

try_get_duration

try_get_duration() -> Duration | None

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

Returns

Duration | None

Code examples
value.try_get_duration()

try_get_iid

try_get_iid() -> str | None

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

Returns

str | None

Code examples
concept.try_get_iid()

try_get_integer

try_get_integer() -> int | None

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

Returns

int | None

Code examples
value.try_get_integer()

try_get_label

try_get_label() -> str | None

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

Returns

str | None

Code examples
concept.try_get_label()

try_get_string

try_get_string() -> str | None

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

Returns

str | None

Code examples
value.try_get_string()

try_get_struct

try_get_struct() -> STRUCT | None

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

Returns

STRUCT | None

Code examples
value.try_get_struct()

try_get_value

try_get_value() -> VALUE | None

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

Returns

VALUE | None

Code examples
concept.try_get_value()

try_get_value_type

try_get_value_type() -> str | None

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

Returns

str | None

Code examples
concept.try_get_value_type()

Schema

Type

Supertypes:

  • Concept

is_type

is_type() -> bool

Checks if the concept is a Type.

Returns

bool

Code examples
type_.is_type()

EntityType

Supertypes:

  • Type

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

as_entity_type

as_entity_type() -> EntityType

Casts the concept to EntityType.

Returns

EntityType

Code examples
entity_type.as_entity_type()

is_entity_type

is_entity_type() -> bool

Checks if the concept is an EntityType.

Returns

bool

Code examples
entity_type.is_entity_type()

RelationType

Supertypes:

  • Type

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

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

A relation type must specify at least one role.

as_relation_type

as_relation_type() -> RelationType

Casts the concept to RelationType.

Returns

RelationType

Code examples
relation_type.as_relation_type()

is_relation_type

is_relation_type() -> bool

Checks if the concept is a RelationType.

Returns

bool

Code examples
relation_type.is_relation_type()

RoleType

Supertypes:

  • Type

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

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

as_role_type

as_role_type() -> RoleType

Casts the concept to RoleType.

Returns

RoleType

Code examples
role_type.as_role_type()

is_role_type

is_role_type() -> bool

Checks if the concept is a RoleType.

Returns

bool

Code examples
role_type.is_role_type()

AttributeType

Supertypes:

  • Type

Attribute types represent properties that other types can own.

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

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

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

as_attribute_type

as_attribute_type() -> AttributeType

Casts the concept to AttributeType.

Returns

AttributeType

Code examples
attribute.as_attribute_type()

is_attribute_type

is_attribute_type() -> bool

Checks if the concept is an AttributeType.

Returns

bool

Code examples
attribute.is_attribute_type()

Data

Instance

Supertypes:

  • Concept

as_instance

as_instance() -> Instance

Casts the concept to Instance.

Returns

Instance

Code examples
instance.as_instance()

get_type

get_type() -> Type

Retrieves the type which this Instance belongs to.

Returns

Type

Code examples
instance.get_type()

is_instance

is_instance() -> bool

Checks if the concept is a Instance.

Returns

bool

Code examples
instance.is_instance()

Entity

Supertypes:

  • Instance

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

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

as_entity

as_entity() -> Entity

Casts the concept to Entity.

Returns

Entity

Code examples
entity.as_entity()

get_iid

get_iid() -> str

Retrieves the unique id of the Entity.

Returns

str

Code examples
entity.get_iid()

get_type

get_type() -> EntityType

Retrieves the type which this Entity belongs to.

Returns

EntityType

Code examples
entity.get_type()

is_entity

is_entity() -> bool

Checks if the concept is an Entity.

Returns

bool

Code examples
entity.is_entity()

Relation

Supertypes:

  • Instance

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

as_relation

as_relation() -> Relation

Casts the concept to Relation.

Returns

Relation

Code examples
relation.as_relation()

get_iid

get_iid() -> str

Retrieves the unique id of the Relation.

Returns

str

Code examples
relation.get_iid()

get_type

get_type() -> RelationType

Retrieves the type which this Relation belongs to.

Returns

RelationType

Code examples
relation.get_type()

is_relation

is_relation() -> bool

Checks if the concept is a Relation.

Returns

bool

Code examples
relation.is_relation()

Attribute

Supertypes:

  • Instance

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

Attributes can be uniquely addressed by their type and value.

as_attribute

as_attribute() -> Attribute

Casts the concept to Attribute.

Returns

Attribute

Code examples
attribute.as_attribute()

get_boolean

get_boolean() -> bool

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

Returns

bool

Code examples
attribute.get_boolean()

get_date

get_date() -> date

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

Returns

date

Code examples
attribute.get_date()

get_datetime

get_datetime() -> Datetime

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

Returns

Datetime

Code examples
attribute.get_datetime()

get_datetime_tz

get_datetime_tz() -> Datetime

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

Returns

Datetime

Code examples
attribute.get_datetime_tz()

get_decimal

get_decimal() -> Decimal

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

Returns

Decimal

Code examples
attribute.get_decimal()

get_double

get_double() -> float

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

Returns

float

Code examples
attribute.get_double()

get_duration

get_duration() -> Duration

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

Returns

Duration

Code examples
attribute.get_duration()

get_integer

get_integer() -> int

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

Returns

int

Code examples
attribute.get_integer()

get_string

get_string() -> str

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

Returns

str

Code examples
attribute.get_string()

get_struct

get_struct() -> Concept.STRUCT

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

Returns

Concept.STRUCT

Code examples
attribute.get_struct()

get_type

get_type() -> AttributeType

Retrieves the type which this Attribute belongs to.

Returns

AttributeType

Code examples
attribute.get_type()

get_value

get_value() -> Concept.VALUE

Retrieves the value which the Attribute instance holds.

Returns

Concept.VALUE

Code examples
attribute.get_value()

get_value_type

get_value_type() -> str

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

Returns

str

Code examples
attribute.get_value_type()

is_attribute

is_attribute() -> bool

Checks if the concept is an Attribute.

Returns

bool

Code examples
attribute.is_attribute()

Value

Supertypes:

  • Concept

as_value

as_value() -> Value

Casts the concept to Value.

Returns

Value

Code examples
value.as_value()

get

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

Retrieves the value which this value concept holds.

Returns

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

Code examples
value.get()

get_boolean

get_boolean() -> bool

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

Returns

bool

Code examples
value.get_boolean()

get_date

get_date() -> date

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

Returns

date

Code examples
value.get_date()

get_datetime

get_datetime() -> Datetime

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

Returns

Datetime

Code examples
value.get_datetime()

get_datetime_tz

get_datetime_tz() -> Datetime

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

Returns

Datetime

Code examples
value.get_datetime_tz()

get_decimal

get_decimal() -> Decimal

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

Returns

Decimal

Code examples
value.get_decimal()

get_double

get_double() -> float

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

Returns

float

Code examples
value.get_double()

get_duration

get_duration() -> Duration

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

Returns

Duration

Code examples
value.get_duration()

get_integer

get_integer() -> int

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

Returns

int

Code examples
value.get_integer()

get_string

get_string() -> str

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

Returns

str

Code examples
value.get_string()

get_struct

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

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

Returns

Dict[str, Value | None]

Code examples
value.get_struct()

get_type

get_type() -> str

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

Returns

str

Code examples
value.get_type()

is_value

is_value() -> bool

Checks if the concept is a Value.

Returns

bool

Code examples
value.is_value()

Value

Datetime

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

Properties
Name Type Description

date

date

Return the date part.

datetime_without_nanos

datetime

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

day

int

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

hour

int

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

microsecond

int

Return the rounded number of microseconds.

minute

int

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

month

int

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

nanos

int

Return the nanoseconds part.

offset_seconds

str | None

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

second

int

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

total_seconds

float

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

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

tz_name

str | None

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

tzinfo

tzinfo

Return timezone info.

weekday

int

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

year

int

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

fromstring

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

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

Input parameters
Name Description Type Default Value

datetime_str

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

str

tz_name

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

str | None

None

offset_seconds

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

int | None

None

datetime_fmt

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

str

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

Returns

Datetime

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

fromtimestamp

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

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

Input parameters
Name Description Type Default Value

timestamp_seconds

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

int

subsec_nanos

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

int

tz_name

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

str | None

None

offset_seconds

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

int | None

None

Returns

``

isoformat

isoformat() -> str

Return the time formatted according to ISO.

Returns

str

offset_seconds_fromstring

classmethod offset_seconds_fromstring(offset: str) -> int

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

Input parameters
Name Description Type Default Value

offset

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

str

Returns

int

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

utcfromstring

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

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

Input parameters
Name Description Type Default Value

datetime_str

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

str

tz_name

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

str | None

None

offset_seconds

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

int | None

None

datetime_fmt

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

str

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

Returns

Datetime

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

utcfromtimestamp

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

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

Input parameters
Name Description Type Default Value

timestamp_seconds

Amount of full seconds since the epoch in UTC.

int

subsec_nanos

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

int

tz_name

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

str | None

None

offset_seconds

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

int | None

None

Returns

``

Duration

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

Properties
Name Type Description

days

int

The days part of the duration

months

int

The months part of the duration

nanos

int

The nanoseconds part of the duration

fromstring

classmethod fromstring(duration_str: str) -> Duration

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

Input parameters
Name Description Type Default Value

duration_str

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

str

Returns

Duration

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

Errors

TypeDBDriverException

Supertypes:

  • RuntimeError

Exceptions raised by the driver.

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